Exemple #1
0
def copyVclFileLanguageVersion(Input, Output):
    """copy to another location, keeping the include files one directory above
    """
    # let include lines to relative paths point to the folder above ..\
    # so you can take the same include file for the alternate language.
    reInclude = re.compile(r'^(\s*include\b\s*[\'\"]?)([^\s;=][^;=\n]*\s*;.*)$')
    Input     = os.path.normpath(Input)
    Output    = os.path.normpath(Output)
    input     = open(Input, 'r').read()
    output    = open(Output, 'w')
    language      = natlinkstatus.NatlinkStatus().getLanguage()
    output.write("# vocola file for alternate language: %s\n"% language)
    lines = map(string.strip, str(input).split('\n'))
    for line in lines:
        m = reInclude.match(line)
        if m:
            line = m.group(1) + "..\\" + m.group(2) 
        output.write(line + '\n')
    output.close()                
Exemple #2
0
def updateUnimacroHeaderIfNeeded():
    status = natlinkstatus.NatlinkStatus()
    if not status.getVocolaTakesUnimacroActions():
        return

    destDir = status.getVocolaUserDirectory()
    coreFolder = os.path.split(__file__)[0]
    sourceDir = os.path.join(coreFolder, "..", "..", "..", "Unimacro",
                             'vocola_compatibility')
    destPath = os.path.join(destDir, 'Unimacro.vch')
    sourcePath = os.path.join(sourceDir, 'Unimacro.vch')
    sourceTime, destTime = vocolaGetModTime(sourcePath), \
                           vocolaGetModTime(destPath)

    if not (sourceTime or destTime):
        print >> sys.stderr, """\n
Error: The option "Vocola Takes Unimacro Actions" is switched on, but
no file "Unimacro.vch" is found.

Please fix the configuration of NatLink/Vocola/Unimacro and restart
Dragon.  Either ensure the source file is at:
    "%s",
or switch off the option "Vocola Takes Unimacro Actions".
""" % sourceDir
        return

    if destTime < sourceTime:
        try:
            shutil.copyfile(sourcePath, destPath)
        except IOError:
            print >> sys.stderr, """\n
Warning: Could not copy example "Unimacro.vch" to:
    "%s".

There is a valid "Unimacro.vch" available, but a newer file is
available at: "%s".

Please fix the configuration of NatLink/Vocola/Unimacro and restart
Dragon, if you want to use the updated version of this file.""" % (destDir,
                                                                   sourceDir)
        else:
            print 'Succesfully copied "Unimacro.vch" from\n\t"%s" to\n\t"%s".' % (
                sourceDir, destDir)
Exemple #3
0
    def set_retain_directory(self, retain_dir):
        """
        Set the directory where audio data is saved.

        Retaining audio data may be useful for acoustic model training. This
        is disabled by default.

        If a relative path is used and the code is running via natspeak.exe,
        then the path will be made relative to the Natlink user directory or
        base directory (e.g. ``MacroSystem``).

        :param retain_dir: retain directory path
        :type retain_dir: string|None
        """
        is_string = isinstance(retain_dir, string_types)
        if not (retain_dir is None or is_string):
            raise EngineError("Invalid retain_dir: %r" % retain_dir)

        if is_string:
            # Handle relative paths by using the Natlink user directory or
            # base directory. Only do this if running via natspeak.exe.
            try:
                import natlinkstatus
            except ImportError:
                natlinkstatus = None
            running_via_natspeak = (
                sys.executable.endswith("natspeak.exe") and
                natlinkstatus is not None
            )
            if not os.path.isabs(retain_dir) and running_via_natspeak:
                status = natlinkstatus.NatlinkStatus()
                user_dir = status.getUserDirectory()
                retain_dir = os.path.join(
                    # Use the base dir if user dir isn't set.
                    user_dir if user_dir else status.BaseDirectory,
                    retain_dir
                )

        # Set the retain directory.
        self._retain_dir = retain_dir
