对不起,我的英语!
我需要将流音频编码为wav或ogg的文件。
这是流音频的和平:data:audio / ogg;编解码器= 0; base64,T2dnUwACAAAAAAAAAABABHGwAAAAAAANOrXmwBE09wdXNIZWFkAQE4AQDuAgAAAABPZ ...
let mediaRecorder;
navigator.mediaDevices.getUserMedia({audio:true})
.then(stream =>{
mediaRecorder = new MediaRecorder(stream);
let partesAudio = []//se for longo ele salva em partes
mediaRecorder.ondataavailable = data =>{
partesAudio.push(data.data);
}
mediaRecorder.onstop=() =>{
const blob = new Blob(partesAudio,{type:'audio/ogg; codecs=0'})
const reader = new window.FileReader()
reader.readAsDataURL(blob)
reader.onloadend= async () =>{
console.log(reader.result)
var resultado= await fetch('http://localhost:4000/fala/',{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
fala:reader.result //'frase8.wav'
}),
});
在后端
const fs = require('fs');
fs.writeFileSync('something.ogg',req.body.fala)
我发现的唯一想法是想法,我怎么做却没有尝试的代码