我正在尝试将录制的音频保存到服务器上的音频文件中。
参考:http ://www.smartjava.org/content/record-audio-using-webrtc-chrome-and-speech-recognition-websockets
代码:
var rec;
function testaudio(){
navigator.getUserMedia({audio: true}, success, error);
function success(stream){
var context = new webkitAudioContext();
console.log(context);
console.log(context.source);
console.log(context.destination);
var mediaStreamSource = context.createMediaStreamSource(stream);
console.log(mediaStreamSource);
rec = new Recorder(mediaStreamSource);
console.log(rec);
}
function error(e){console.log('error in testing audio.. !!1'+e);}
}
函数记录(){rec.record();
console.log("recording..");
}
函数 stopAndSend() {
rec.stop();
console.log("recording stopped!!!");
rec.exportWAV(function(blob){
console.log(blob);
socket.emit('audioSave', {recordedData:blob}); //sending blob to server, socket is created using socket.io
});
}
服务器端代码:
socket.on('audioSave', function(data){
var audio=data.recordedData;
/*
Here i want to save this audio in an audio file , i tried this
fs.writeFile('out.wav', audio, function(err)
{
if(err) {console.log("!!!!!!!!!!!!!!!error in writing file..."+ err);}
console.log(" Audio File created ");
}
);
This method creates text file
*/
});
如何将音频 blob 写入音频文件?