简体   繁体   中英

jarvis ai building in python for windows

from gtts import gTTS import os import speech_recognition as sr import webbrowser import time

def talkToME(audioString): print(audioString) tts=gTTS(text=audioString, lang='en') tts.save('audio.mp3') os.system('mpg123 audio.mp3')

listens for commands

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())

this is my code. however, when i run it there is no error message and nothing seems to happen. i am kind of lost whats wrong. it was supposed to answer "I am fine" but nothing happens. i am using windows 10. and python 3.6.3 the code seems to be for linux. but i dont know why? and even if so how can edit or write a code for creating a simple jarvis for windows using python. thank you.

Try changing the following lines to get results:

sr.Microphone to sr.Microphone() and r.recognise_google(audio) to r.recognize_google(audio)

Please tell me if this works cause it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM