Python Forum
what can i do with this error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what can i do with this error?
#1
import codecs
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
engine=pyttsx3.init('sapi5')
voices=engine.getProperty('voices')
engine.setProperty('voices',voices[0].id)
def speak(audio):
    engine.say(audio)
    engine.runAndWait()
def wishme():
    hour=int(datetime.datetime.now().hour)
    if hour>0 and hour<=12:
        speak("Good Morning")
    elif hour>12 and hour<=16:
        speak("Good Afternoon")
    elif hour>=16 and hour<20:
        speak("Good Evening")
    else:
        speak("Good Night")
    speak("I am Jaarvis. Please tell me How may I help You")
def takecommand():
    r=sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening")
        r.pause_threshold=1
        r.energy_threshold=300
        audio=r.listen(source)
    try:
        print("Recognizing....")
        query=r.recognize_google(audio,language='en-US')
        print('user said:',query,'\n')
    except Exception as e:
        print(e)
        print("Say that again Please.......")
        return "None"
    return query
if __name__ == '__main__':
    wishme()
    while True:
        query=takecommand().upper()
Error:
'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
Reply
#2
Error:
Traceback (most recent call last): File "E:/Data Files/A/artificial Inteligence/AI/AI2.py", line 36, in <module> query=takecommand().upper() File "E:/Data Files/A/artificial Inteligence/AI/AI2.py", line 31, in takecommand query=r.recognize_google(audio,language='en-US') File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\speech_recognition\__init__.py", line 845, in recognize_google response_text = response.read().decode("utf-8") UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
Reply
#3
Well, there's an encoding error. The source is expected to be valid utf-8 and it's not. I'm not familiar with the speech recognition package, but I would look to their documentation to find out what the encoding is, and if you can specify that encoding when reading it. However, this appears to all be internal to the speech_recognition package, so it may just be a bug that you need to talk to the authors of that package about.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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