def loadResults(fileName): print 'Recognizing from '+fileName+'.nwv...' print '>',' '*70, grammar = DictationGrammar() grammar.initialize() # Here we force recognition to happen. The results objects will be # created for each utterance in the wave file and passed to the callback # function (callback.func) where they will be collected in an array natlink.inputFromFile(fileName+'.nwv') print '' grammar.unload() return grammar.results
def loadResults(fileName): print 'Recognizing from ' + fileName + '.nwv...' print '>', ' ' * 70, grammar = DictationGrammar() grammar.initialize() # Here we force recognition to happen. The results objects will be # created for each utterance in the wave file and passed to the callback # function (callback.func) where they will be collected in an array natlink.inputFromFile(fileName + '.nwv') print '' grammar.unload() return grammar.results
def main(): # Define required and optional command-line arguments. parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="Script for safely using Natlink's inputFromFile() " "function.\n\n" "This script is intended to be run in a dedicated process in " "order to work around potential page faults." ) parser.add_argument( "file", type=argparse.FileType("r"), help="Name of the wave file to take input from." ) parser.add_argument( "--no-utt-detect", default=False, action="store_true", help="Do not perform utterance detection (i.e. don't split speech " "at pauses) when processing the specified wave file. Use this if " "the file contains only one utterance." ) # Parse command-line arguments. args = parser.parse_args() # Get the filename and uttdetect arguments. f = args.file filename = f.name f.close() # Close the file object created by argparse uttdetect = 0 if args.no_utt_detect else 1 # Instruct Windows to suppress the error reporting window if this script # causes a page fault. win32api.SetErrorMode(win32con.SEM_NOGPFAULTERRORBOX) # Connect to NatSpeak. natlink.natConnect() try: # Process the specified wave file using the specified options. natlink.inputFromFile(filename, 0, [], uttdetect) finally: # Disconnect from NatSpeak. natlink.natDisconnect()
def processFile(fileName): # this create a decoder object sx96 = mobiletools.SX96Codec() # open the file and get the header information again (this has the side # effect of skipping past the header) sriFile = open(fileName,'rb') year,month,day,hour,minute,second,packetCount = decodeHeader(sriFile) # compute the size of the data for the output file frameCount = packetCount * 9 outDataSize = frameCount * wavFrameSize # open an output wave file and write out a header tempFileName = tempfile.mktemp() + '.wav' wavFile = open(tempFileName,'wb') writeHeader(wavFile,outDataSize) # iterate over each packet (9 frames) in the input file, convert the data # and write the converted data into the output file for i in range(packetCount): for j in range(9): frame = sriFile.read(sriFrameSize) wavData = sx96.decode(frame) wavFile.write(wavData) # discard the extra packet descriptor byte sriFile.read(1) wavFile.close() wavFile = None sriFile.close() sriFile = None # now we transcribe this file in NatSpeak natlink.execScript('AppBringUp "NatSpeak"') natlink.playString(formatDate(year,month,day,hour,minute,second)) natlink.inputFromFile(tempFileName)