简体   繁体   中英

Audio in Node-webkit using node js and Web Audio API

I'm working on an application using node-webkit in which I need to play audio. I've successfully played audio using Web Audio API and an XMLHttpRequest, but loading the song is very slow. It takes up to 1 second depending on the format and size.

Is there any way to load a file using the node.js file system, and then pass that data to the Web Audio API to decrease the loading time? Is there an better way to go about this whole thing?

Note: I'm building a native application so I want to play the audio not to stream it to clients. I also need to be able to do processing on the audio, which is why I looked into Web Audio API.

You could convert the audio data to a data: uri and use that.

Check out this question for more information.

There are a large number of tools to convert an audio file to a data uri too .

This npm file-component

  var file = require('file');
  var img = file("/path/to/audio");

  if (!img.is('image/*')) {
    alert('Images only!');
    return;
  }

  var reader = img.toDataURL(function(err, str){
    if (err) throw err;
    console.log("This is a data: uri: " + str);
  });

  reader.on('progress', function(e){
    console.log(e.percent);
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM