async Task <string> SpeechToText(string audioFile)
        {
            try
            {
                switch (outputMode)
                {
                case OutputMode.Simple:
                    var simpleResult = await bingSpeechClient.SpeechToTextSimple(audioFile);

                    return(ProcessResult(simpleResult));

                case OutputMode.Detailed:
                    var detailedResult = await bingSpeechClient.SpeechToTextDetailed(audioFile);

                    return(ProcessResult(detailedResult));
                }

                return(null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }
예제 #2
0
        async Task <string> SpeechToText(string audioFile)
        {
            try
            {
                var speechResult = await bingSpeechClient.SpeechToTextSimple(audioFile);

                if (speechResult != null)
                {
                    var RecognitionStatus = speechResult.RecognitionStatus;
                    var DisplayText       = speechResult.DisplayText;
                    var Offset            = speechResult.Offset;
                    var Duration          = speechResult.Duration;
                }

                return(speechResult.DisplayText);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #3
0
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording) //Record button clicked
                {
                    //start recording audio
                    var audioRecordTask = await recorder.StartRecording();

                    var audioFile = await audioRecordTask;

                    //if we're not streaming the audio as we're recording, we'll use the file-based STT API here
                    if (audioFile != null)
                    {
                        var resultText = await bingSpeechClient.SpeechToTextSimple(audioFile);

                        if ((ResultsLabel.Text = resultText.DisplayText) != null)
                        {
                            var splitText = resultText.DisplayText.Split(new[] { ' ' }, 3);
                            if (splitText.Length == 3)
                            {
                                await DoCommands(splitText, resultText.DisplayText);
                            }
                        }
                    }
                }
                else //Stop button clicked
                {
                    //stop the recording...
                    await recorder.StopRecording();
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }