双重输入[文本和语音]在Python中同时

问题描述

我正在用python开发一个个人助理,该助理可以接收语音命令,并根据命令执行某些任务。该软件适用于Windows。

与问题有关的模块:

  • pyttsx3
  • 语音识别(recognize_google)

我想使其类似于Google助手(是的。称我为傻瓜)。它会在后台进行侦听,直到听到一个特定的单词或“唤醒”单词后才会回复

唤醒单词之后,它将接受语音输入并匹配多个if-elif条件,并且如果语音输入中的单词与if-elif中的单词匹配,它将执行该块。

现在,我希望它可以使用户同时在语音和文本输入之间切换,而且不,我不想按通话按钮。

我想要这样,如果用户说出唤醒词,程序将激活并接受命令,并且当用户单击文本输入框(不需要唤醒词btw)时,键入command并点击回车它会和接受语音命令时完全一样。

键入命令后,语音输入将禁用,反之亦然。

此外,我将PyQt5用作前端,以实现现代UI外观。 (请告诉我是否有更好的选择)

一些示例代码段。 (不要在代码段中输入模块)

Main.py

speak = ASpeak.speak

    if __name__ == '__main__':
        # Wake Word
        WAKE = 'hello'
        SERVICE = Gcalender.authenticate_google()
        WishUser.wishuser()
    
        while True:
            print('Listening')
            # Change Vinput = VoiceCommand() to input voice commands
            Vinput = CInput.get_command()
    
            if Vinput.count(WAKE) > 0:
                speak("I am Ready")
                Vinput = CInput.get_command()
    
                #Shows how many and which events you have on a specific date(input)
                if "what do i have on" in Vinput or "do i have plans on" in Vinput or "am i busy on" in Vinput or "What events" in Vinput:
                    date = Gcalender.get_date(Vinput)
                    if date:
                        Gcalender.get_events(date,SERVICE)
                    else:
                        speak('I dont understand')                    
            

VoiceInput.py

def VoiceCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source)
        said = ""           #Empty 'said' variable initialized to later on append the input command

        try:
            said = r.recognize_google(audio)
            print(said)         #Prints the user's audio input for user's verification

        except Exception as e:
            print(e)
            
    return said.lower()         #lowers the input to avoid any errors due to capitalization and ease of recognization

TextInput.py(我知道可以改进)

def get_command():
    usertyped = input("Enter a command: ")

    return usertyped.lower()
    

我尝试自己做,但是我对GUI和其他东西不好。请帮忙一个同伴!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...