浏览器关闭录音方法及录音时系统音量变小问题

var audioStream = null;
navigator.getUserMedia({
        audio: {  // 处理录音播放音频音量变小问题
          channelCount: 1,  
          sampleRate: 16000,
          volume: 1.0,
          sampleSize: 16,  
          echoCancellation: false,
          noiseSuppression: false,
        },
        video: false
},
function (stream) {
        audioStream = stream;
        audioStream.stop = function () {
                this.getAudioTracks().forEach(function (track) {
                    track.stop();
                });
                this.getVideoTracks().forEach(function (track) { //in case... :)
                    track.stop();
                });
                 // 或者
                 stream.getTracks().forEach(track => track.stop())
        };
});

// 调用stop方法可全部关闭录音

audioStream.stop();

你可能感兴趣的:(javascript,开发语言,ecmascript)