我目前正在编写一个AI程序,它接收来自Dragon NaturallySpeaking(使用Natlink)的输入,处理它,并返回语音输出。我能够拿出一个Receiver GrammarBase来捕获Dragon的所有输入并将其发送给我的解析器。
class Receiver(GrammarBase):
gramSpec = """ <start> exported = {emptyList}; """
def initialize(self):
self.load(self.gramSpec, allResults = 1)
self.activateAll()
def gotResultsObject(self, recogType, resObj):
if recogType == 'reject':
inpt, self.best_guess = [], []
else:
inpt = extract_words(resObj)
inpt = process_input(inpt) # Forms a list of possible interpretations
self.best_guess = resObj.getWords(0)
self.send_input(inpt)
def send_input(self, inpt):
send = send_to_parser(inpt) # Sends first possible interpretation to parser
try:
while True:
send.next() # Sends the next possible interpretation if the first is rejected
except StopIteration: # If all interpretations are rejected, try sending the input to Dragon
try:
recognitionMimic(parse(self.best_guess))
except MimicFailed: # If that fails too, execute all_failed
all_failed()
此代码按预期工作,但有几个问题:
Dragon在将输入发送到我的程序之前对其进行处理。例如,如果我要说“打开谷歌浏览器”,它将打开谷歌浏览器,然后将输入发送到Python。有没有办法将输入发送到Python而不先处理它?</ p>
当我调用waitForSpeech()时,会弹出一个消息框,说明Python解释器正在等待输入。是否可以(为了美观和方便)阻止消息框显示,而是在用户显着停顿后终止语音收集过程?
谢谢!
答案 0 :(得分:3)
关于你的第一个问题,事实证明DNS使用“Open ...”话语作为其内部命令解析过程的一部分。这意味着DNS解析语音并在natlink有机会之前执行命令方式。解决这个问题的唯一方法是在你的natlink语法中将话语从“打开...”更改为“触发器...”(或者除了“触发器”之外的DNS还没有使用的其他话语)。
一些natlink开发者在speechcomputing.com上闲逛。你可能会在那里得到更好的回应。
祝你好运!