speech_recognition
speech_recognition copied to clipboard
speech_recognition does not implemented the vosk wrapper
I'm trying to use speech_regognition with vosk. But when I try to call the vosk method I receive the following message:
Traceback (most recent call last):
File "C:\Users\user\projects\\studies\speechreco.py", line 27, in <module>
text = recognizer.recognize_vosk(audio)
AttributeError: 'Recognizer' object has no attribute 'recognize_vosk'. Did you mean: 'recognize_api'?
The method is:
import speech_recognition as speechreco
import vosk
while True:
try:
print("begin loop")
with speechreco.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic)
print("begin listening")
audio = recognizer.listen(mic)
text = recognizer.recognize_vosk(audio)
...
It looks like the vosk wrapper is not implemented at the version:
vosk - 0.3.42 python - 3.10.4
Need I use a downgrade version?
I follow the sample:

version 3.8.1 doesn't include vosk (master does, so I guess it will be in the next release?): https://github.com/Uberi/speech_recognition/blob/3.8.1/speech_recognition/init.py
I'm also interested in using Vosk as it seems to be the only offline option that actually works.
Yeah same problem, any fix?
As @Enhex mentioned (Thanks! ❤️),
- version 3.8.1 was released in 2017
- version 3.8.1 does not include
recognize_voskmethod- This method was added at https://github.com/Uberi/speech_recognition/pull/513 on 2020
For example if you install from PyPI, recognize_vosk was not implemented
$ pip install SpeechRecognition
>>> import speech_recognition as speechreco
>>> recognizer = speechreco.Recognizer()
>>> "recognize_vosk" in dir(recognizer)
False
Temporary workaround
Clone this repository and install from source (👉See simpler command by @nshmyrev https://github.com/Uberi/speech_recognition/issues/613#issuecomment-1264475131 )
$ # I recommend to prepare another virtual environment for source installation
$ git clone https://github.com/Uberi/speech_recognition.git
$ cd speech_recognition/
$ pip install -e .
>>> import speech_recognition as speechreco
>>> recognizer = speechreco.Recognizer()
>>> "recognize_vosk" in dir(recognizer)
True
Thanks for reporting this issue. ❤️ Can you try this workaround, @ramleda @mattiasu96 ?
I will prepare for PyPI release. It is preferable as solution.
Clone this repository and install from source
You can do it with a single pip command actually:
pip3 install git+https://github.com/Uberi/speech_recognition
@nshmyrev Thanks!
Actually, I misunderstood the project's metadata and was not able to install like pip install SomeProject@git+https://git.repo/[email protected]
https://pip.pypa.io/en/stable/cli/pip_install/#examples (example 5)
Your comment gave me suggestions and helped me realize the misunderstanding.
pip install speech-recognition@git+https://github.com/Uberi/speech_recognition.git