Exemple #4
0
def reboot():
    # TODO: Save engine arguments elsewhere and retrieves for reboot. Allows for user-defined arguments.
    popen_parameters = []
    engine = get_current_engine()
    if engine.name == 'kaldi':
        engine.disconnect()
        subprocess.Popen([
            sys.executable, '-m', 'dragonfly', 'load', '_*.py', '--engine',
            'kaldi', '--no-recobs-messages'
        ])
    if engine.name == 'sapi5inproc':
        engine.disconnect()
        subprocess.Popen([
            sys.executable, '-m', 'dragonfly', 'load', '--engine',
            'sapi5inproc', '_*.py', '--no-recobs-messages'
        ])
    if engine.name in ["sapi5shared", "sapi5"]:
        popen_parameters.append(settings.SETTINGS["paths"]["REBOOT_PATH_WSR"])
        popen_parameters.append(settings.SETTINGS["paths"]["WSR_PATH"])
        printer.out(popen_parameters)
        subprocess.Popen(popen_parameters)
    if engine.name == 'natlink':
        import natlinkstatus  # pylint: disable=import-error
        status = natlinkstatus.NatlinkStatus()
        if status.NatlinkIsEnabled() == 1:
            # Natlink in-process
            popen_parameters.append(settings.SETTINGS["paths"]["REBOOT_PATH"])
            popen_parameters.append(settings.SETTINGS["paths"]["ENGINE_PATH"])
            username = status.getUserName()
            popen_parameters.append(username)
            printer.out(popen_parameters)
            subprocess.Popen(popen_parameters)
        else:
            # Natlink out-of-process
            engine.disconnect()
            subprocess.Popen([
                sys.executable, '-m', 'dragonfly', 'load', '--engine',
                'natlink', '_*.py', '--no-recobs-messages'
            ])
Exemple #5
0
    import natlinkstatus  # for extracting status info (QH)
    import natlinkstartup
    debugTiming = 0
    #
    # This redirects stdout and stderr to a dialog box.
    #
    # bookkeeping for Vocola:
    vocolaEnabled = 1  # first time try, is set to 0 if _vocola_main signals it is not active
    doVocolaFirst = '_vocola_main'
    vocolaIsLoaded = None  # 1 or None
    vocolaModule = None  # pointer to the module...

    reVocolaModuleName = re.compile(r'_vcl[0-9]?$')

    # status:
    status = natlinkstatus.NatlinkStatus()
    status.checkSysPath()
    debugLoad = status.getDebugLoad()
    debugCallback = status.getDebugCallback()
    if debugLoad:
        print 'do extra output at (re)loading time: %s' % debugLoad
    if debugCallback:
        print 'do extra output at callback time: %s' % debugCallback

    # QH added:checkForGrammarChanges is set when calling "edit grammar ..." in the control grammar,
    # otherwise no grammar change checking is performed, only at microphone toggle
    checkForGrammarChanges = 0

    def setCheckForGrammarChanges(value):
        """switching on or off (1 or 0), for continuous checking or only a mic toggle"""
        global checkForGrammarChanges
Exemple #6
0
            path = os.path.join("..", "..", name[4:])
            suite.addTests(doctest.DocFileSuite(path))
        else:
            raise Exception("Invalid test name: %r." % (name, ))
    return suite


sapi5_suite = build_suite(EngineTestSuite("sapi5"), sapi5_names)
sapi5inproc_suite = build_suite(EngineTestSuite("sapi5inproc"), sapi5_names)
sphinx_suite = build_suite(EngineTestSuite("sphinx"), sphinx_names)
text_suite = build_suite(EngineTestSuite("text"), text_names)

# Build the natlink test suite for the current version of DNS.
try:
    import natlinkstatus
    dns_version = int(natlinkstatus.NatlinkStatus().getDNSVersion())
except:
    # Couldn't get the DNS version for whatever reason.
    dns_version = None

# Use different test names depending on the DNS version. Fallback on v11 if
# the version is unknown.
if dns_version and dns_version <= 10:
    natlink_names = natlink_10_names
else:
    natlink_names = natlink_11_names

# Exclude the grammar lists doctest file for DNS 15 and above due to a minor
# bug with natlink/Dragon.
if dns_version and dns_version >= 15:
    lists_doctest = "doc:documentation/test_grammar_list_doctest.txt"