Make record.py use precise wrapper

This commit is contained in:
Matthew D. Scholefield 2017-11-27 21:36:49 -06:00
parent 5a1fe8c078
commit 5d925dae59
2 changed files with 9 additions and 22 deletions

View File

@ -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()

View File

@ -22,7 +22,8 @@ setup(
'speechpy',
'pyaudio',
'keras',
'wavio'
'wavio',
# 'precise-runner' # Needs to get uploaded to PyPi first
],
author='Matthew Scholefield',