2014-11-01 20 views
0

我使用的WSR,它可以分析一個字做一個程序,龍蠅,任何聲音匹配這個詞,輸出「是它匹配」蟒蛇蜻蜓認識到類似的話

如果我說「捷克斯洛伐克」那麼它必須打印真實的,即使對於這個世界的所有類似的比賽,就像'斯洛伐克圈,貓在slavia,seko vakia ...'

什麼具體的方法,我應該用這個?

我的程序

from dragonfly.all import * 
import pythoncom 
import time 
# Voice command rule combining spoken form and recognition processing. 
class ExampleRule(CompoundRule): 
    spec = "czechoslovakia|circle slovalia|sceko bakia|cat on ania"     # Spoken form of command. 

    def _process_recognition(self, node, extras): # Callback when command is spoken. 
     print "Voice command spoken." 

# Create a grammar which contains and loads the command rule. 
grammar = Grammar("example grammar")    # Create a grammar to contain the command rule. 
grammar.add_rule(ExampleRule())      # Add the command rule to the grammar. 
grammar.load()          # Load the grammar. 

while True: 
    pythoncom.PumpWaitingMessages() 
    time.sleep(.1) 
+0

那麼你如何定義「相似」呢。你可能想詳細說明一下。 – 2014-11-02 15:28:40

回答

1

沒有什麼內置蜻蜓,讓您做到這一點,但你有一些其他的選擇。

  1. 如果你正在尋找動態生成的規範,你可能想 看看Fuzzy。你可以給它一個字,並用它來產生來自該單詞的其他類似的發音單詞 。然後你可以從它們創建 規範。
  2. Here is the WSR engine class蜻蜓。 我不太瞭解SAPI5,但you might be able to ask it for alternatives。如果可以的話,你可能可以擴展蜻蜓語法包裝以暴露替代品,然後使用一個搜索語法來保存所有話語,然後過濾掉你想要的東西(可能使用模糊)。
  3. 如果您使用的是Natlink,我會推薦 查看結果對象。正如你所看到的,here,結果 對象可以訪問龍的所有不同的假設,你在給定的話語中說了什麼 。就像我的第二個建議 一樣,你可以抓住一切,然後過濾你想要的東西:

from natlinkutils import GrammarBase 

class CatchAll(GrammarBase): 

    # this spec will catch everything 
    gramSpec = """ 
     <start> exported = {emptyList}; 
    """ 

    def initialize(self): 
     self.load(self.gramSpec, allResults=1) 
     self.activateAll() 

    def gotResultsObject(self, recogType, resObj): 
     for x in range(0, 100): 
      try: 
       possible_interpretation = resObj.getWords(x) 
       # do whatever sort of filtering you want here 
      except Exception: 
       break 

c = CatchAll() 
c.initialize() 

def unload(): 
    global c 
    if c: 
     c.unload() 
    c = None