如何使用语音gtts进行用户输入

时间:2019-02-20 23:47:08

标签: python python-3.x artificial-intelligence google-text-to-speech

我正在创建一个带有语音输入的简单披萨应用程序。 在创建这篇文章之前,我进行了很多搜索,没有发现有用的东西。

This is the full code

小提琴无法正确运行代码,因此请不要在那儿运行。

问题:

当我尝试在我的“输入” 中使用“命令” 时(例如

count = 0

def talkToMe(audio):

    global count
    print(audio)
    text_to_speech = gTTS(text=audio, lang='en-us')
    text_to_speech.save(f'speech{count%2}.mp3')
    mixer.init()
    mixer.music.load(f'speech{count%2}.mp3')
    mixer.music.play()
    count += 1

def myCommand():


    r = sr.Recognizer()

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

    try:
        command = r.recognize_google(audio).lower()
        print('You said: ' + command + '\n')

    #loop back to continue to listen for commands if unrecognizable speech is received
    except sr.UnknownValueError:
        print('Your last command couldn\'t be heard')
        command = myCommand();

    return command

def assistant(command):

    def pick_or_deli():
        global delivery
        global customer_name 
        global customer_telephone

        delivery = input("pickup - pick up / delivery - delivery:" + command)
        delivery = delivery.upper()
        if delivery == "DELIVERY":
             while running == True:
        ..............................

我只是得到:

this

不要为小写的“交付”花钱。 即使我更改此行:

if delivery == "DELIVERY": 

对此:

if delivery == "delivery":

它不起作用。即使我按Enter。系统无法将其识别为输入。

任何解决方案/建议都很好。

0 个答案:

没有答案