Skip to content

Instantly share code, notes, and snippets.

@MilesDowe
Created February 1, 2018 22:00
Show Gist options
  • Save MilesDowe/0a430956d9ea57257ade160a1acbff3b to your computer and use it in GitHub Desktop.
Save MilesDowe/0a430956d9ea57257ade160a1acbff3b to your computer and use it in GitHub Desktop.
One way to slice a wav file in memory and supply to scipy wavreader
from pydub import AudioSegment
from io import BytesIO
from scipy.io import wavfile
# get file
audio_file = AudioSegment.from_wav("some.wav")
# create output, supply to AudioSegment
audio_sample = BytesIO()
audio_file[2000:5000].export(audio_sample, format='wav')
# read into scipy.wavreader
audio_info = wavfile.read(BytesIO(audio_sample.getvalue()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment