How to Save a Wav File in Node.js

Asked 2 years ago, Updated 2 years ago, 77 views

When saving wav files using Node.js,
How does WebAudioAPI record data?
I don't know if I should hand it over to fs.writeFile().

◆Development environment
win10
goole chrome ver 55.0.2883.87 m
Node.jsver6.7.0
Web Audio API recorder.js

Currently, the audio recording itself uses the Web Audio API and
Convert to wav file recorder.js
(Reference: https://labs.irohasoft.com/webaudio/chrome/)
I'm using
wav files in fs.writeFile. I'm struggling because I don't know how to save it.

◆Client side
Audio recording uses WebAudioAPI and
converting to wav file in recorder.js.
Below is the code for the wav file conversion part.

recorder&recorder.exportWAV(function(blob){
    var url = URL.createObjectURL(blob);
    var hf = document.createElement('a');

    hf.href=url;
    hf.download=new Date().toISOSstring()+'.wav';
    hf.innerHTML = hf.download;
    voiceBuff=?;
});

voiceBuff is a variable prepared in module.exports. I would like to use it as a second argument for fs.writeFile().
I don't know what to give to ?, so I'm worried.

◆ Common js file (common.js)

var voiceBuff;

(function(exports){
    exports.getVoice=function() {return voiceBuff};
}) (typeof exports==='undefined'?this.mymodule={}:exports);

◆ Server side

varfs=require('fs');
var common=require('./js/common.js');

・・・

fs.writeFile(
    'rec01.wav',
    common.getVoice(),
    function(err){
        console.log(err);
    }
);


Due to lack of study, there are some mistakes or difficulties to understand. I think there are many, but if there is anything you don't understand,
I will add it at any time.
I look forward to your kind cooperation.

javascript html5 node.js websocket

2022-09-30 16:38

1 Answers

◆ Client side
Post binary data using XMLHttpRequest
Send binary data

◆ Server side Save POSTed body
Save files uploaded from the form with Node.js

resolved in .


2022-09-30 16:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.