Пример #1
0
def delete_words(input):
    natlink.natConnect(0)
    try:
        for line in input.readlines():
            delete_word(line.rstrip())
    finally:
        natlink.natDisconnect()
Пример #2
0
def dump_words(input, include_pronunciations, verbose_level):
    natlink.natConnect(0)
    try:
        for line in input.readlines():
            dump_word(line.rstrip(), include_pronunciations, verbose_level)
    finally:
        natlink.natDisconnect()
    def DISABLED_test_natlink_timer(self):
        return

        callback_occurred = False

        def callback():
            callback_occurred = True

        ticks = 200

        import time
        import natlink
        natlink.natConnect()
        try:
            natlink.setTimerCallback(callback, ticks)
            #            time.sleep(1)
            import sys
            import time
            import win32gui
            timeout = time.time() + 3
            while time.time() < timeout:
                print("Luke")
                sys.stdout.flush()
                if win32gui.PumpWaitingMessages():
                    raise RuntimeError("We got an unexpected WM_QUIT message!")
                time.sleep(1)
            natlink.setTimerCallback(None, 0)
            print("callback occurred:", callback_occurred)
        finally:
            natlink.natDisconnect()
    def DISABLED_test_natlink_timer(self):
        return

        callback_occurred = False
        def callback():
            callback_occurred = True
        ticks = 200

        import time
        import natlink
        natlink.natConnect()
        try:
            natlink.setTimerCallback(callback, ticks)
#            time.sleep(1)
            import sys
            import time
            import win32gui
            timeout = time.time() + 3
            while time.time() < timeout:
                print("Luke")
                sys.stdout.flush()
                if win32gui.PumpWaitingMessages():
                    raise RuntimeError("We got an unexpected WM_QUIT message!")
                time.sleep(1)
            natlink.setTimerCallback(None, 0)
            print("callback occurred:", callback_occurred)
        finally:
            natlink.natDisconnect()
Пример #5
0
def run():
    try:
        natlink.natConnect(1)
        TestDialog(MakeDlgTemplate()).DoModal()
        natlink.natDisconnect()
    except:
        natlink.natDisconnect()
        raise
Пример #6
0
def run():
    try:
        natlink.natConnect(1)
        TestDialog(MakeDlgTemplate()).DoModal()
        natlink.natDisconnect()
    except:
        natlink.natDisconnect()
        raise
Пример #7
0
def run():
    if not natlink.isNatSpeakRunning():
        raise TranscribeError,'NatSpeak should be running before transcribing files'
    try:
        natlink.natConnect()
        doTranscription()
    finally:
        natlink.natDisconnect()
Пример #8
0
def demodlg():
    Title = 'Train Phrases'
    p = [('word 1'), ('word 2'), ('word 3')]
    dlg = TrainDialog(Title, p, 1)
    try:
        natlink.natConnect(1)
    except:
        return
    dlg.DoModal()
    natlink.natDisconnect()
Пример #9
0
def demodlg ():
    Title='Train Phrases'
    p=[('word 1'),('word 2'),('word 3')]
    dlg=TrainDialog(Title, p, 1)
    try:
        natlink.natConnect(1)
    except:
        return
    dlg.DoModal()
    natlink.natDisconnect()    
Пример #10
0
def load_words(input):
    natlink.natConnect(0)
    try:
        for line in input.readlines():
            fields = parse_word_definition(line)
            if fields == None:
                continue
            written, spoken, properties, pronunciations = fields
            
            load_word(written, spoken, properties)
    finally:
        natlink.natDisconnect()
Пример #11
0
def run(args):
    fileSpecs,userName,baseModel,baseTopic = parseArgs(args)
    if not fileSpecs:
        return
    try:
        natlink.natConnect()
        doTraining(fileSpecs,userName,baseModel,baseTopic)
        natlink.natDisconnect()
    except TrainingError,message:
        natlink.natDisconnect()
        print ''
        print 'TrainingError:',message
