当我开始编写代码来创建我的语音助手时,我在使用Speech RecognitionPython 库时遇到了问题。
错误: IndentationError: unindent does not match any outer indentation level
这是发生错误的代码部分:r = sr.Recognizer()
这是目前的完整代码。
import os
import sys
import time
import speech_recognition as sr
from fuzzywuzzy import fuzz
import pyttsx3
import datetime
opts = {
"alias": ('jarvis', 'jervis', 'jirves', 'jurves', 'jervas'
'jalvis', 'jelvis', 'jilves', 'julves', 'jelvas'),
"tbr": ('say', 'tell', 'show', 'how much', 'will', 'would',
'could', 'may', 'can', 'must', 'the'),
"cmds": {
"ctime": ('current time', 'time', 'what time is it'),
"radio": ('turn on the music', 'turn on the radio',
'play radio'),
"jokes": ('tell a joke', 'do you know any jokes',
'make me laugh')
}
}
# functions
def speak(what):
print(what)
speak_engine.say(what)
speak_engine.runAndWait()
speak_engine.stop()
#start
r = sr.Recognizer()
m = sr.Microphone(device_index=1)
with m as source:
r.adjust_for_ambient_noise(source)
speak_engine = pyttsx3.init()
speak("Good day my master")
speak("Jarvis is listening")
# stop_listening = r.listen_in_background(m, callback)
# while True:
# time.sleep(0.1) # infinite loop
所有库都用 pip 安装好,所有库都经过测试
IndentationError- 代码缩进不正确时发生的错误。这是更正后的代码: