我需要在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))
答案 0 :(得分:0)
我不能完全确定我理解您的问题,但总的来说,我知道使语音检测正常工作的问题。 我看到一次睡眠,这可能是哪里出了问题。
您可能需要执行以下操作:
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()
基本上,它需要不断检查语音一段时间,而不是睡觉,看看是否检测到任何东西。 我相信过去无论如何对我有用!
希望这会有所帮助!