Test file
This commit is contained in:
parent
e2b99a0270
commit
b03027218c
1 changed files with 0 additions and 33 deletions
33
play-test.py
33
play-test.py
|
@ -1,33 +0,0 @@
|
|||
"""PyAudio Example: Play a wave file."""
|
||||
|
||||
import wave
|
||||
import sys
|
||||
|
||||
import pyaudio
|
||||
|
||||
|
||||
CHUNK = 1024
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print(f'Plays a wave file. Usage: {sys.argv[0]} filename.wav')
|
||||
sys.exit(-1)
|
||||
|
||||
with wave.open(sys.argv[1], 'rb') as wf:
|
||||
# Instantiate PyAudio and initialize PortAudio system resources (1)
|
||||
p = pyaudio.PyAudio()
|
||||
|
||||
# Open stream (2)
|
||||
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
|
||||
channels=wf.getnchannels(),
|
||||
rate=wf.getframerate(),
|
||||
output=True)
|
||||
|
||||
# Play samples from the wave file (3)
|
||||
while len(data := wf.readframes(CHUNK)): # Requires Python 3.8+ for :=
|
||||
stream.write(data)
|
||||
|
||||
# Close stream (4)
|
||||
stream.close()
|
||||
|
||||
# Release PortAudio system resources (5)
|
||||
p.terminate()
|
Loading…
Reference in a new issue