beep on activation WIP

This commit is contained in:
Bartmoss 2023-01-29 22:31:45 +01:00
parent 1f0ee10efe
commit 1e93daa4aa
3 changed files with 30 additions and 1 deletions

Binary file not shown.

View file

@ -34,6 +34,7 @@ from openwakeword.model import Model
import scipy.io.wavfile
import datetime
import argparse
from utils.beep import playBeep
# Parse input arguments
parser=argparse.ArgumentParser()
@ -116,10 +117,13 @@ if __name__ == "__main__":
last_save = time.time()
activation_times[mdl] = []
detect_time = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
print(f'Detected activation from \"{mdl}\" model at time {detect_time}!')
# Capture total of 5 seconds, with the audio associated with the
# activation around the ~4 second point
audio_context = np.array(list(owwModel.preprocessor.raw_data_buffer)[-16000*5:]).astype(np.int16)
fname = detect_time + f"_{mdl}.wav"
scipy.io.wavfile.write(os.path.join(os.path.abspath(args.output_dir), fname), 16000, audio_context)
scipy.io.wavfile.write(os.path.join(os.path.abspath(args.output_dir), fname), 16000, audio_context)
playBeep('audio/activation.wav')

25
examples/utils/beep.py Normal file
View file

@ -0,0 +1,25 @@
import pyaudio
import wave
def playBeep(file_path):
CHUNK = 1024
wf = wave.open(file_path, 'rb')
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
data = wf.readframes(CHUNK)
while data != '':
stream.write(data)
data = wf.readframes(CHUNK)
#stream.stop_stream()
#stream.close()
#p.terminate()