【问题标题】:jarvis ai building in python for windowsjarvis ai 在 python 中为 windows 构建
【发布时间】:2018-03-09 16:00:57
【问题描述】:

从 gtts 导入 gTTS 导入操作系统 将语音识别导入为 sr 导入浏览器 进口时间

def talkToME(音频字符串): 打印(音频字符串) tts=gTTS(text=audioString, lang='en') tts.save('audio.mp3') os.system('mpg123 audio.mp3')

监听命令

def myCommand():

    r = sr.Recognizer()

    with sr.Microphone as source:
        print('Say Something!')
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source, duration =1)
        audio = r.listen(source)


    try:
        command = r.recognise_google(audio)
        print('you said: ' + command+ '/n')

        #loop back to continue listen for commands

    except sr.UnknownvalueError:
        assistant(myCommand())

        return command
#if statements for executing commands

    def assistant(command):

        if "how are you" in command:
            talkToMe("i am fine")


time.sleep(2)
talkToMe(' hi brian, what can i do for you?')

while True:
    command = recordAudio()
    assistant(myCommand())

这是我的代码。但是,当我运行它时,没有错误消息,似乎什么也没有发生。我有点迷失了什么是错的。它应该回答“我很好”,但没有任何反应。我正在使用 Windows 10. 和 python 3.6.3 该代码似乎适用于linux。但我不知道为什么?即使是这样,如何编辑或编写代码来使用python为windows创建一个简单的jarvis。 谢谢。

【问题讨论】:

    标签: python windows-10


    【解决方案1】:

    尝试更改以下几行以获得结果:

    sr.Microphonesr.Microphone()r.recognise_google(audio)r.recognize_google(audio)

    请告诉我这是否可行,因为它对我有用。

    【讨论】:

    • 感谢您的帮助,非常感谢!抱歉耽搁了,我从没想过有人会真正回复,因为这是我第一次。
    猜你喜欢
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多