Skip to content

Commit

Permalink
Avoid waiting state when data are present. Reduce size of chunks from…
Browse files Browse the repository at this point in the history
… recorder to 1024.

This improves responsiveness  and allows to have smaller chunks from recorder
  • Loading branch information
Papoteur committed Oct 24, 2021
1 parent 9c2c183 commit b448b71
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions nerd-dictation
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def file_remove_if_exists(filepath: str) -> bool:


def enqueue_output(vosk_out, queue):
for block in iter(partial(vosk_out.read, 16384), b""):
for block in iter(partial(vosk_out.read, 1024), b""):
queue.put(block)


Expand Down Expand Up @@ -644,22 +644,21 @@ def text_from_vosk_pipe(
# -1=cancel, 0=continue, 1=finish.
code = exit_fn(handled_any)

if idle_time > 0.0:
# Subtract processing time from the previous loop.
# Skip idling in the event dictation can't keep up with the recording.
idle_time_curr = time.time()
idle_time_test = idle_time - (idle_time_curr - idle_time_prev)
if idle_time_test > 0.0:
# Prevents excessive processor load.
time.sleep(idle_time_test)
idle_time_prev = time.time()
else:
idle_time_prev = idle_time_curr

try:
data = vosk_queue.get_nowait()
except Empty:
pass
if idle_time > 0.0:
# Subtract processing time from the previous loop.
# Skip idling in the event dictation can't keep up with the recording.
idle_time_curr = time.time()
idle_time_test = idle_time - (idle_time_curr - idle_time_prev)
if idle_time_test > 0.0:
# Prevents excessive processor load.
time.sleep(idle_time_test)
idle_time_prev = time.time()
else:
idle_time_prev = idle_time_curr
else:
ok = rec.AcceptWaveform(data)
if ok:
Expand Down

0 comments on commit b448b71

Please sign in to comment.