Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.36k stars 2.39k forks source link

speech_recognition does not implemented the vosk wrapper #613

Open ramleda opened 2 years ago

ramleda commented 2 years ago

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:

image

Enhex commented 2 years ago

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.

mattiasu96 commented 2 years ago

Yeah same problem, any fix?

ftnext commented 2 years ago

As @Enhex mentioned (Thanks! ❤️),

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.

nshmyrev commented 2 years ago

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
ftnext commented 2 years ago

@nshmyrev Thanks! Actually, I misunderstood the project's metadata and was not able to install like pip install SomeProject@git+https://git.repo/some_pkg.git@1.3.1 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