openwakeword/examples/utils/beep.py

22 lines
484 B
Python
Raw Permalink Normal View History

2023-01-29 22:31:45 +01:00
import pyaudio
import wave
def playBeep(file_path, audio):
2023-01-29 22:31:45 +01:00
CHUNK = 1024
wf = wave.open(file_path, 'rb')
stream = audio.open(format=audio.get_format_from_width(wf.getsampwidth()),
2023-01-29 22:31:45 +01:00
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
data = wf.readframes(CHUNK)
while data != b'':
2023-01-29 22:31:45 +01:00
stream.write(data)
data = wf.readframes(CHUNK)
stream.stop_stream()
stream.close()