Add files via upload
This commit is contained in:
1 parent
b599082b22
commit
c780b2ef21
16 files changed
+1324
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import sounddevice as sd
|
||||
import vosk
|
||||
import queue
|
||||
import sys
|
||||
import json
|
||||
import threading
|
||||
|
||||
MODEL_PATH = "C:/Users/90553/Downloads/vosk/vosk-model-small-en-us-0.15" # put your path
|
||||
model = vosk.Model(MODEL_PATH)
|
||||
|
||||
q = queue.Queue()
|
||||
stop_listening_flag = threading.Event()
|
||||
|
||||
def callback(indata, frames, time, status):
|
||||
if status:
|
||||
print(status, file=sys.stderr)
|
||||
q.put(bytes(indata))
|
||||
|
||||
def record_voice(prompt="🎙 I'm listening, sir..."):
|
||||
"""
|
||||
Blocking call, returns the first recognized sentence.
|
||||
"""
|
||||
print(prompt)
|
||||
rec = vosk.KaldiRecognizer(model, 16000)
|
||||
with sd.RawInputStream(samplerate=16000, blocksize=8000, dtype='int16',
|
||||
channels=1, callback=callback):
|
||||
while not stop_listening_flag.is_set():
|
||||
try:
|
||||
data = q.get(timeout=0.1)
|
||||
except queue.Empty:
|
||||
continue
|
||||
if rec.AcceptWaveform(data):
|
||||
result = json.loads(rec.Result())
|
||||
text = result.get("text", "")
|
||||
if text.strip():
|
||||
print("👤 You:", text)
|
||||
return text
|
||||
return ""
|
||||
Reference in new issue
Block a user