mirror of
https://github.com/alphacep/vosk-api.git
synced 2026-03-23 00:01:25 +08:00
29 lines
700 B
Python
Executable File
29 lines
700 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
from vosk import Model, KaldiRecognizer
|
|
import os
|
|
|
|
if not os.path.exists("model-en"):
|
|
print ("Please download the model from https://github.com/alphacep/kaldi-android-demo/releases and unpack as 'model' in the current folder.")
|
|
exit (1)
|
|
|
|
import pyaudio
|
|
|
|
p = pyaudio.PyAudio()
|
|
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8000)
|
|
stream.start_stream()
|
|
|
|
model = Model("model-en")
|
|
rec = KaldiRecognizer(model, 16000)
|
|
|
|
while True:
|
|
data = stream.read(2000)
|
|
if len(data) == 0:
|
|
break
|
|
if rec.AcceptWaveform(data):
|
|
print(rec.Result())
|
|
else:
|
|
print(rec.PartialResult())
|
|
|
|
print(rec.FinalResult())
|