kaldi-asr / kaldi

kaldi-asr/kaldi is the official location of the Kaldi project.
http://kaldi-asr.org
Other
14.11k stars 5.31k forks source link

Can't initialise KaldiRecognizer with a simple list of words #4925

Closed waveywhite closed 1 month ago

waveywhite commented 1 month ago

According to the example at python/example/test_text.py we should be able to do this:

rec = KaldiRecognizer(model, 16000, "zero oh one two three four five six seven eight nine")

However this results in:

ERROR: Parse: Unknown starting character 'z'
WARNING (VoskAPI:UpdateGrammarFst():recognizer.cc:283) Expecting array of strings, got: 'zero oh one two three four five six seven eight nine'
Segmentation fault (core dumped)

From the error it seems that the underlying C++ code is expecting an array so I also tried the following:

rec = KaldiRecognizer(model, 16000, ["zero", "oh", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"])

Which resulted in:

Exception ignored in: <function KaldiRecognizer.__del__ at 0x7728b0edac00>
Traceback (most recent call last):
  File "/home/david/Workspace-agents/useragent/src/main/python/env-userdevice/lib/python3.12/site-packages/vosk/__init__.py", line 161, in __del__
    _c.vosk_recognizer_free(self._handle)
                            ^^^^^^^^^^^^
AttributeError: 'KaldiRecognizer' object has no attribute '_handle'
TypeError: Unknown arguments
waveywhite commented 1 month ago

This works:

words = "zero oh one two three four five six seven eight nine"
words = json.dumps(words.split())
rec = KaldiRecognizer(model, 16000, words)
danpovey commented 1 month ago

this shoul be opened on vosk's github, not here.