31 lines
757 B
Python
Executable file
31 lines
757 B
Python
Executable file
#!/usr/bin/python3
|
|
|
|
from vosk import Model, KaldiRecognizer
|
|
import sys
|
|
import json
|
|
import os
|
|
import wave
|
|
|
|
model_path = "model"
|
|
|
|
if not os.path.exists(model_path):
|
|
print ("Please download the model from https://github.com/alphacep/kaldi-android-demo/releases and unpack as 'model' in the current folder.")
|
|
exit (1)
|
|
|
|
model = Model(model_path)
|
|
|
|
with wave.open(sys.argv[1], "rb") as wf:
|
|
frame_rate = wf.getframerate()
|
|
|
|
rec = KaldiRecognizer(model, frame_rate)
|
|
|
|
while True:
|
|
data = wf.readframes(2000)
|
|
if len(data) == 0:
|
|
break
|
|
if rec.AcceptWaveform(data):
|
|
print(json.loads(rec.Result()))
|
|
else:
|
|
print(json.loads(rec.PartialResult()))
|
|
|
|
print(json.loads(rec.FinalResult()))
|