realtime.py voice-to-text added, needs to be integrated

master
Jake Wilkinson 2025-10-24 10:27:05 +00:00
parent 61e42c8bb6
commit 699ae46f06
2 changed files with 27 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
vosk-model-small-en-us-0.15/

26
realtime.py Normal file
View File

@ -0,0 +1,26 @@
import sounddevice as sd
import queue
import sys
import json
from vosk import Model, KaldiRecognizer
model = Model("./vosk-model-small-en-us-0.15")
rec = KaldiRecognizer(model, 16000)
q = queue.Queue()
def callback(indata, frames, time, status):
if status:
print(status, file=sys.stderr)
q.put(bytes(indata))
with sd.RawInputStream(samplerate=16000, blocksize=8000, dtype='int16',
channels=1, callback=callback):
print("Listening... Speak into the mic.")
while True:
data = q.get()
if rec.AcceptWaveform(data):
result = json.loads(rec.Result())
print(".", result)
else:
partial = json.loads(rec.PartialResult())
print("...", partial, end='\r')