Closed tonio-lora closed 7 years ago
Hi @tonio-lora,
The issue is that your file is named speech_recognition.py
. When you do import speech_recognition as sr
in Python 2, it's interpreted as an implicit relative import, which basically means your file is importing itself.
It's a weird issue; I did the same thing a few years at a BattleHack 2015, and it took hours to figure out at the time! In Python 3, implicit relative importing is gone, so this can't happen.
The solution is to not name your file speech_recognition.py
.
Steps to reproduce
Hi, I'm trying the speech_recognition/examples/audio_transcribe.py example on Python 2.7 and I get this error:
C:\Python27\python.exe C:/Users/anlo/PycharmProjects/textanalyticsdemo/speech_recognition.py Traceback (most recent call last): File "C:/Users/anlo/PycharmProjects/textanalyticsdemo/speech_recognition.py", line 1, in
import speech_recognition as sr
File "C:\Users\anlo\PycharmProjects\textanalyticsdemo\speech_recognition.py", line 11, in
r = sr.Recognizer()
AttributeError: 'module' object has no attribute 'Recognizer'
Process finished with exit code 1
The code I'm using is exactly the same that is listed on GitHub. I just changed the location of the audio file. These are the first lines:
Expected behaviour
I was hoping the program will process the audio file using the Bing Speech recognition API (I entered the service key on the code) and print the text returned by the Bing Speech service
Actual behaviour
I got the error above.
System information
My system is Windows 10 X64
My Python version is 2.7.11. My Pip version is 9.1.
My SpeechRecognition library version is 3.6.0. (You can check this by running
python -c "import speech_recognition as sr;print(sr.__version__)"
.)