添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am recording audio using web audio API and recorder.js but when I download the audio and checked this audio spectogram. I have found signals dropped for some milliseconds. Not getting any solution. Can sombody tell me what changes I should make in the code. Any help will be appreciated.

    let gumStream = null;
    let recorder = null;
    let audioContext = null;
  let recordButton = document.getElementById("recordButton");
  let stopButton = document.getElementById("stopButton");
  let pauseButton = document.getElementById("pauseButton");
    const startRecording = () => {
      let constraints = {
        audio: true,
        video: false,
      timer.style.color = "#78CF4D"
      recordButton.disabled = true;
      stopButton.disabled = false;
      pauseButton.disabled = false;
      audioContext = new window.AudioContext({
        sampleRate: 16000,
        //bufferLen: 4096
      console.log("sample rate: " + audioContext.sampleRate);
      navigator.mediaDevices
        .getUserMedia(constraints)
        .then(function (stream) {
          console.log("initializing Recorder.js ...");
          gumStream = stream;
          let input = audioContext.createMediaStreamSource(stream);
          recorder = new window.Recorder(input, {
            numChannels: 1,
            sampleBits: 16, // 8 or 16
            //bufferLen: 4096,
            mimeType: "audio/wav",
          recorder.record();
          if (stoptime == true) {
            stoptime = false;
            timerCycle();
        .catch(function (err) {
          //enable the record button if getUserMedia() fails
          timer.style.color = "#7C7F85"
          recordButton.disabled = false;
          stopButton.disabled = true;
          pauseButton.disabled = true;

I assume you've tested this in Chrome (or Edge or Opera). There is a long standing bug in Chrome. It sometimes inserts silence when you use an AudioContext to only record something without playing anything.

https://bugs.chromium.org/p/chromium/issues/detail?id=1016104

Unfortunately this is exactly what Recorder.js does.

I'm maintaining a similar library and ran into the same problem a while ago. Luckily there is a workaround. Chrome's MediaRecorder doesn't have the same bug. It will record without any outages. And it allows to record PCM audio wrapped in a webm container. My library uses that to record uncompressed audio.

In short I would expect the silence to go away if you use extendable-media-recorder instead.

We have tried extendable-media-recorder and It is working perfectly fine. Resolved audio signal drop issue. But it providing samplerate 48khz,. Our requirement is samplerate 16khz. Is there any way to specify samplerate? Please let me know. Thanks in advance. – Vijay D Mar 2 at 5:47 In case someone wonders the conversation continued over here: github.com/chrisguttandin/extendable-media-recorder/issues/674. – chrisguttandin Mar 5 at 23:22

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.