Skip to content

Instantly share code, notes, and snippets.

@Mlawrence95
Created April 21, 2020 21:30
Show Gist options
  • Save Mlawrence95/fd20ac0a73c9643321c88704a9d8c9fa to your computer and use it in GitHub Desktop.
Save Mlawrence95/fd20ac0a73c9643321c88704a9d8c9fa to your computer and use it in GitHub Desktop.
[python] convert .mp3 file into a .wav, then visualize the sound using a matplotlib plot
import matplotlib.pyplot as plt
import soundfile as sf
from pydub import AudioSegment
# we want to convert source, mp3, into dest, a .wav file
source = "./recordings/test.mp3"
dest = "./recordings/test.wav"
# conversion - check!
sound = AudioSegment.from_mp3(src)
sound.export(dest, format="wav")
# we can now load in the .wav file as a numpy-style array like so
data, samplerate = sf.read(dest)
# make a plot of the sound data. Super rewarding - tada!
plt.plot(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment