Skip to content

Instantly share code, notes, and snippets.

@dcalacci
Created November 14, 2014 01:21
Show Gist options
  • Save dcalacci/39de37ed993f23c86b55 to your computer and use it in GitHub Desktop.
Save dcalacci/39de37ed993f23c86b55 to your computer and use it in GitHub Desktop.
resampling PCM audio
from scipy.signal import resample
def resample_pcm(samplerate, channels, resample_rate=RESAMPLE_RATE):
"""Resamples the given PCM stream to resample_rate.
"""
new_length = resample_rate * (len(channels) / samplerate)
# convert to int so we have more exact matches
return resample(channels, new_length).astype(int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment