如何将语音识别添加到Nao B

2024-04-28 17:14:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一些关于nao机器人语音识别的帮助。在我的代码中,我启动了引擎,但我不知道如何将语音添加到内存中,然后调用它。 任何帮助都是好的。顺便说一句,这是在课堂上

这是我的密码:

    n = "WordRecognized"
    asr = self.session.service("ALSpeechRecognition")
    asr.pause(True)
    alm = self.session.service("ALMemory")
    alm.declareEvent(n)
    asr.setAudioExpression(True)
    asr.subscribe(n)
    self.say("Started Voice Recognition")
    time.sleep(t)
    asr.unsubscribe(n)
    print(alm.getData(n))

Tags: 内存代码引擎selftrue密码sessionservice
1条回答
网友
1楼 · 发布于 2024-04-28 17:14:18

我不能完全肯定我理解你的问题,但总的来说,我认识到让语音检测工作的问题。 我看到一个单一的睡眠,这可能是它出错的地方

您可能需要执行以下操作:

import time
# get current time as start time
t_start = time.time() 
t_current = t_start                              
RecognizedWords = []                    
duration = 10                           # detecting time

# if duration time has not passed
while t_current-t_start<duration:
    recognized_words = alm.getData(n)  
    # if something is in the list (thus something was detected)
    if len(recognized_words) > 0:          
        # then we break the loop, so we stop checking for more speech.
        break                       
    else:                               # if list is empty (nothing recognized)
        t_current = time.time()   

基本上,它需要一段时间不停地检查语音,而不是睡觉,看是否有任何东西被检测到。 我相信这在过去对我是有效的

希望这有帮助

相关问题 更多 >