alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.36k stars 1.04k forks source link

Failure to create model #1510

Open Wines101 opened 5 months ago

Wines101 commented 5 months ago

My pre-trained en-us model downloaded from the vosk website keeps failing to build. It was working and building perfectly fine with the same model, I am not sure what to change.

This is my code.


from vosk import Model, KaldiRecognizer
import wave
import json

def transcribe(file_path): model = Model('src/vosk-model-en-us-0.22') recognizer = KaldiRecognizer(model, 16000) # includes the path to the audiofile and the bitrate

file = wave.open(file_path, "rb")

transcribed_text_list = []

while True:
    data = file.readframes(4000)
    if len(data) == 0:
        break
    if recognizer.AcceptWaveform(data):
        result = json.loads(recognizer.Result())
        transcribed_text_list.append(result['text'])

final_result = json.loads(recognizer.FinalResult())
transcribed_text_list.append(final_result['text'])

complete_text = ' '.join(transcribed_text_list)

return complete_text

> This is the output.

LOG (VoskAPI:ReadDataFiles():model.cc:213) Decoding params beam=13 max-active=7000 lattice-beam=6 LOG (VoskAPI:ReadDataFiles():model.cc:216) Silence phones 1:2:3:4:5:11:12:13:14:15 LOG (VoskAPI:RemoveOrphanNodes():nnet-nnet.cc:948) Removed 0 orphan nodes. LOG (VoskAPI:RemoveOrphanComponents():nnet-nnet.cc:847) Removing 0 orphan components. LOG (VoskAPI:ReadDataFiles():model.cc:248) Loading i-vector extractor from src/vosk-model-en-us-0.22/ivector/final.ie LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:183) Computing derived variables for iVector extractor LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:204) Done. LOG (VoskAPI:ReadDataFiles():model.cc:279) Loading HCLG from src/vosk-model-en-us-0.22/graph/HCLG.fst LOG (VoskAPI:ReadDataFiles():model.cc:297) Loading words from src/vosk-model-en-us-0.22/graph/words.txt LOG (VoskAPI:ReadDataFiles():model.cc:308) Loading winfo src/vosk-model-en-us-0.22/graph/phones/word_boundary.int LOG (VoskAPI:ReadDataFiles():model.cc:315) Loading subtract G.fst model from src/vosk-model-en-us-0.22/rescore/G.fst LOG (VoskAPI:ReadDataFiles():model.cc:317) Loading CARPA model from src/vosk-model-en-us-0.22/rescore/G.carpa ERROR (VoskAPI:ReadInternal():const-arpa-lm.cc:610) ConstArpaLm section reading failed. Traceback (most recent call last): File "/workspaces/speech_recognition_libraries/src/vosk_demo.py", line 33, in transcribe(file_path) File "/workspaces/speech_recognition_libraries/src/vosk_demo.py", line 6, in transcribe model = Model('src/vosk-model-en-us-0.22') File "/usr/local/python/3.10.13/lib/python3.10/site-packages/vosk/init.py", line 57, in init raise Exception("Failed to create a model") Exception: Failed to create a model

nshmyrev commented 4 months ago

Probably model files are corrupted or not enough memory. It needs quite a big memory chunk