public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var speech = await SpeechWrapper.RecognizeSpeechAsync();

            return(new OkObjectResult(speech));
        }
Esempio n. 2
0
    // Make sure to kill the Kinect on quitting.
    void OnApplicationQuit()
    {
        // Shutdown Speech Recognizer and Kinect
        SpeechWrapper.FinishSpeechRecognizer();
        SpeechWrapper.ShutdownKinectSensor();

        sapiInitialized = false;
        instance        = null;
    }
    // Adds a phrase to the from-rule of dynamic grammar. If the to-rule is empty, this means end of the phrase recognition.
    public bool AddGrammarPhrase(string fromRule, string toRule, string phrase, bool bClearRulePhrases, bool bCommitGrammar)
    {
        if (sapiInitialized)
        {
            int hr = SpeechWrapper.AddGrammarPhrase(fromRule, toRule, phrase, bClearRulePhrases, bCommitGrammar);
            return(hr == 0);
        }

        return(false);
    }
Esempio n. 4
0
    void StartRecognizer()
    {
        try
        {
            // initialize Kinect sensor as needed
            int rc = SpeechWrapper.InitKinectSensor();
            if (rc != 0)
            {
                throw new Exception("Initialization of Kinect sensor failed");
            }

            // Initialize the kinect speech wrapper
            string sCriteria = String.Format("Language={0:X};Kinect=True", languageCode);
            rc = SpeechWrapper.InitSpeechRecognizer(sCriteria, true, false);

            if (rc < 0 && errorHandler == null)
            {
                errorHandler = new SpeechErrorHandler();
                string sErrorMessage = errorHandler.GetSapiErrorMessage(rc);

                throw new Exception(String.Format("Error initializing Kinect/SAPI: " + sErrorMessage));
            }

            if (requiredConfidence > 0)
            {
                SpeechWrapper.SetRequiredConfidence(requiredConfidence);
            }

            if (grammarFileName != string.Empty)
            {
                rc = SpeechWrapper.LoadSpeechGrammar(grammarFileName, (short)languageCode);

                if (rc < 0 && errorHandler == null)
                {
                    errorHandler = new SpeechErrorHandler();
                    string sErrorMessage = errorHandler.GetSapiErrorMessage(rc);

                    throw new Exception("Error loading grammar file " + grammarFileName + ": " + sErrorMessage);
                }
            }

            instance        = this;
            sapiInitialized = true;

            DontDestroyOnLoad(gameObject);
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
    }
Esempio n. 5
0
    //----------------------------------- end of public functions --------------------------------------//

    void Awake()
    {
        //debugText = GameObject.Find("DebugText");

        // ensure the needed dlls are in place
        if (SpeechWrapper.EnsureKinectWrapperPresence())
        {
            // reload the same level
            Application.LoadLevel(Application.loadedLevel);
        }
    }
Esempio n. 6
0
        public async Task <Result> FindAll(int page)
        {
            var result = await PaginatedList <Speech> .CreateAsync(db.speeches.AsNoTracking(), page, ConstantUtil.SPEECH_PAGE_SIZE, t => t.id);

            Dictionary <string, object> map = new Dictionary <string, object>();

            map.Add("Total", result.TotalPages);
            map.Add("Current", result.PageIndex);
            map.Add("Data", SpeechWrapper.WrapSpeech(result));

            return(ResultUtil.Success(map));
        }
    void Update()
    {
        // start Kinect speech recognizer as needed
        if (!sapiInitialized)
        {
            StartRecognizer();

            if (!sapiInitialized)
            {
                Application.Quit();
                return;
            }
        }

        if (sapiInitialized)
        {
            // update the speech recognizer
            int rc = SpeechWrapper.UpdateSpeechRecognizer();

            if (rc >= 0)
            {
                // estimate the listening state
                if (SpeechWrapper.IsSoundStarted())
                {
                    isListening = true;
                }
                else if (SpeechWrapper.IsSoundEnded())
                {
                    isListening = false;
                }

                // check if a grammar phrase has been recognized
                if (SpeechWrapper.IsPhraseRecognized())
                {
                    isPhraseRecognized = true;
                    phraseConfidence   = SpeechWrapper.GetPhraseConfidence();

                    IntPtr pPhraseTag = SpeechWrapper.GetRecognizedTag();
                    phraseTagRecognized = Marshal.PtrToStringUni(pPhraseTag);

                    SpeechWrapper.ClearPhraseRecognized();

                    //Debug.Log(phraseTagRecognized);
                }
            }
        }
    }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    var speechText = await SpeechWrapper.RecognizeSpeechAsync();
                    Console.WriteLine(speechText);
                    await context.Response.WriteAsync(speechText);
                });
            });
        }
