Skip to content

Commit

Permalink
beep on activation WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AmateurAcademic committed Jan 29, 2023
1 parent 1f0ee10 commit 1e93daa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Binary file added examples/audio/activation.wav
Binary file not shown.
6 changes: 5 additions & 1 deletion examples/capture_activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import scipy.io.wavfile
import datetime
import argparse
from utils.beep import playBeep

# Parse input arguments
parser=argparse.ArgumentParser()
Expand Down Expand Up @@ -116,10 +117,13 @@
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 changes: 25 additions & 0 deletions examples/utils/beep.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1e93daa

Please sign in to comment.