Closed ritwickdsouza closed 8 years ago
@RitwickDSouza,
Please post the full code of the audio_transcribe.py
example you are running. It sounds like you've modified the code, but we can't help you without knowing what those modifications are.
Also, it would be very helpful if you posted your Python version and SpeechRecognition library version. If you are not using SpeechRecognition 3.4.3, I highly recommend upgrading.
def textParse(audio):
try:
result = r.recognize_google(audio)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition Service".format(e))
return result
def getPhrase():
with sr.Microphone() as source:
audio = r.listen(source)
return textParse(audio)
def getClip(clip_name):
with sr.AudioFile(path.join(path.dirname(path.realpath(__file__)), clip_name)) as source:
audio = r.record(source)
return textParse(audio)
import speech_recognition as sr
from os import path
r = sr.Recognizer()
try:
phrase = getClip('english.wav')
print phrase
except UnboundLocalError:
print 'Unable to hear the `word'
Python Version : 2.7.11 VoiceRecognition Version : 3.4.3
Can't seem to figure what is wrong. the function getPhrase() works but getClip does not work
That exact code is working fine for me. Did you modify the audio file english.wav
? If so, please post it here.
Can you try the following code, and post the full output (that means everything that the program output, not just one line)?
def textParse(audio):
return r.recognize_google(audio)
def getPhrase():
with sr.Microphone() as source:
audio = r.listen(source)
return textParse(audio)
def getClip(clip_name):
with sr.AudioFile(path.join(path.dirname(path.realpath(__file__)), clip_name)) as source:
audio = r.record(source)
return textParse(audio)
import speech_recognition as sr
from os import path
r = sr.Recognizer()
try:
phrase = getClip('english.wav')
print phrase
except UnboundLocalError:
print 'Unable to hear the `word'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Users\Ritwick DSouza\Desktop\Wrappup\microphone_recognition.py in <module>()
17 r = sr.Recognizer()
18 try:
---> 19 phrase = getClip('english.wav')
20 print phrase
21 except UnboundLocalError:
C:\Users\Ritwick DSouza\Desktop\Wrappup\microphone_recognition.py in getClip(clip_name)
8
9 def getClip(clip_name):
---> 10 with sr.AudioFile(path.join(path.dirname(path.realpath(__file__)), clip_name)) as source:
11 audio = r.record(source)
12 return textParse(audio)
C:\Users\Ritwick DSouza\AppData\Local\Enthought\Canopy\User\lib\site-packages\speech_recognition\__init__.pyc in __init__(self, filename_or_fileobject)
160
161 def __init__(self, filename_or_fileobject):
--> 162 assert isinstance(filename_or_fileobject, str) or filename_or_fileobject.read, "Given audio file must be a filename string or a file-like object"
163 self.filename_or_fileobject = filename_or_fileobject
164 self.stream = None
AttributeError: 'unicode' object has no attribute 'read'
@RitwickDSouza,
I found the problem, and fixed it in b011c9aa555dc6d1ff03897e6ac4ca66915d13c8. Expect to see it in the next release!
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Users\Ritwick DSouza\Desktop\Wrappup\microphone_recognition.py in <module>()
17 r = sr.Recognizer()
18 try:
---> 19 phrase = getClip('english.wav')
20 print phrase
21 except UnboundLocalError:
C:\Users\Ritwick DSouza\Desktop\Wrappup\microphone_recognition.py in getClip(clip_name)
8
9 def getClip(clip_name):
---> 10 with sr.AudioFile(path.join(path.dirname(path.realpath(__file__)), clip_name)) as source:
11 audio = r.record(source)
12 return textParse(audio)
C:\Users\Ritwick DSouza\AppData\Local\Enthought\Canopy\User\lib\site-packages\speech_recognition\__init__.pyc in __init__(self, filename_or_fileobject)
160
161 def __init__(self, filename_or_fileobject):
--> 162 if str is bytes: # Python 2 - if a file path is specified, it must either be a `str` instance or a `unicode` instance
163 assert isinstance(filename_or_fileobject, (str, unicode)) or hasattr(filename_or_fileobject, "read"), "Given audio file must be a filename string or a file-like object"
164 else: # Python 3 - if a file path is specified, it must be a `str` instance
AttributeError: 'unicode' object has no attribute 'read'
Still getting this error :/
The new version has not been released yet; it seems like you patched the source, but didn't delete the .pyc bytecode caches.
This has been fixed in 3.4.4. Thanks for reporting!
still having this issue on the latest release
Hi, When i try to run the audio_trasnscribe.py it gives me the error AttributeError: 'unicode' object has no attribute 'read' on line number 7.