1

I installed the speech recognition and the pyttsx3 libraries

pip install SpeechRecognition
pip install pyttsx3

but when i try to import them it gives two errors

Import "speech_recognition" could not be resolved
Import "pyttsx3" could not be resolved

heres my code

import speech_recognition as sr
import pyttsx3

audio = sr.Recognizer()

2 Answers 2

1

Usually this happens because of virtual env or interpreter issues. Possible fixes:

  1. Make sure that the interpreter you are using inside your IDE, is the same as the one in which you installed the libraries.

  2. Same as above in case of virtual env.

  3. If your IDE is VS Code, then open the settings.json file and set python server to Jedi instead of Microsoft/Pylance.

I faced similar issues, was unable to diagnose the exact cause, but somehow the popular CodeRunner extension and VS code's recommended python extensions were in conflict. Therefore, i disabled the former and the program executed without any issues

1
  • I changed the interpreter to the one where the libraries were and it worked, thanks!! Feb 12, 2022 at 17:29
0

Installing these packages additionally along with SpeechRecognition and PyAudio resolved all the conflicts, and SpeechRecognition and googletrans were able to work just fine:

pip3 install beautifulsoup4

pip3 install googletrans

pip3 install gTTS

pip3 install gTTS-token

pip3 install pip

pip3 install pipwin

pip3 install playsound

pip3 install PyAudio

pip3 install pylint

pip3 install pyobjc

pip3 install pyttsx3

pip3 install setuptools

pip3 install SpeechRecognition

pip3 install Translator

brew install flac

brew install portaudio

If your IDE is VS Code, then set the python language server to Pylance instead of Default in the settings.json file. This worked for me!

Else, set it to Jedi server.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.