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

Fix Dynamic Sample Rate Detection for Audio Compatibility #7

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mmtmn
Copy link

@mmtmn mmtmn commented Oct 1, 2024

On Firefox, we get the issue:

Here is the explanation to this fix:

Connecting AudioNodes from AudioContexts with different sample-rate is currently not supported.

  • getSystemSampleRate(): This helper function will dynamically detect the system's default sample rate by creating a new AudioContext instance and querying its sampleRate property. This is important because different browsers and devices may have different default sample rates, and this will prevent sample rate mismatch issues.
  • Changes in WavStreamPlayer and WavRecorder: By using new AudioContext().sampleRate as the fallback, the application adapts to the system's default sample rate if none is explicitly provided. This is critical for maintaining compatibility across different browsers, particularly Firefox, which enforces stricter rules on sample rates.

These are the changes needed to ensure your application works seamlessly with the system's default audio configuration without causing issues, particularly in Firefox.

… dynamic sample rate detection.

Detect the system's default sample rate dynamically instead of hardcoding it to 24000 Hz, especially since Firefox is more sensitive to sample rate discrepancies.
Use the system's default sample rate when creating the audio context. This ensures that if no specific sample rate is provided, it will default to the system's preferred sample rate.
Use the system's sample rate as the default if none is provided.
@khorwood-openai
Copy link
Contributor

For the Realtime API we need a 24,000 Hz sample rate. Do you think there's another solution to this problem? This is Firefox only, correct?

@Grant-CP
Copy link

Grant-CP commented Oct 1, 2024

@khorwood-openai From my brief testing this happens on Firefox and not Safari.

@mmtmn
Copy link
Author

mmtmn commented Oct 1, 2024

For the Realtime API we need a 24,000 Hz sample rate. Do you think there's another solution to this problem? This is Firefox only, correct?

Ah, I see. I think there might be a way around this but I'm not sure. I'll report back in a few minutes.

@mmtmn
Copy link
Author

mmtmn commented Oct 1, 2024

Working on a resample audio to 24,000 Hz solution to this pull request, should be updating this shortly

@mmtmn
Copy link
Author

mmtmn commented Oct 1, 2024

Ok, I think resampling should be working, just improving a bit on the resampling efficiency. Once I get the resampling efficient I'll update the PR.

@mmtmn
Copy link
Author

mmtmn commented Oct 1, 2024

@khorwood-openai I've added resampling to this pull request, it should be good to review now.

@samiy803
Copy link

@khorwood-openai any updates on this? This fixes issue #5

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

Successfully merging this pull request may close these issues.

4 participants