Created
January 9, 2022 18:15
-
-
Save rntz/75811e0400a296834cbb0ce7b3dfbf28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# please don't commit this to user repos, it uses unstable talon APIs - in | |
# particular, the audio metadata. | |
from talon import speech_system | |
import logging | |
# ignore all phrase recognitions that take fewer than this many ms. | |
IGNORE_THRESHOLD = 100 | |
# name: (bad_threshold, worse_threshold) | |
# you probably want to modify these for your computer & usage patterns. | |
TIMINGS = {'audio': (10000, 30000), | |
'compile': (500, 1000), | |
'emit': (200, 400), | |
'decode': (30, 60), | |
'total': (1000, 2000), | |
} | |
def format_time(name, time, lo, hi): | |
unesc = "" if time < lo else "\033[0m" | |
esc = ("" if time < lo else | |
# yellow if above lo threshold | |
"\033[33m" if time < hi else | |
# red if above hi threshold | |
"\033[31m") | |
return esc + f"{name}={time:.3f}ms" + unesc | |
def print_timings(j): | |
try: | |
phrase = ' '.join(j['phrase']) | |
meta = j['_metadata'] | |
timings = [(name, meta[name+'_ms'], lo, hi) | |
for name, (lo, hi) in TIMINGS.items()] | |
except KeyError: pass | |
else: | |
if meta['total_ms'] < IGNORE_THRESHOLD: return | |
logging.info(f'PHRASE {phrase}') | |
if meta['compile_ms'] > 1: logging.info('-> dfa recompile') | |
logging.info(" ".join(format_time(*x) for x in timings)) | |
speech_system.register('phrase', print_timings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment