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 sample rate issues #153

Merged
merged 2 commits into from
Oct 11, 2023
Merged

Fix sample rate issues #153

merged 2 commits into from
Oct 11, 2023

Conversation

juanmc2005
Copy link
Owner

@juanmc2005 juanmc2005 commented May 21, 2023

This PR addresses issue #152.

Changelog

  • MicrophoneAudioSource now detects supported sample rates and chooses the lowest possible one (higher than 16khz)
  • MicrophoneAudioSource no longer receives a sample_rate argument
  • Change block_size argument to block_duration in all audio sources
  • Fix bug in StreamingInference when resampling audio to pipeline's sample rate
  • Resample can now run on GPU by passing a device argument

@juanmc2005 juanmc2005 added the bug Something isn't working label May 21, 2023
@juanmc2005 juanmc2005 added this to the Version 0.8 milestone May 21, 2023
@juanmc2005 juanmc2005 marked this pull request as ready for review May 27, 2023 15:07
# Dynamic resampling if the audio source isn't compatible
if sample_rate != self.source.sample_rate:
msg = f"Audio source has sample rate {self.source.sample_rate}, " \
f"but pipeline's is {sample_rate}. Will resample."
logging.warning(msg)
self.stream = self.stream.pipe(
ops.map(blocks.Resample(self.source.sample_rate, sample_rate))
ops.map(blocks.Resample(self.source.sample_rate, sample_rate, self.pipeline.config.device))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resample before rearrange_audio_stream so the same audio is not resampled multiple times.
Because of how the first 5s buffer is filled at the beginning, this actually means that Resample will be called more times, but (unless it's running on GPU) each call should also be faster because the size of the chunk is reduced by 10 (80k vs 8k samples)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's track this for a future PR, see #180

@juanmc2005 juanmc2005 merged commit 410ab89 into develop Oct 11, 2023
@juanmc2005 juanmc2005 deleted the fix/samplerate branch October 11, 2023 14:13
@juanmc2005 juanmc2005 mentioned this pull request Oct 26, 2023
juanmc2005 added a commit that referenced this pull request Oct 28, 2023
* Add automatic sample rate detection in MicrophoneAudioSource. Fix resampling crash.

* Replace block_size by block_duration in audio source constructors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant