Alternatively, if you want a wav file, you could install something to convert it to a wav file. Pymedia is a good module for that. The pymedia version made for current versions of python could be difficult to find, however, I have found a good place to get it at: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pymedia
Here is a function that will convert the mp3 file to a wav file, and save a wav file in your file system:
def dumpWAV( name ):
import pymedia.audio.acodec as acodec
import pymedia.muxer as muxer
import time, wave, string, os
name1= str.split( name, '.' )
name2= string.join( name1[ : len( name1 )- 1 ] )
# Open demuxer first
dm= muxer.Demuxer( name1[ -1 ].lower() )
dec= None
f= open( name, 'rb' )
snd= None
s= " "
while len( s ):
s= f.read( 20000 )
if len( s ):
frames= dm.parse( s )
for fr in frames:
if dec== None:
# Open decoder
dec= acodec.Decoder( dm.streams[ 0 ] )
r= dec.decode( fr[ 1 ] )
if r and r.data:
if snd== None:
snd= wave.open( name2+ '.wav', 'wb' )
snd.setparams( (r.channels, 2, r.sample_rate, 0, 'NONE','') )
snd.writeframes( r.data )
You may want to just play the mp3, but it is significantly easier to play a wav file in python. For example, pygame's support of mp3 files is limited, but it can always play a wav file.