diff --git a/precise_lite/__init__.py b/precise_lite/__init__.py index df904b5..9b1c187 100644 --- a/precise_lite/__init__.py +++ b/precise_lite/__init__.py @@ -1 +1 @@ -__version__ = '0.4.0a1' +__version__ = '0.4.0a2' diff --git a/precise_lite/runner.py b/precise_lite/runner.py index a6296e2..87e3cd7 100644 --- a/precise_lite/runner.py +++ b/precise_lite/runner.py @@ -1,15 +1,11 @@ -import numpy as np -from os.path import join -from precise_lite_runner import PreciseRunner -from precise_lite_runner.runner import ListenerEngine -from prettyparse import Usage -from random import randint -from shutil import get_terminal_size +import time from threading import Event +import numpy as np from precise_lite.network_runner import Listener -from precise_lite.scripts.base_script import BaseScript -from precise_lite.util import save_audio, buffer_to_audio, activate_notify +from precise_lite.util import buffer_to_audio +from precise_lite_runner import PreciseRunner +from precise_lite_runner.runner import ListenerEngine class ReadWriteStream: @@ -17,6 +13,7 @@ class ReadWriteStream: Class used to support writing binary audio data at any pace, optionally chopping when the buffer gets too large """ + def __init__(self, s=b'', chop_samples=-1): self.buffer = s self.write_event = Event() @@ -53,14 +50,16 @@ class ReadWriteStream: class PreciseLiteListener: def __init__(self, model, chunk_size, trigger_level, sensitivity, - on_activation=None, on_prediction=None): + on_activation=None, on_prediction=None, stream=None): on_activation = on_activation or self.on_activation on_prediction = on_prediction or self.on_prediction self.listener = Listener(model, chunk_size) - self.audio_buffer = np.zeros(self.listener.pr.buffer_samples, dtype=float) + self.audio_buffer = np.zeros(self.listener.pr.buffer_samples, + dtype=float) self.engine = ListenerEngine(self.listener, chunk_size) self.engine.get_prediction = self.get_prediction self.runner = PreciseRunner(self.engine, trigger_level, + stream=stream, sensitivity=sensitivity, on_activation=on_activation, on_prediction=on_prediction) @@ -73,7 +72,8 @@ class PreciseLiteListener: def get_prediction(self, chunk): audio = buffer_to_audio(chunk) - self.audio_buffer = np.concatenate((self.audio_buffer[len(audio):], audio)) + self.audio_buffer = np.concatenate( + (self.audio_buffer[len(audio):], audio)) return self.listener.update(audio) def start(self): diff --git a/runner/precise_lite_runner/runner.py b/runner/precise_lite_runner/runner.py index dad89c6..47408ea 100644 --- a/runner/precise_lite_runner/runner.py +++ b/runner/precise_lite_runner/runner.py @@ -19,7 +19,7 @@ from subprocess import PIPE, Popen from threading import Thread, Event -class Engine(object): +class Engine: def __init__(self, chunk_size=2048): self.chunk_size = chunk_size @@ -73,7 +73,7 @@ class ListenerEngine(Engine): self.get_prediction = listener.update -class ReadWriteStream(object): +class ReadWriteStream: """ Class used to support writing binary audio data at any pace, optionally chopping when the buffer gets too large @@ -142,7 +142,7 @@ class TriggerDetector: return False -class PreciseRunner(object): +class PreciseRunner: """ Wrapper to use Precise. Example: >>> def on_act():