在Windows上,speech_recognition模块python更好

问题描述

我正在RaspBerry pi上开发语音助手,但是我注意到与使用完全相同的麦克风和脚本的Windows pc相比,我编写的python脚本在pi上产生的效果要差得多。我试过在pi上做alsamixer,但没有成功。最有问题的确切短语是“嘿GLaDOS”,它可以在我的电脑上完美地转录,但通常会返回“嘿玻璃”,“ 8乐透”,“嘿巴黎”,“克劳斯” 。我正在使用带有以太网电缆的pi 2B。 pi还可以完美地从使用基本python脚本记录的.wav文件中转录,而只是不使用Speech_recognition中的流。

请问有人对如何解决此问题有任何建议,因为我想在pi上运行该系统,但现在对于我的目的而言还不够准确

pi通常会自行正确地转录glados单词,但是当说嘿glados或okglados时,它几乎总是会出错,这与pc正确9/10次一样。

我有语音识别功能,可以返回所有可能的转录,如果最有可能的不是“ GLADOS”,那么其他都不是

脚本中的一些示例代码

def recognize_speech_from_mic(recognizer,microphone):

    # check that recognizer and microphone arguments are appropriate type
    if not isinstance(recognizer,sr.Recognizer):
        raise TypeError("`recognizer` must be `Recognizer` instance")
    if not isinstance(microphone,sr.Microphone):
        raise TypeError("`microphone` must be `Microphone` instance")
    #sorting out adjustment for bg noise
    #from the microphone
    with microphone as source:
        recognizer.pause_threshold=1
        recognizer.adjust_for_ambient_noise(source)
        audio = recognizer.listen(source)
    #response object returns 3 parts - error message boolean for success and transcribed text if completed
    response = {
        "success": True,"error": None,"transcription": None                               #THIS FUNCTION WAS FOUND AT https://realpython.com/python-speech-recognition/
    }                                                       #as part of speech recognition library tutorial
    #try recognizing the speech in the recording
    #if a RequestError or UnkNownValueError exception is caught,#update the response object accordingly
    try:
        response["transcription"] = recognizer.recognize_google(audio)
        print(recognizer.recognize_google(audio,show_all=True))
    except sr.RequestError:
        # API was unreachable or unresponsive
        response["success"] = False
        response["error"] = "API unavailable"
    except sr.UnkNownValueError:
        # speech was unintelligible
        response["error"] = "Unable to recognize speech"
    return response


if __name__ == "__main__":

    #pygame audio init
    mixer.init()
    
    #recognizer and mic instances
    recognizer = sr.Recognizer()
    microphone = sr.Microphone()

    #with microphone as source:
    #    recognizer.adjust_for_ambient_noise(source)

    #variables set before operation
    play_obj = None   
    song = 1
    active = False
    songactive = False

    while True:
        while True:
            command = recognize_speech_from_mic(recognizer,microphone)
            if command["transcription"]:
                break
            if not command["success"]:
                break

        #if there was an error print it 
        if command["error"]:
            print("ERROR: {}".format(command["error"]))
            #break

        print(command["transcription"])

        #keyword listening
        if keywordlocate(command["transcription"],"ok GLaDOS") == True or keywordlocate(command["transcription"],"ok glass") == True or keywordlocate(command["transcription"],"ok ladders") == True or keywordlocate(command["transcription"],"ok Gladys") == True:
            active = True
            oneattempt = True
        
            while active == True:
                if oneattempt == False:
                    while True:
                        print("speak Now")
                        command = recognize_speech_from_mic(recognizer,microphone)
                        if command["transcription"]:
                            break
                        if not command["success"]:
                            break
                        print("I didn't catch that. What did you say?\n")

                    # if there was an error,stop 
                    if command["error"]:
                        print("ERROR: {}".format(command["error"]))
                        break

                print("You said: {}".format(command["transcription"]))

                #returns sound effect for when keyword activated or when user says hey glados again
                if keywordlocate(command["transcription"],"ok Gladys") == True:
                    vlines = ["hello again (low key).wav","hello again (high key).wav","lets get to business.wav"]
                    sound = mixer.sound(random.choice(vlines))
                    sound.play()
                    while mixer.get_busy() == True:
                        continue

解决方法

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

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

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

相关问答

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