Skip to content

Instantly share code, notes, and snippets.

@eribeiro
Created August 9, 2012 17:04
Show Gist options
  • Save eribeiro/3305931 to your computer and use it in GitHub Desktop.
Save eribeiro/3305931 to your computer and use it in GitHub Desktop.
Convert a WMA file into MP3
#!/usr/bin/python
# This script converts a WMA file into a MP3 file.
# Requisites: mplayer e lame
# Disclaimer: it worked last time I checked, but it was a long time ago,
# so I put it here just to reference. Use it at your own risk.
import os
list = os.listdir(".")
for f in list:
file = f.strip();
if file.endswith(".wma"):
print "converting",file
new_file = file[:-3] + "mp3"
command = "mplayer -ao pcm \"" + file + "\""
os.system(command)
command = "lame -b 128 audiodump.wav \"" + new_file + "\"";
os.system(command)
command = "rm audiodump.wav"
os.system(command)
print "Finished. Bye, Bye"
@mahdialaaaldin
Copy link

it's not working :(

@8byr0
Copy link

8byr0 commented Feb 16, 2023

Python 3 version, working as expected:

#!/usr/bin/python
# This script converts a WMA file into a MP3 file.

# Requisites: mplayer e lame
# Disclaimer: it worked last time I checked, but it was a long time ago,
#             so I put it here just to reference. Use it at your own risk.

import os

list = os.listdir(".")
for f in list:
    file = f.strip()
    if file.endswith(".wma"):
        print ("converting",file)
        new_file = file[:-3] + "mp3"
        command = "mplayer -ao pcm \"" + file + "\""
        os.system(command)
        command = "lame -b 128 audiodump.wav \"" + new_file + "\""
        os.system(command)
        command = "rm audiodump.wav"
        os.system(command)

print( "Finished. Bye, Bye")

You can install mplayer like that (MacOS only):

brew install mplayer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment