mirror of
https://github.com/alphacep/vosk-api.git
synced 2026-01-21 04:54:39 +08:00
34 lines
800 B
Python
Executable File
34 lines
800 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from vosk import Model, KaldiRecognizer
|
|
import sys
|
|
import json
|
|
import os
|
|
|
|
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)
|
|
|
|
|
|
model = Model("model")
|
|
|
|
# Large vocabulary free form recognition
|
|
rec = KaldiRecognizer(model, 16000)
|
|
|
|
# You can also specify the possible word list
|
|
#rec = KaldiRecognizer(model, 16000, "zero oh one two three four five six seven eight nine")
|
|
|
|
wf = open(sys.argv[1], "rb")
|
|
wf.read(44) # skip header
|
|
|
|
while True:
|
|
data = wf.read(4000)
|
|
if len(data) == 0:
|
|
break
|
|
if rec.AcceptWaveform(data):
|
|
res = json.loads(rec.Result())
|
|
print (res['text'])
|
|
|
|
res = json.loads(rec.FinalResult())
|
|
print (res['text'])
|