class DragonRule(MappingRule): mapping = { "(go-to-sleep | snore | mic-sleep)": Function(lambda: natlink.setMicState("sleeping")), "(lock-Dragon|turn-mic-off)": Function(lambda: natlink.setMicState("off")), "german profile": Function( lambda: natlink.saveUser() + natlink.openUser("Codebold german")), "englisches Profil": Function(lambda: natlink.saveUser() + natlink.openUser("Codebold")), "reload grammar[s]": Function(lambda: updateAllGrammars()), "reload <grammar>": GrammarUpdate(), "como": Function(lambda: natlink.recognitionMimic( ["switch", "to", "command", "mode"])), "diemo": Function( lambda: natlink.recognitionMimic(["start", "dictation", "mode"])), "nomo": Function(lambda: natlink.recognitionMimic(["normal", "mode", "on"])), "sleemo": Function(lambda: natlink.recognitionMimic(["go", "to", "sleep"])), "dictation": Function( lambda: natlink.recognitionMimic(["show", "dictation", "box"])), "dictox": Function(lambda: natlink.recognitionMimic(["normal", "mode", "on"])) + Function( lambda: natlink.recognitionMimic(["show", "dictation", "box"])), "transfox": Function(lambda: natlink.recognitionMimic(["click", "transfer"])) + Function(lambda: natlink.recognitionMimic(["command", "mode", "on"])), "blitz NatLink": Function(blitz_natlink_status), "show NatLink": Function(show_natlink_status) } extras = [chc_base.grammar]
def doTraining(fileSpecs,userName='',baseModel='',baseTopic=''): if not userName: userName = '******' # # Expand the file specification list into a list of files without # extensions # allFiles = [] if type(fileSpecs) == type(''): allFiles = expandFiles(fileSpecs) else: for fileSpec in fileSpecs: allFiles = allFiles + expandFiles(fileSpec) if not len(allFiles): print "No files found which match fileSpec:" print " ",fileSpecs raise TrainingError,'no files' # # Create a new user. Make sure the new user is active. # createNewUser(userName,baseModel,baseTopic) # # Read the LST files from disk into Python arrays. As we read the LST # files, we need to convert the format of words from underscores (using # tilde as an escape character) into spaces. # # We build up a master array which contains one entry per input file. # Each file entry is an array with one entry per utterance. Each # utterance entry is an array of strings representing the words # recognized. # allWords = [] for fileName in allFiles: allWords.append(loadWords(fileName)) # # The NIST wave files have to converted into NatSpeak result objects. # The easiest way to do this is to build a dictation grammar and recognize # all of the utterances in the NIST wave files. # allResults = [] for fileName in allFiles: allResults.append(loadResults(fileName)) # # Produce a single array which contains tuples representing the results # object and the transcript. Skip over any results which have blank # transcripts. Print an error if the two arrays sizes do not match # combinedResults = [] fileCount = len(allFiles) for fileNum in range(fileCount): lstSize = len(allWords[fileNum]) nwvSize = len(allResults[fileNum]) if lstSize != nwvSize: print 'The number of utterances in', print allFiles[fileNum]+'.nwv','('+str(nwvSize)+')', print 'does not match', print 'the number of lines in', print allFiles[fileNum]+'.lst','('+str(lstSize)+')' for resNum in range(lstSize): words = allWords[fileNum][resNum] resObj = allResults[fileNum][resNum] if len(words) and resObj: combinedResults.append((words,resObj)) # # Perform calibration on the first N utterances (20 maximum) # trainingPass(combinedResults[:20],'calibrate') # # Perform batch adaptation on the entire set of utterances. # trainingPass(combinedResults,'longtrain') # # Perform training on the entire set of utterances. # trainingPass(combinedResults,'batchadapt') # # Save the user. # print 'Saving the user...' natlink.saveUser() print 'All done.'
def saveUser(): """Saves the current user""" natlink.saveUser() sr_user_needs_saving = 0
def doTraining(fileSpecs, userName='', baseModel='', baseTopic=''): if not userName: userName = '******' # # Expand the file specification list into a list of files without # extensions # allFiles = [] if type(fileSpecs) == type(''): allFiles = expandFiles(fileSpecs) else: for fileSpec in fileSpecs: allFiles = allFiles + expandFiles(fileSpec) if not len(allFiles): print "No files found which match fileSpec:" print " ", fileSpecs raise TrainingError, 'no files' # # Create a new user. Make sure the new user is active. # createNewUser(userName, baseModel, baseTopic) # # Read the LST files from disk into Python arrays. As we read the LST # files, we need to convert the format of words from underscores (using # tilde as an escape character) into spaces. # # We build up a master array which contains one entry per input file. # Each file entry is an array with one entry per utterance. Each # utterance entry is an array of strings representing the words # recognized. # allWords = [] for fileName in allFiles: allWords.append(loadWords(fileName)) # # The NIST wave files have to converted into NatSpeak result objects. # The easiest way to do this is to build a dictation grammar and recognize # all of the utterances in the NIST wave files. # allResults = [] for fileName in allFiles: allResults.append(loadResults(fileName)) # # Produce a single array which contains tuples representing the results # object and the transcript. Skip over any results which have blank # transcripts. Print an error if the two arrays sizes do not match # combinedResults = [] fileCount = len(allFiles) for fileNum in range(fileCount): lstSize = len(allWords[fileNum]) nwvSize = len(allResults[fileNum]) if lstSize != nwvSize: print 'The number of utterances in', print allFiles[fileNum] + '.nwv', '(' + str(nwvSize) + ')', print 'does not match', print 'the number of lines in', print allFiles[fileNum] + '.lst', '(' + str(lstSize) + ')' for resNum in range(lstSize): words = allWords[fileNum][resNum] resObj = allResults[fileNum][resNum] if len(words) and resObj: combinedResults.append((words, resObj)) # # Perform calibration on the first N utterances (20 maximum) # trainingPass(combinedResults[:20], 'calibrate') # # Perform batch adaptation on the entire set of utterances. # trainingPass(combinedResults, 'longtrain') # # Perform training on the entire set of utterances. # trainingPass(combinedResults, 'batchadapt') # # Save the user. # print 'Saving the user...' natlink.saveUser() print 'All done.'