Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to set sample rate from 48khz to 16khz. #674

Closed
VijayDhake opened this issue Mar 2, 2023 · 5 comments
Closed

Want to set sample rate from 48khz to 16khz. #674

VijayDhake opened this issue Mar 2, 2023 · 5 comments

Comments

@VijayDhake
Copy link

We are facing audio signal drop out issue in audio recording in chrome browser. But after using [extendable-media-recorder] that issue resolved. Thanks for it. But recorded audio is of 48khz but we want 16khz. Is there any way to set it. Please let me know. Thanks in advance.

@chrisguttandin
Copy link
Owner

Hi @VijayDhake,

there is no way to do this directly with a MediaRecorder. But it gets asked quite frequently and therefore I've added a section to the README which describes how it can be done with an AudioContext. I hope this helps.

@VijayDhake
Copy link
Author

VijayDhake commented Mar 8, 2023

Hi @chrisguttandin,

As you suggest, I have tried the following code to resample the audio.

const audioContext = new AudioContext({ sampleRate: 16000 });
const mediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(audioContext, { mediaStream: stream });
const mediaStreamAudioDestinationNode = new MediaStreamAudioDestinationNode(audioContext);

mediaStreamAudioSourceNode.connect(mediaStreamAudioDestinationNode);

const mediaRecorder = new MediaRecorder(mediaStreamAudioSourceNode.stream);

Above code is not working for me But If I change const mediaRecorder = new MediaRecorder(mediaStreamAudioSourceNode.stream); to const mediaRecorder = new MediaRecorder(mediaStreamAudioDestinationNode.stream, { mimeType: 'audio/wav' }); works fine for me. It is giving me a output 16khz, 16bit, 2 channel, But I require 16khz, 16bit, 1 channel. I have tried many ways to change it but it is not changing. There is any way to set channel. Please let me know. Thanks in advance.

@chrisguttandin
Copy link
Owner

Thanks for making me aware of the typo. I've fixed the readme. 66b9451

I have tried many ways to change it but it is not changing.

What exactly did you try and didn't work?

I think setting the channelCount of the MediaStreamAudioDestinationNode should work.

const mediaStreamAudioDestinationNode = new MediaStreamAudioDestinationNode(
    audioContext,
    {
        channelCount: 1
    }
);

@VijayDhake
Copy link
Author

VijayDhake commented Mar 14, 2023

        let stream = await navigator.mediaDevices.getUserMedia({ audio: true });

            gumStream = stream;

          const audioContext = new 
![console](https://user-images.githubusercontent.com/67089587/224911604-ae2c786e-9ef2-42f5-b318-d7ef5d5520cd.png)
AudioContext({ sampleRate: 16000 });    
          const mediaStreamAudioSourceNode = new MediaStreamAudioSourceNode(audioContext, { mediaStream: stream });
          //console.log("mediaStreamAudioSourceNode", mediaStreamAudioSourceNode)

          const mediaStreamAudioDestinationNode = new MediaStreamAudioDestinationNode(audioContext);
          //console.log("mediaStreamAudioDestinationNode", mediaStreamAudioDestinationNode)

          mediaStreamAudioSourceNode.connect(mediaStreamAudioDestinationNode);

          recorder = new MediaRecorder(mediaStreamAudioDestinationNode.stream, { mimeType: 'audio/wav', channelCount: 1 });
          recorder.start();

Have already added and tried above solution. But Still output showing 2 channel. Attached screenshot of output.

console
mediainfo

@chrisguttandin
Copy link
Owner

Could you please try again with the latest version. I hope the fix for #655 fixed this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants