Pc browser acquires audio stream, how to transmit it to the background in real time

Code:
if (navigator.getUserMedia) {

        navigator.getUserMedia(
            // constraints
            {
                //video: true,
                audio: true
            },
            // successCallback
            function (localMediaStream) {
                var audio = document.querySelector("audio");
                console.log(localMediaStream,"");
                audio.src = window.URL.createObjectURL(localMediaStream);
                console.log(audio.src,"")
                // do whatever you want with the video
                audio.play();
            },
            // errorCallback
            function (err) {
                console.log("The following error occured: " + err);
            });
    } else {
        alert("getUserMedia not supported by your web browser or Operating system version");
    }
    
    
    localMediaStreampcbloburlaudio
    :localMediaStreammp3
    

you can submit blob to the backend in real time via ajax


Video works the same as audio. Here, take audio as an example.

in fact, this problem you need to negotiate with the backend, assuming that there is an interface to accept file streams in the background, then the code looks like this:

navigator.getUserMedia(
            // constraints
            {
                //video: true,
                audio: true
            },
            // successCallback
            function (localMediaStream) {
               fetch(url, {
                   method: 'POST',
                   body: localMediaStream
               })
            },
            // errorCallback
            function (err) {
                console.log("The following error occured: " + err);
            });
    } else {
        alert("getUserMedia not supported by your web browser or Operating system version");
    }

Brother, have you solved your problem? I have the same problem

Menu