commit 00a615c29e057e302e1a7e9b2a0c4bafc0ba3f09 Author: radxa Date: Thu Oct 23 08:20:36 2025 +0000 first diff --git a/realtime.py b/realtime.py new file mode 100644 index 0000000..4c1d1fe --- /dev/null +++ b/realtime.py @@ -0,0 +1,26 @@ +import sounddevice as sd +import queue +import sys +import json +from vosk import Model, KaldiRecognizer +model = Model("/home/radxa/vosk-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')