diff --git a/precise/network_runner.py b/precise/network_runner.py index f19b6d0..e07edf7 100644 --- a/precise/network_runner.py +++ b/precise/network_runner.py @@ -11,14 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import numpy as np from abc import abstractmethod, ABCMeta from importlib import import_module from os.path import splitext from typing import * from typing import BinaryIO -import numpy as np - from precise.model import load_precise_model from precise.params import inject_params from precise.util import buffer_to_audio diff --git a/precise/params.py b/precise/params.py index e92ebd2..1ae10d8 100644 --- a/precise/params.py +++ b/precise/params.py @@ -11,11 +11,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from math import floor + +import attr +import json from os.path import isfile -import json -from math import floor -import attr @attr.s(frozen=True) class ListenerParams: diff --git a/precise/pocketsphinx/listener.py b/precise/pocketsphinx/listener.py index aacf48a..060c68b 100644 --- a/precise/pocketsphinx/listener.py +++ b/precise/pocketsphinx/listener.py @@ -12,11 +12,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import numpy as np from typing import * from typing import BinaryIO -import numpy as np - from precise.params import pr from precise.util import audio_to_buffer diff --git a/precise/pocketsphinx/scripts/listen.py b/precise/pocketsphinx/scripts/listen.py index 225917b..3f2bfb0 100755 --- a/precise/pocketsphinx/scripts/listen.py +++ b/precise/pocketsphinx/scripts/listen.py @@ -12,15 +12,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from prettyparse import create_parser from random import randint from threading import Event -from prettyparse import create_parser - from precise.pocketsphinx.listener import PocketsphinxListener +from precise.util import activate_notify from precise_runner import PreciseRunner from precise_runner.runner import ListenerEngine -from precise.util import activate_notify usage = ''' Run Pocketsphinx on microphone audio input diff --git a/precise/pocketsphinx/scripts/test.py b/precise/pocketsphinx/scripts/test.py index cf05b3e..cb11c70 100755 --- a/precise/pocketsphinx/scripts/test.py +++ b/precise/pocketsphinx/scripts/test.py @@ -13,9 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import wave -from subprocess import check_output, PIPE - from prettyparse import create_parser +from subprocess import check_output, PIPE from precise.pocketsphinx.listener import PocketsphinxListener from precise.scripts.test import show_stats, Stats diff --git a/precise/scripts/collect.py b/precise/scripts/collect.py index 2b26913..f22103f 100644 --- a/precise/scripts/collect.py +++ b/precise/scripts/collect.py @@ -12,15 +12,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tty -import wave -from os.path import isfile from select import select from sys import stdin from termios import tcsetattr, tcgetattr, TCSADRAIN -from prettyparse import create_parser import pyaudio +import tty +import wave +from os.path import isfile +from prettyparse import create_parser usage = ''' Record audio samples for use with precise @@ -66,8 +66,8 @@ EXIT_KEY_CODE = 27 def record_until(p, should_return, args): chunk_size = 1024 - stream = p.open(format=p.get_format_from_width(args.width), channels=args.channels, rate=args.rate, - input=True, frames_per_buffer=chunk_size) + stream = p.open(format=p.get_format_from_width(args.width), channels=args.channels, + rate=args.rate, input=True, frames_per_buffer=chunk_size) frames = [] while not should_return(): diff --git a/precise/scripts/convert.py b/precise/scripts/convert.py index 8a31914..a06637a 100755 --- a/precise/scripts/convert.py +++ b/precise/scripts/convert.py @@ -15,9 +15,8 @@ # limitations under the License. import os from os.path import split, isfile -from shutil import copyfile - from prettyparse import create_parser +from shutil import copyfile usage = ''' Convert wake word model from Keras to TensorFlow diff --git a/precise/scripts/engine.py b/precise/scripts/engine.py index 199e793..72b8f62 100755 --- a/precise/scripts/engine.py +++ b/precise/scripts/engine.py @@ -12,9 +12,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import os import sys +import os from prettyparse import create_parser from precise import __version__ diff --git a/precise/scripts/eval.py b/precise/scripts/eval.py index 8744ca4..56a82e2 100755 --- a/precise/scripts/eval.py +++ b/precise/scripts/eval.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. import json - from os.path import isfile, isdir from prettyparse import create_parser diff --git a/precise/scripts/listen.py b/precise/scripts/listen.py index ff508d8..46b0314 100755 --- a/precise/scripts/listen.py +++ b/precise/scripts/listen.py @@ -12,13 +12,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import numpy as np from os.path import join +from prettyparse import create_parser from random import randint from threading import Event -import numpy as np -from prettyparse import create_parser - from precise.network_runner import Listener from precise.util import save_audio, buffer_to_audio, activate_notify from precise_runner import PreciseRunner @@ -74,7 +73,8 @@ def main(): engine = ListenerEngine(listener, args.chunk_size) engine.get_prediction = get_prediction - runner = PreciseRunner(engine, args.threshold, on_activation=on_activation, on_prediction=on_prediction) + runner = PreciseRunner(engine, args.threshold, on_activation=on_activation, + on_prediction=on_prediction) runner.start() Event().wait() # Wait forever diff --git a/precise/scripts/test.py b/precise/scripts/test.py index fc1c0ec..4950163 100755 --- a/precise/scripts/test.py +++ b/precise/scripts/test.py @@ -16,7 +16,6 @@ from collections import namedtuple from prettyparse import create_parser -from precise.model import load_precise_model from precise.network_runner import Listener from precise.params import inject_params from precise.train_data import TrainData diff --git a/precise/train_data.py b/precise/train_data.py index caa005e..6663b7e 100644 --- a/precise/train_data.py +++ b/precise/train_data.py @@ -12,18 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. import json +import numpy as np from argparse import ArgumentParser -from contextlib import suppress from glob import glob from hashlib import md5 -from os.path import join, isfile, dirname +from os.path import join, isfile +from prettyparse import add_to_parser from typing import * -import numpy as np -from prettyparse import add_to_parser - from precise.util import find_wavs -from precise.vectorization import load_vector, vectorize_inhibit, vectorize +from precise.vectorization import load_vector, vectorize_inhibit class TrainData: diff --git a/precise/util.py b/precise/util.py index 0f1bc2d..80006d0 100644 --- a/precise/util.py +++ b/precise/util.py @@ -11,10 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import * - import numpy as np from os.path import join, dirname, abspath +from typing import * from precise.params import pr @@ -55,6 +54,7 @@ def save_audio(filename: str, audio: np.ndarray): save_audio = (audio * np.iinfo(np.int16).max).astype(np.int16) wavio.write(filename, save_audio, pr.sample_rate, sampwidth=pr.sample_depth, scale='none') + def play_audio(filename: str): """ Args: @@ -66,12 +66,14 @@ def play_audio(filename: str): player = 'play' if platform.system() == 'Darwin' else 'aplay' Popen([player, '-q', filename]) + def activate_notify(): audio = 'data/activate.wav' audio = abspath(dirname(abspath(__file__)) + '/../' + audio) play_audio(audio) + def glob_all(folder: str, filt: str) -> List[str]: """Recursive glob""" import os diff --git a/precise/vectorization.py b/precise/vectorization.py index 79b8ea1..3ff26fe 100644 --- a/precise/vectorization.py +++ b/precise/vectorization.py @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import hashlib -from typing import * -import json - import numpy as np +from typing import * from precise.params import pr from precise.util import load_audio