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.