Python Forum
Error with SpeechRecognition module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error with SpeechRecognition module
#1
I am following this tutorial to transcribe audio.

First, I installed all the modules and program before running python3 transcribe.py, and transcribe.py contains the following code.

import speech_recognition as sr
from os import path
from pydub import AudioSegment

# convert mp3 file to wav                                                       
sound = AudioSegment.from_mp3("transcript.mp3")
sound.export("transcript.wav", format="wav")


# transcribe audio file                                                         
AUDIO_FILE = "transcript.wav"

# use the audio file as the audio source                                        
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
        audio = r.record(source)  # read the entire audio file                  

        print("Transcription: " + r.recognize_google(audio))
When I run the python3 transcribe.py line in my terminal, I get the following error:

Error:
]Traceback (most recent call last): File "transcribe.py", line 1, in <module> import speech_recognition as sr ImportError: No module named speech_recognition
I checked whether SpeechRecognition was properly installed using pip3 list, and it shows up on nthe list.

I also checked the following:

Output:
pip3 install --upgrade speechrecognition Requirement already up-to-date: speechrecognition in /usr/local/lib/python3.8/site-packages (3.8.1)
In any case, any help will be appreciated! Thanks!
Reply
#2
At the beginning of the script, write
import sys
print(sys.executable)
print(sys.version_info)
print(sys.path)
sys.exit(0)
and post the output here.
Reply
#3
(Aug-03-2020, 09:15 PM)Gribouillis Wrote: At the beginning of the script, write
import sys
print(sys.executable)
print(sys.version_info)
print(sys.path)
sys.exit(0)
and post the output here.

Thank you so much for responding! Here's the output:

Output:
/usr/local/bin/python3 sys.version_info(major=3, minor=7, micro=2, releaselevel='final', serial=0) ['dir/folder', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/myusername/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']
Reply
#4
Then why did pip3 install the package for python3.8 and not the python3.7 that you are using? You have two solutions, either you run the script with python3.8, either you install the package for python3.7 as well

First option
Output:
python3.8 myscript.py
Second option
Output:
python3 -m pip install speechrecognition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  vlc module error pythonprogrammer 1 2,863 Apr-23-2020, 04:16 AM
Last Post: Larz60+
  Cannot use speechrecognition Please HELP Simurg 1 2,148 Aug-11-2019, 07:12 PM
Last Post: buran
  speechrecognition 3.8.1 aibrain 1 3,328 Apr-07-2018, 02:17 PM
Last Post: wavic
  pyhton error there is no PIL module error help! pokeboss235 1 2,906 Feb-22-2018, 03:03 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020