/// <summary>
    /// Feeds a pre-recorded speech audio file to the Speech Recognition service.
    /// Triggered from btnStartReco UI Canvas button.
    /// </summary>
    public void StartSpeechRecognitionFromFile()
    {
        // Replace this with your own file. Add it to the project and mark it as "Content" and "Copy if newer".
        //string audioFilePath = Path.Combine(Application.streamingAssetsPath, "Thisisatest.wav");
        string audioFilePath = Path.Combine(Application.temporaryCachePath, "recording.wav");

        Debug.Log($"Using speech audio file located at {audioFilePath}");

        Debug.Log($"Creating Speech Recognition job from audio file.");
        Task <bool> recojob = recoServiceClient.CreateSpeechRecognitionJobFromFile(audioFilePath, auth.GetAccessToken(), region);

        StartCoroutine(CompleteSpeechRecognitionJob(recojob));
        Debug.Log($"Speech Recognition job started.");
    }
Example #2
0
        /// <summary>
        /// Feeds a pre-recorded speech audio file to the Speech Recognition service.
        /// Triggered from btnStartReco UI Canvas button.
        /// </summary>
        public void StartSpeechRecognitionFromFile()
        {
            try
            {
                if (isAuthenticated)
                {
                    // Replace this with your own file. Add it to the project and mark it as "Content" and "Copy if newer".
                    //string audioFilePath = Path.Combine(Application.streamingAssetsPath, "Thisisatest.wav");
                    string audioFilePath = Path.Combine(Application.temporaryCachePath, "recording.wav");

                    if (!File.Exists(audioFilePath))
                    {
                        OnError?.Invoke("The file 'recording.wav' was not found. make sure to record one before starting recognition.");
                        return;
                    }

                    Debug.Log($"Using speech audio file located at {audioFilePath}");

                    Debug.Log($"Creating Speech Recognition job from audio file.");
                    Task <bool> recojob = recoServiceClient.CreateSpeechRecognitionJobFromFile(audioFilePath, auth.GetAccessToken(), region);

                    StartCoroutine(CompleteSpeechRecognitionJob(recojob));
                    Debug.Log($"Speech Recognition job started.");
                }
                else
                {
                    string msg = "Cannot start speech recognition job since authentication has not successfully completed.";
                    Debug.Log(msg);

                    OnError?.Invoke(msg);
                }
            }
            catch (Exception ex)
            {
                string msg = String.Format("Error: Something went wrong when starting the recognition process from a file. See error details below:{0}{1}{2}{3}",
                                           Environment.NewLine, ex.ToString(), Environment.NewLine, ex.Message);
                Debug.LogError(msg);

                OnError?.Invoke(msg);
            }
        }