realtime.py voice-to-text added, needs to be integrated
parent
61e42c8bb6
commit
699ae46f06
|
|
@ -0,0 +1 @@
|
|||
vosk-model-small-en-us-0.15/
|
||||
|
|
@ -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')
|
||||
Loading…
Reference in New Issue