mirror of
https://github.com/alphacep/vosk-api.git
synced 2026-01-20 20:44:12 +08:00
34 lines
866 B
Python
Executable File
34 lines
866 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from vosk import Model, KaldiRecognizer, SetLogLevel
|
|
import sys
|
|
import os
|
|
import wave
|
|
import subprocess
|
|
|
|
SetLogLevel(0)
|
|
|
|
if not os.path.exists("model"):
|
|
print ("Please download the model from https://alphacephei.com/vosk/models and unpack as 'model' in the current folder.")
|
|
exit (1)
|
|
|
|
sample_rate=16000
|
|
model = Model("model")
|
|
rec = KaldiRecognizer(model, sample_rate)
|
|
|
|
process = subprocess.Popen(['ffmpeg', '-loglevel', 'quiet', '-i',
|
|
sys.argv[1],
|
|
'-ar', str(sample_rate) , '-ac', '1', '-f', 's16le', '-'],
|
|
stdout=subprocess.PIPE)
|
|
|
|
while True:
|
|
data = process.stdout.read(4000)
|
|
if len(data) == 0:
|
|
break
|
|
if rec.AcceptWaveform(data):
|
|
print(rec.Result())
|
|
else:
|
|
print(rec.PartialResult())
|
|
|
|
print(rec.FinalResult())
|