Esempio n. 9
0
    void StartRecognizer()
    {
        try
        {
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please, wait...";
            }

            // initialize Kinect sensor as needed
            int rc = SpeechWrapper.InitKinectSensor();
            if (rc != 0)
            {
                throw new Exception("Initialization of Kinect sensor failed");
            }

            // Initialize the kinect speech wrapper
            string sCriteria = String.Format("Language={0:X};Kinect=True", LanguageCode);
            rc = SpeechWrapper.InitSpeechRecognizer(sCriteria, true, false);
            if (rc < 0)
            {
                throw new Exception(String.Format("Error initializing Kinect/SAPI: " + SpeechWrapper.GetSystemErrorMessage(rc)));
            }

            if (RequiredConfidence > 0)
            {
                SpeechWrapper.SetRequiredConfidence(RequiredConfidence);
            }

            if (GrammarFileName != string.Empty)
            {
                rc = SpeechWrapper.LoadSpeechGrammar(GrammarFileName, (short)LanguageCode);
                if (rc < 0)
                {
                    throw new Exception(String.Format("Error loading grammar file " + GrammarFileName + ": hr=0x{0:X}", rc));
                }
            }

            instance        = this;
            sapiInitialized = true;

            DontDestroyOnLoad(gameObject);

            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Ready.";
            }
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please check the Kinect and SAPI installations.";
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = ex.Message;
            }
        }
    }
Esempio n. 10
0
 public override void setUp(SpeechWrapper speechWrapper)
 {
     addPhraseCommand(new TestExample().create(speechWrapper.initWord));
 }
    void StartRecognizer()
    {
        try
        {
            if (errorHandler == null && debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please, wait...";
            }

            // initialize Kinect sensor as needed
            int rc = SpeechWrapper.InitKinectSensor();
            if (rc != 0)
            {
                throw new Exception("Initialization of Kinect sensor failed");
            }

            // Initialize the kinect speech wrapper
            string sCriteria = String.Format("Language={0:X};Kinect=True", languageCode);
            rc = SpeechWrapper.InitSpeechRecognizer(sCriteria, true, false);

            if (rc < 0 && errorHandler == null)
            {
                errorHandler = new SpeechErrorHandler();
                string sErrorMessage = errorHandler.GetSapiErrorMessage(rc);

                throw new Exception(String.Format("Error initializing Kinect/SAPI: " + sErrorMessage));
            }

            if (requiredConfidence > 0)
            {
                SpeechWrapper.SetRequiredConfidence(requiredConfidence);
            }

            if (grammarFileName != string.Empty)
            {
                rc = SpeechWrapper.LoadSpeechGrammar(grammarFileName, (short)languageCode, dynamicGrammar);

                if (rc < 0 && errorHandler == null)
                {
                    errorHandler = new SpeechErrorHandler();
                    string sErrorMessage = errorHandler.GetSapiErrorMessage(rc);

                    throw new Exception("Error loading grammar file " + grammarFileName + ": " + sErrorMessage);
                }

//				// test dynamic grammar phrases
//				rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Nancy Anderson", true, false);
//				rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Cindy White", false, false);
//				rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Oliver Lee", false, false);
//				rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Alan Brewer", false, false);
//				rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "April Reagan", false, true);
            }

            instance        = this;
            sapiInitialized = true;

            DontDestroyOnLoad(gameObject);

            if (errorHandler == null && debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Ready.";
            }
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = "Please check the Kinect and SAPI installations.";
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
            {
                debugText.GetComponent <GUIText>().text = ex.Message;
            }
        }
    }