Пример #12
0
def run(args):
    fileSpecs, userName, baseModel, baseTopic = parseArgs(args)
    if not fileSpecs:
        return
    try:
        natlink.natConnect()
        doTraining(fileSpecs, userName, baseModel, baseTopic)
        natlink.natDisconnect()
    except TrainingError, message:
        natlink.natDisconnect()
        print ''
        print 'TrainingError:', message
Пример #13
0
 def goTrain(self, ToTrain):
     Title = 'Train Phrases'
     Phrases = []
     for p in ToTrain:
         Phrases.append((p))
     try:
         natlink.natConnect(1)
     except:
         return
     MicState = natlink.getMicState()
     dlg = TrainDialog.TrainDialog(Title, Phrases, MicState)
     SetMic('off')
     dlg.DoModal()
     natlink.natDisconnect()
Пример #14
0
 def goTrain(self,ToTrain):
     Title='Train Phrases'
     Phrases=[]
     for p in ToTrain:
         Phrases.append((p))
     try:
         natlink.natConnect(1)
     except:
         return
     MicState=natlink.getMicState()
     dlg=TrainDialog.TrainDialog(Title,Phrases,MicState)
     SetMic('off')
     dlg.DoModal()
     natlink.natDisconnect()    
def run():
    global logFile, natconnectOption
    logFile = open(logFileName, "w")
    log("log messages to file: %s" % logFileName)
    log('starting UnittestMouse')
    # trick: if you only want one or two tests to perform, change
    # the test names to her example def tttest....
    # and change the word 'test' into 'tttest'...
    # do not forget to change back and do all the tests when you are done.
    suite = unittest.makeSuite(UnittestMouse, 'test')
    ##    natconnectOption = 0 # no threading has most chances to pass...
    log('\nstarting tests with threading: %s\n' % natconnectOption)
    natlink.natConnect(natconnectOption)
    result = unittest.TextTestRunner().run(suite)
    dumpResult(result, logFile=logFile)
    natlink.natDisconnect()
    logFile.close()
Пример #16
0
def disconnect():
    """Dicsconnects from SR system.
    
    **INPUTS**
    
    *none* -- 
    
    
    **OUTPUTS**
    
    *none* -- 
    """
    global sr_is_connected, sr_mic_change_callback

    if sr_mic_change_callback:
        natlink.setChangeCallback(None)
        sr_mic_change_callback = None
    natlink.natDisconnect()
    sr_is_connected = 0
Пример #17
0
def disconnect():
    """Dicsconnects from SR system.
    
    **INPUTS**
    
    *none* -- 
    
    
    **OUTPUTS**
    
    *none* -- 
    """
    global sr_is_connected, sr_mic_change_callback

    if sr_mic_change_callback:
        natlink.setChangeCallback(None)
        sr_mic_change_callback = None
    natlink.natDisconnect()
    sr_is_connected = 0        
Пример #18
0
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()
Пример #19
0
def run():
    global s
    global g
    natlink.natConnect(1)  #if natlink.isNatSpeakRunning() else wait
    try:
        print 'MicState:', natlink.getMicState()
        natlink.setBeginCallback(beginCallback)
        natlink.setChangeCallback(changeCallback)
        updateGrammarFromClient()
        natlink.setMicState('on')
        natlink.waitForSpeech(300)
        #data = client_socket.recv(512)
        #data = raw_input ( "SEND( TYPE q or Q to Quit):" )
    except:
        #print sys.exc_info()
        print traceback.format_exc()
    finally:
        g.unload()
        natlink.natDisconnect()
        print 'iDisconnected.'
        s.close()
        print 'all closed'
