Last active
July 31, 2018 19:59
-
-
Save henriquegogo/b834fb683b8c5c0fc7d880624c7b2802 to your computer and use it in GitHub Desktop.
How to play a simple audio in python without any dependency
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
#!/usr/bin/padsp python | |
import sys | |
import wave | |
import ossaudiodev | |
audiofile = wave.open(sys.argv[1], 'r') | |
(nchannels, sampwidth, framerate, nframes, comptype, compname) = audiofile.getparams() | |
audiofile.setpos(0) | |
frames = audiofile.readframes(nframes) | |
audiofile.close() | |
dsp = ossaudiodev.open('w') | |
dsp.setparameters(ossaudiodev.AFMT_S16_LE, nchannels, framerate) | |
dsp.write(frames) | |
dsp.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment