Make record.py use precise wrapper
This commit is contained in:
parent
5a1fe8c078
commit
5d925dae59
@ -2,12 +2,11 @@
|
|||||||
# Copyright (c) 2017 Mycroft AI Inc.
|
# Copyright (c) 2017 Mycroft AI Inc.
|
||||||
|
|
||||||
import sys
|
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 argparse import ArgumentParser
|
||||||
|
from precise_runner import PreciseRunner
|
||||||
|
from threading import Event
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -15,24 +14,11 @@ def main():
|
|||||||
parser.add_argument('-m', '--model', default='keyword.pb')
|
parser.add_argument('-m', '--model', default='keyword.pb')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
pa = PyAudio()
|
def on_prediction(prob):
|
||||||
stream = pa.open(pr.sample_rate, 1, paInt16, True, frames_per_buffer=1024)
|
|
||||||
|
|
||||||
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)
|
print('!' if prob > 0.5 else '.', end='', flush=True)
|
||||||
except KeyboardInterrupt:
|
|
||||||
print()
|
PreciseRunner('./precise/stream.py', args.model, on_prediction=on_prediction).start()
|
||||||
finally:
|
Event().wait() # Wait forever
|
||||||
stream.stop_stream()
|
|
||||||
pa.terminate()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user