我目前正在编写一个 AI 程序,它接收来自 Dragon NaturallySpeaking(使用 Natlink)的输入,对其进行处理,然后返回语音输出。我能够想出一个接收器语法库,它捕获来自 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 在将输入发送到我的程序之前对其进行处理。例如,如果我说“打开 Google Chrome。”,它会打开 Google Chrome,然后将输入发送到 Python。有没有办法在不先处理输入的情况下将输入发送到 Python?
当我调用 waitForSpeech() 时,会弹出一个消息框,说明 Python 解释器正在等待输入。是否有可能(为了美观和方便)阻止消息框出现,而是在用户显着暂停后终止语音收集过程?
谢谢!