Пример #20
0
def run():
    global s
    global g
    natlink.natConnect(1) #if natlink.isNatSpeakRunning() else wait
    try:
        print 'MicState:', natlink.getMicState()
        natlink.setBeginCallback(beginCallback)
        natlink.setChangeCallback(changeCallback)
        updateGrammarFromClient()
        natlink.setMicState('on')
        natlink.waitForSpeech(300)
        #data = client_socket.recv(512)
        #data = raw_input ( "SEND( TYPE q or Q to Quit):" )
    except:
        #print sys.exc_info()
        print traceback.format_exc()
    finally:
        g.unload()
        natlink.natDisconnect()
        print 'iDisconnected.'
        s.close()
        print 'all closed'
Пример #21
0
def run():
    natlink.natConnect(1)
    TestDialog(MakeDlgTemplate()).DoModal()
    natlink.natDisconnect()
 def PostDoModal(self):
     natlink.natDisconnect()
Пример #23
0
 def tearDown(self):
     natlink.natDisconnect()
     pass
Пример #24
0
def natDisconnect():
    natlink.natDisconnect()
    if debugLoad:
        print 'after natDisconnect'
Пример #25
0
 def PostDoModal(self):
     natlink.natDisconnect()
 def tearDown(self):
     self.folders.unload()
     natlink.natDisconnect()
Пример #27
0
        try:
            natlink.natDisconnect()
            natlink.natConnect(1)
        except:
            pass

    def PostDoModal(self):
        natlink.natDisconnect()



def CheckCreateApp():
    if sys.modules.has_key("pywin.framework.startup"):
        App=ServerApp()
        App.InitInstance()
    else:
        print 'does not have "pywin.framework.startup" imported'

def demodlg ():
    dlg=MainWindow()
    dlg.DoModal()


if __name__=='__main__':
    natlink.natConnect()
    demodlg()
    natlink.natDisconnect()
    #demomodeless()
else:
    CheckCreateApp()                        
Пример #28
0
 def PreDoModal(self):
     try:
         natlink.natDisconnect()
         natlink.natConnect(1)
     except:
         pass
Пример #29
0
def shutdown():
    print "shutting down"
    natlink.setTimerCallback(None)
    for g in grammars:
        grammars[g].unload()
    natlink.natDisconnect()
Пример #30
0
def run():
    natlink.natConnect(1)
    TestDialog(MakeDlgTemplate()).DoModal()
    natlink.natDisconnect()
 def PreDoModal(self):
     try:
         natlink.natDisconnect()
         natlink.natConnect(1)
     except:
         pass
Пример #32
0
 def disconnect(self):
     natlink.natDisconnect()
Пример #33
0
        return [nl_user_file, fallback_config_file]

    # choose between .natlink/natlink.ini in home or the fallback_directory:
    return [join(home, config_sub_dir, natlink_inifile), fallback_config_file]


def run() -> None:
    logger = logging.getLogger('natlink')
    try:
        # TODO: remove this hack. As of October 2021, win32api does not load properly, except if
        # the package pywin32_system32 is explictly put on new dll_directory white-list
        pywin32_dir = os.path.join(sysconfig.get_path('platlib'),
                                   "pywin32_system32")
        if os.path.isdir(pywin32_dir):
            os.add_dll_directory(pywin32_dir)

        config = NatlinkConfig.from_first_found_file(config_locations())
        main = NatlinkMain(logger, config)
        main.setup_logger()
        main.start()
    except Exception as exc:
        print(f'Exception: "{exc}" in loader.run', file=sys.stderr)
        print(traceback.format_exc())
        raise Exception from exc


if __name__ == "__main__":
    natlink.natConnect()
    run()
    natlink.natDisconnect()
 def disconnect(self):
     natlink.natDisconnect()
Пример #35
0
 def __exit__(self, exType, exValue, traceback):
     for g in self.grammars:
         g.unload()
     natlink.natDisconnect()
Пример #36
0
 def natDisconnect():
     natlink.natDisconnect()
     if debugLoad:
         print 'after natDisconnect'
Пример #37
0
 def tearDown(self):
     self.control.unload()
     natlink.natDisconnect()