muaz-khan / RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
https://www.webrtc-experiment.com/RecordRTC/
MIT License
6.6k stars 1.76k forks source link

i just want find out when there is no sound in the mediaStream , can u check my code and tell me if it's ok or not #348

Open xuedygaga opened 7 years ago

xuedygaga commented 7 years ago

i just want find out when there is no sound in this mediaStream:

var recorder = RecordRTC(mediaStream, {
    type: 'audio',
    mineType: "audio/wav",
    recorderType: StereoAudioRecorder
});

function postFiles() {
    var blob = recorder.getBlob();
    console.log("blob", blob); //if the blob.size is small , i can believe there is no sound in this blob
}

function getBlob() {
    if (recorder) {
        recorder.startRecording();

        function stopRecord() {
            recorder.stopRecording(postFiles);
        }
        window.setTimeout(stopRecord, 1000); //get blob per a second
    }
}
window.setInterval(getBlob, 1500);
muaz-khan commented 7 years ago

Please try this instead:

If audio tracks are still empty then please make sure to pass custom values for sampleRate (and maybe bufferSize as well).

If you want a similar behavior as your code snippet, then please try this library instead: