I created a .wav file from a recording from my microphone using this javascript library Unfortuntely the file is 7-bit encoded .wav file. I send this file to my node.js server and now I need to send this file to google's speech to text api to be processed but google only accepts base64 linear 16 .wav files. What can I do?
Here is how I create and send the audio file to my server:
navigator.mediaDevices.getUserMedia({
audio: true,video:false
})
.then((stream) => {
context = new AudioContext()
var source = context.createMediaStreamSource(stream)
config = {
numChannels:1
}
var rec = new Recorder(source,config)
rec.record()
$('#stop').click(()=>{
rec.stop()
blob = rec.exportWAV(export)
function export(blob)
{
fd = new FormData()
fd.append('file',blob)
$.ajax({
type: "POST",
url: "http:localhost:3000/send",
data: fd,
contentType:false,
processData: false,
encType:"multipart/form-data",
success: function(data){
console.log('success')
}
});
}
})
Here is how I handle it on my node.js server:
var upload = multer()
var app = express({ dest: '/' })
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
var upload = multer().any()
app.get('/',(req,res)=>{
res.send('Hello World!')
})
app.post('/send',(req,res)=>{
upload(req, res, function (err) {
if (err) {
console.log(err)
return
}
file = req.files[0]
buffer = file.buffer
var wstream = fs.createWriteStream('audiofile.wav');
wstream.write(buffer)
wstream.end();
path = "path/audiofile.wav"