音频降噪音,回声消除,自动增益代码示例

json

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <style>
    html, body{
      height: 100%;
      width: 100%;
    }
    #video{
      height: 300px;
      width: 300px;
    }
  </style>
  <script>
    $(() => {
      var constraints =  {
        audio: {
          echoCancellationType: 'system',//browser|system
          echoCancellation: true,
          noiseSuppression: true,
          autoGainControl: false,
          sampleRate:24000,
          sampleSize:16,
          channelCount:2,
          volume:0.5
        },
        video: {
          width:320,
          height:240,
          frameRate:{ideal:60, min:10}
        }
      }

      navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
        $('#video')[0].srcObject = stream;
        let statusHtml = '';
        stream.getTracks().forEach((track) => {
          statusHtml = statusHtml + track.kind+":"+JSON.stringify(track.getSettings(), null, 2)+'<br>';
          console.log('settings:', track.getSettings());
          console.log('capabilities:', track.getCapabilities());
        })
        $('#status').html(statusHtml);
      }).catch((err) => {
        console.log(err);
      });
    });
  </script>
</head>
<body>
  <h1> 音频降噪音,回声消除,自动增益测试</h1>
  <p>尝试更改 echoCancellation, noiseSuppression ,autoGainControl属性的值 .</p>
  <div>
  <video id='video' autoplay='false' playsinline='false'></video>
  <pre id='status'></pre>
  </div>
  </body>
</html>

 

音频降噪音,回声消除,自动增益代码示例
标签: