Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Example modified from
- # <http://people.csail.mit.edu/hubert/pyaudio/#docs>
- """PyAudio Example: Play a WAVE file."""
- import pyaudio
- import wave
- import sys
- # Get from the filepool
- src = exp.get_file('example.wav')
- # Index of the output device or None for default
- output_device_index = None
- # The chunk size for playing back the stream
- chunk_size = 1024
- # Initialize PyAudio and open an output stream
- p = pyaudio.PyAudio()
- wf = wave.open(src, 'rb')
- stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
- channels=wf.getnchannels(),
- rate=wf.getframerate(),
- output=True,
- output_device_index=output_device_index)
- # Read and play stream data until the stream is empty
- data = wf.readframes(chunk_size)
- while data != '':
- stream.write(data)
- data = wf.readframes(chunk_size)
- # Clean up
- stream.stop_stream()
- stream.close()
- p.terminate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement