From 5d925dae5916ea1adf684a4ea2676777a7ceba80 Mon Sep 17 00:00:00 2001 From: "Matthew D. Scholefield" Date: Mon, 27 Nov 2017 21:36:49 -0600 Subject: [PATCH] Make record.py use precise wrapper --- precise/record.py | 28 +++++++--------------------- setup.py | 3 ++- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/precise/record.py b/precise/record.py index 1a73197..2d5097b 100755 --- a/precise/record.py +++ b/precise/record.py @@ -2,12 +2,11 @@ # Copyright (c) 2017 Mycroft AI Inc. import sys -sys.path += ['.'] # noqa +sys.path += ['.', 'runner'] # noqa -from subprocess import Popen, PIPE -from pyaudio import PyAudio, paInt16 -from precise.common import pr from argparse import ArgumentParser +from precise_runner import PreciseRunner +from threading import Event def main(): @@ -15,24 +14,11 @@ def main(): parser.add_argument('-m', '--model', default='keyword.pb') args = parser.parse_args() - pa = PyAudio() - stream = pa.open(pr.sample_rate, 1, paInt16, True, frames_per_buffer=1024) + def on_prediction(prob): + print('!' if prob > 0.5 else '.', end='', flush=True) - proc = Popen(['python3', 'precise/stream.py', args.model, '1024'], stdin=PIPE, stdout=PIPE) - - print('Listening...') - try: - while True: - proc.stdin.write(stream.read(1024)) - proc.stdin.flush() - - prob = float(proc.stdout.readline()) - print('!' if prob > 0.5 else '.', end='', flush=True) - except KeyboardInterrupt: - print() - finally: - stream.stop_stream() - pa.terminate() + PreciseRunner('./precise/stream.py', args.model, on_prediction=on_prediction).start() + Event().wait() # Wait forever if __name__ == '__main__': main() diff --git a/setup.py b/setup.py index 36a774a..561bee0 100755 --- a/setup.py +++ b/setup.py @@ -22,7 +22,8 @@ setup( 'speechpy', 'pyaudio', 'keras', - 'wavio' + 'wavio', + # 'precise-runner' # Needs to get uploaded to PyPi first ], author='Matthew Scholefield',