Created
April 21, 2020 21:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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