1

我正在尝试将当前录制的语音的 base64 字符串发送到服务器进行其他处理。我的方法是将base64字符串推送到recordedChunks中进行查询然后发送到服务器。

const recordedChunks = [];
var context = null;
var blob = null;

const handler = function(stream) {
    if (window.URL) {
        player.srcObject = stream;
    } else {
        //player.src = stream;
    }
    const context = new AudioContext();
    const source = context.createMediaStreamSource(stream);
    let bufferSize=1024;
    const processor = context.createScriptProcessor(bufferSize, 1, 1);

    source.connect(processor);
    processor.connect(context.destination);

    processor.onaudioprocess = function(e) {
         //e.inputBuffer
        // Do something with the data, e.g. convert it to mp3
        // How to get base64 of what has been recorded without stopping the recorder
       // recordedChunks.push('somePrerecodedBase64String');
    };
};

navigator.mediaDevices.getUserMedia({ audio: true, video: false })
    .then(handler);
4

0 回答 0