Created
August 20, 2014 01:10
-
-
Save atran/afb94ea1e3550e104598 to your computer and use it in GitHub Desktop.
Play MP3s with pyaudio
This file contains hidden or 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 pyaudio | |
import mad | |
import sys | |
if len(sys.argv) < 2: | |
print "Plays a wave file.\n\n" +\ | |
"Usage: %s filename.wav" % sys.argv[0] | |
sys.exit(-1) | |
mf = mad.MadFile(sys.argv[1]) | |
p = pyaudio.PyAudio() | |
# open stream | |
stream = p.open(format = | |
p.get_format_from_width(pyaudio.paInt32), | |
channels = 2, | |
rate = mf.samplerate(), | |
output = True) | |
# read data | |
data = mf.read() | |
# play stream | |
while data != None: | |
stream.write(data) | |
data = mf.read() | |
stream.close() | |
p.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment