Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Last active July 31, 2018 19:59
Show Gist options
  • Save henriquegogo/b834fb683b8c5c0fc7d880624c7b2802 to your computer and use it in GitHub Desktop.
Save henriquegogo/b834fb683b8c5c0fc7d880624c7b2802 to your computer and use it in GitHub Desktop.
How to play a simple audio in python without any dependency
#!/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