Files
notecast/transcription/engines/vosk_engine.py
T
2026-06-25 00:30:59 +03:00

53 lines
1.1 KiB
Python

from transcription.engines.BaseEngine import BaseEngine
import wave, json
from vosk import Model, KaldiRecognizer
"""
import wave
import json
import sys
from multiprocessing.dummy import Pool
from vosk import Model, KaldiRecognizer
model = Model("en-us")
def recognize(line):
uid, fn = line.split()
wf = wave.open(fn, "rb")
rec = KaldiRecognizer(model, wf.getframerate())
text = ""
while True:
data = wf.readframes(1000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
jres = json.loads(rec.Result())
text = text + " " + jres["text"]
jres = json.loads(rec.FinalResult())
text = text + " " + jres["text"]
return uid + text
def main():
p = Pool(8)
texts = p.map(recognize, open(sys.argv[1], encoding="utf-8").readlines())
print ("\n".join(texts))
main()
"""
class VoskEngine(BaseEngine):
TARGET_SAMPLING_RATE = 16000
def loadModel(self) -> None:
...
def unloadModel(self) -> None:
...
def transcribeBatch(
self,
batch,
) -> str:
...