Example #1
0
 void OnApplicationQuit()
 {
     if (initialized || SphinxPlugin.Is_Recognizer_Enabled() == 1)
     {
         Stop();
     }
 }
Example #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;
 }
Example #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;
 }
Example #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);
    }
Example #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);
    }
Example #6
0
    IEnumerator Recognize()
    {
        while (true)
        {
            yield return(null);

            if (running && Time.time - lastRecognized >= 0.1f)
            {
                lastRecognized = Time.time;
                SphinxPlugin.Recognize_Mic();
            }
        }
    }
Example #7
0
    public static string GetSearchModel()
    {
        StringBuilder str     = new StringBuilder(10);
        int           strlen  = str.Capacity;
        int           errcode = SphinxPlugin.Get_Search_Model(str, strlen);

        if (errcode == -91)
        {
            Debug.LogWarning("Pocketsphinx recognizer object was not initialized properly.");
        }
        else if (errcode == -92)
        {
            Debug.LogWarning("Pocketsphinx has no search model enabled.");
        }
        return(str.ToString());
    }
Example #8
0
    public static string DequeueString()
    {
        int strlen = SphinxPlugin.Request_Buffer_Length();

        // Not sure what the buffer size difference is between
        // char * and StringBuilder, so just add 10 more bytes
        strlen += 10;
        StringBuilder str = new StringBuilder(strlen);

        if (strlen > 0)
        {
            SphinxPlugin.Dequeue_String(str, strlen);
        }

        return(str.ToString());
    }
Example #9
0
    public static void SetkwsPath(string path)
    {
        Stop();
        StringBuilder str = new StringBuilder(path.Length);

        str.Append(path);
        int errcode = SphinxPlugin.Set_kws(str);

        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.");
        }
        instance.StartCoroutine("Recognize");
        searchModel = SearchModel.kws;
        Init();
        Run();
    }
Example #10
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");
    }
Example #11
0
 public static bool IsUtteranceStarted()
 {
     return(SphinxPlugin.Is_utt_started() == 1);
 }
Example #12
0
 public static int GetQueueLength()
 {
     return(SphinxPlugin.Get_Queue_Length());
 }