Member-only story
Beyond visual and textual applications, Python also serves as an effective swiss-army knife for working with audio data thanks to its versatile math libraries and external music packages. Signals processing techniques come built-in without needing external middleware.
By exploring some audio processing foundations with Python, hopefully we can better appreciate how a little coding goes a long way when manipulating sounds to build creative musical applications. Let’s tune in to some examples!
Getting Set Up
Before applying audio operations, we need utilities for reading wav files and playing byte buffers as sound. The standard library wave module handles wav file interfaces:
import wave
wav_file = wave.open("input_sound.wav", mode="rb")
frame_bytes = bytearray(list(wav_file.readframes(wav_file.getnframes())))
sampled_rate = wav_file.getframerate()
This reads an entire wav file’s raw bytes for processing in a bytearray buffer along with extracting its time sample rate.
The simpleaudio module plays back byte arrays:
import simpleaudio
play_obj = simpleaudio.play_buffer(frame_bytes, wav_file.getnchannels()…