Error: Speech to Text Codec cannot decode the bytes in position

0 votes

This is my program i used.

import speech_recognition as sr
r = sr.Recognizer()
audio ='C\Users\Desktop\audiofile1.wav'
with sr.AudioFile(audio) as source:
    print("Audio File")
    audio = r.record(source)
    print("Captured successfully")
try:
    text = r.recognize_google(audio)
    print (text)
except Exception as exp:
    print (exp)

This is the error I am getting:

Can someone help?

Nov 27, 2018 in Python by Nitesh
• 2,870 points
85 views

Your file location string must be written as follows:

audio ='C\\Users\\Desktop\\audiofile1.wav'
Thank you @Shuvodip Ghosh it worked fine.

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+3 votes
Best answer
import speech_recognition as sr
r = sr.Recognizer()
audio ='C\Users\Desktop\audiofile1.wav'
with sr.AudioFile(audio) as source:
    print("Audio File")
    audio = r.record(source)
    print("Captured successfully")
try:
    text = r.recognize_google(audio)
    print (text)
except Exception as exp:
    print (exp)

The error is caused by the 3rd line use \\ instead of \ otherwise it will show you a unicode error.

I changed your program's 3rd line.

import speech_recognition as sr
r = sr.Recognizer()​
audio ='C\\Users\\Desktop\\audiofile1.wav'
with sr.AudioFile(audio) as source:
    print("Audio File")
    audio = r.record(source)
    print("Captured successfully")
try:
    text = r.recognize_google(audio)
    print (text)
except Exception as exp:
    print (exp)

Run the file it will work fine.

answered Nov 27, 2018 by Nabarupa Das

selected Nov 30, 2018 by Omkar
–3 votes
import speech_recognition as sr
r = sr.Recognizer()
audio ='C\Users\Desktop\audiofile1.wav'
with sr.AudioFile(audio) as source:
    print("Audio File")
    audio = r.record(source)
    print("Captured successfully")
try:
    text = r.recognize_google(audio)
    print (text)
except Exception as exp:
    print (exp)

The above file should be in the location of your program. Else it wont be recognised.

Try placing it in the location of your program.

answered Nov 27, 2018 by Jino

This is not the right solution. The file need not necessarily be in the same location. The error is because of single back-slash (\). When single back-slash is used, it is considered as a Uni-code character. You have to use escape character (use double back-slash)

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

Python Error "UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128)"

use the sep argument of to_csv, to delimit by a tab: df.to_csv(file_name, ...READ MORE

answered Jun 13 in Python by Rhea
17 views
0 votes
1 answer

How to hide a window in the constructor immediately after creation?

You can use QtCore.QTimer class Example(QWidget):     def __init__(self, app):         QWidget.__init__(self)         QTimer.singleShot(0, ...READ MORE

answered Apr 17, 2018 in Python by anonymous
18 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by ariaholic
• 7,320 points
49 views
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8 in Python by rajesh
• 1,210 points
39 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
58 views
+1 vote
2 answers

Speech (audio file, wav) to Text - getting timed out

I think the error you are getting ...READ MORE

answered Nov 27, 2018 in Python by Omkar
• 66,910 points
157 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.