Ejemplo n.º 1
0
 void OnApplicationQuit()
 {
     if (initialized || SphinxPlugin.Is_Recognizer_Enabled() == 1)
     {
         Stop();
     }
 }
Ejemplo n.º 2
0
 public static void Pause()
 {
     if (!initialized || SphinxPlugin.Is_Recognizer_Enabled() == 0)
     {
         Debug.LogWarning("Attempting to pause a recognizer that has not been initialized.");
         return;
     }
     running = false;
 }
Ejemplo n.º 3
0
 public static void Stop()
 {
     if (!initialized || SphinxPlugin.Is_Recognizer_Enabled() == 0)
     {
         Debug.LogWarning("Attempting to stop a recognizer that has not been initialized.");
     }
     SphinxPlugin.Free_Recognizer();
     instance.StopCoroutine("Recognize");
     initialized = false;
     running     = false;
 }
Ejemplo n.º 4
0
    public static bool IsRunning()
    {
        if ((running && SphinxPlugin.Is_Recognizer_Enabled() == 0) ||
            (!running && SphinxPlugin.Is_Recognizer_Enabled() == 1))
        {
            Debug.LogError("DLL and UnitySphinx somehow got out of sync. This should be impossible.");
            return(false);
        }
        bool isRunning = running && SphinxPlugin.Is_Recognizer_Enabled() == 1;

        return(isRunning);
    }
Ejemplo n.º 5
0
    public static bool IsInitialized()
    {
        if ((initialized && SphinxPlugin.Is_Recognizer_Enabled() == 0) ||
            (!initialized && SphinxPlugin.Is_Recognizer_Enabled() == 1))
        {
            Debug.LogError("DLL and UnitySphinx somehow got out of sync. This should be impossible.");
            return(false);
        }
        bool isInitialized = initialized && SphinxPlugin.Is_Recognizer_Enabled() == 1;

        return(isInitialized);
    }
Ejemplo n.º 6
0
    public static void Init(AudioDevice audioDevice, SearchModel searchModel, string hmm, string lm, string dict, string jsgf, string kws)
    {
        int searchInt = SearchModelToSearchInt(searchModel);
        int audioInt  = 0;

        if (audioDevice == AudioDevice.Mic)
        {
            audioInt = 0;
        }
        else if (audioDevice == AudioDevice.File)
        {
            audioInt = 1;
        }

        StringBuilder hmmSB  = new StringBuilder(hmm.Length);
        StringBuilder lmSB   = new StringBuilder(lm.Length);
        StringBuilder dictSB = new StringBuilder(dict.Length);
        StringBuilder jsgfSB = new StringBuilder(jsgf.Length);
        StringBuilder kwsSB  = new StringBuilder(kws.Length);

        hmmSB.Append(hmm);
        lmSB.Append(lm);
        dictSB.Append(dict);
        jsgfSB.Append(jsgf);
        kwsSB.Append(kws);

        if (instance == null)
        {
            //By Unity's design, an instance is required to start a coroutine for speech recognition
            Debug.LogError("There needs to be one instance of UnitySphinx in the scene. Initialization aborted.");
            return;
        }

        if (initialized || running || SphinxPlugin.Is_Recognizer_Enabled() == 1)
        {
            Debug.LogError("There was an attempt to initialize a new instance of UnitySphinx without stopping it. Aborted.");
            return;
        }
        //Stop ();

        int errcode = SphinxPlugin.Init_Recognizer(audioInt, searchInt,
                                                   hmmSB, lmSB, dictSB, jsgfSB, kwsSB);

        if (errcode != 0)
        {
            Debug.LogError("Pocketsphinx recognizer object failed to initialize.");
            if (errcode == -20)
            {
                Debug.LogError("Config failed to initialize properly.");
            }
            else if (errcode == -21)
            {
                Debug.LogError("Check that all your dictionary, grammar, and acoustic model paths are correct.");
            }
            else if (errcode == -31)
            {
                Debug.LogError("Failed to open mic device.");
            }
            else if (errcode == -32)
            {
                Debug.LogError("Failed to start recording through mic.");
            }
            else if (errcode == -33)
            {
                Debug.LogError("Failed to start utterance.");
            }
            else if (errcode == -61)
            {
                Debug.LogWarning("Pocketsphinx recognizer object was not initialized properly. Failed to set kws file.");
            }
            else if (errcode == -62)
            {
                Debug.LogWarning("Failed to set kws file. Ensure the path is valid.");
            }
            else if (errcode == -71)
            {
                Debug.LogWarning("Pocketsphinx recognizer object was not initialized properly. Failed to set jsgf file.");
            }
            else if (errcode == -72)
            {
                Debug.LogWarning("Failed to set jsgf file. Ensure the path is valid.");
            }
            else
            {
                Debug.LogWarning("Some other problem happened");
            }
            return;
        }
        initialized = true;
        instance.StartCoroutine("Recognize");
    }