alphacep / alphacep/vosk-api

Properly escape lang for regex

Open
#1,242 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
15.1k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

I'm trying to load a language model from a downloaded file (provided by vosk at https://alphacephei.com/vosk/models/vosk-model-small-pt-0.3.zip).
I've already downloaded, unzipped in a local folder. C:\Users\user.here\PycharmProjects\ASR_Custom\models\pt-small

and tried to load with
```
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "models", "pt-small")
model = Model(lang=path)
```

and I'm receiving this error:

```
Traceback (most recent call last):
File "C:\Users\user.here\PycharmProjects\ASR_Custom\main.py", line 14, in
model = Model(lang="C:\\Users\\user.here\.cache\\vosk\\vosk-model-small-pt-0.3")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user.here\PycharmProjects\ASR_Custom\venv\Lib\site-packages\vosk\__init__.py", line 54, in __init__
model_path = self.get_model_path(model_name, lang)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user.here\PycharmProjects\ASR_Custom\venv\Lib\site-packages\vosk\__init__.py", line 67, in get_model_path
model_path = self.get_model_by_lang(lang)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user.here\PycharmProjects\ASR_Custom\venv\Lib\site-packages\vosk\__init__.py", line 94, in get_model_by_lang
model_file = [model for model in model_file_list if
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user.here\PycharmProjects\ASR_Custom\venv\Lib\site-packages\vosk\__init__.py", line 95, in
match(r"vosk-model(-small)?-{}".format(lang), model)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files (x86)\Python311-32\Lib\re\__init__.py", line 166, in match
return _compile(pattern, flags).match(string)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files (x86)\Python311-32\Lib\re\__init__.py", line 294, in _compile
p = _compiler.compile(pattern, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files (x86)\Python311-32\Lib\re\_compiler.py", line 743, in compile
p = _parser.parse(p, flags)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files (x86)\Python311-32\Lib\re\_parser.py", line 980, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files (x86)\Python311-32\Lib\re\_parser.py", line 455, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files (x86)\Python311-32\Lib\re\_parser.py", line 539, in _parse
code = _escape(source, this, state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files (x86)\Python311-32\Lib\re\_parser.py", line 393, in _escape
raise source.error("incomplete escape %s" % escape, len(escape))
re.error: incomplete escape \U at position 22
Exception ignored in:
Traceback (most recent call last):
File "C:\Users\user.here\PycharmProjects\ASR_Custom\venv\Lib\site-packages\vosk\__init__.py", line 60, in __del__
_c.vosk_model_free(self._handle)
^^^^^^^^^^^^
AttributeError: 'Model' object has no attribute '_handle'
```

Is that a bug or I'm doing something wrong?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.