예제 #1
0
        private async void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            if (!_isRecording)
            {
                _isRecording      = true;
                btnRecord.Content = "Go";
                _soundRecorder.StartRecording();
            }
            else
            {
                btnSendSMS.IsEnabled      = false;
                statusProgress.Visibility = Visibility.Visible;
                _isRecording               = false;
                btnRecord.Content          = "Converting...";
                btnRecord.IsEnabled        = false;
                txtSpeechOutput.IsReadOnly = true;
                _soundRecorder.StopRecording();

                //clientId = "your client id here";
                //clientSecret = "your client secret";
                try
                {
                    ContentInfo speechContentInfo = new ContentInfo();
                    speechContentInfo.Content = await _soundRecorder.GetBytes();

                    speechContentInfo.Name = _soundRecorder.FilePath;

                    SpeechService  speechService  = new SpeechService(new SDK.Entities.AttServiceSettings(clientId, clientSecret, new Uri(uriString)));
                    SpeechResponse speechResponse = await speechService.SpeechToText(speechContentInfo);

                    txtSpeechOutput.IsReadOnly = false;
                    if (null != speechResponse)
                    {
                        txtSpeechOutput.Text = speechResponse.GetTranscription();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                btnSendSMS.IsEnabled      = true;
                statusProgress.Visibility = Visibility.Collapsed;
                btnRecord.Content         = "Speak";
                btnRecord.IsEnabled       = true;
            }
        }
        private async void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            if (!_isRecording)
            {
                _isRecording = true;
                btnRecord.Content = "Go";
                _soundRecorder.StartRecording();
            }
            else
            {
                btnSendSMS.IsEnabled = false;
                statusProgress.Visibility = Visibility.Visible;
                _isRecording = false;
                btnRecord.Content = "Converting...";
                btnRecord.IsEnabled = false;
                txtSpeechOutput.IsReadOnly = true;
                _soundRecorder.StopRecording();

                //clientId = "your client id here";
                //clientSecret = "your client secret";
                try
                {
                    ContentInfo speechContentInfo = new ContentInfo();
                    speechContentInfo.Content = await _soundRecorder.GetBytes();
                    speechContentInfo.Name = _soundRecorder.FilePath;

                    SpeechService speechService = new SpeechService(new SDK.Entities.AttServiceSettings(clientId, clientSecret, new Uri(uriString)));
                    SpeechResponse speechResponse = await speechService.SpeechToText(speechContentInfo);
                    txtSpeechOutput.IsReadOnly = false;
                    if (null != speechResponse)
                    {
                        txtSpeechOutput.Text = speechResponse.GetTranscription();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                btnSendSMS.IsEnabled = true;
                statusProgress.Visibility = Visibility.Collapsed;
                btnRecord.Content = "Speak";
                btnRecord.IsEnabled = true;
            }
        }
예제 #3
0
        private async void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            if (!_isRecording)
            {
                _isRecording      = true;
                btnRecord.Content = "Stop";
                _soundRecorder.StartRecording();
            }
            else
            {
                statusProgress.Visibility = Visibility.Visible;
                _isRecording        = false;
                btnRecord.Content   = "Converting...";
                btnRecord.IsEnabled = false;
                _soundRecorder.StopRecording();

                clientId     = "your_att_app_key";
                clientSecret = "your_att_secret_key";
                uriString    = "https://api.att.com";
                try
                {
                    ContentInfo speechContentInfo = new ContentInfo();
                    speechContentInfo.Content = await _soundRecorder.GetBytes();

                    speechContentInfo.Name = _soundRecorder.FilePath;

                    SpeechService  speechService  = new SpeechService(new SDK.Entities.AttServiceSettings(clientId, clientSecret, new Uri(uriString)));
                    SpeechResponse speechResponse = await speechService.SpeechToText(speechContentInfo);

                    if (null != speechResponse)
                    {
                        txtSpeechOutput.Text = speechResponse.GetTranscription();
                    }
                }
                catch (Exception ex)
                {
                    txtSpeechOutput.Text = ex.Message;
                }

                statusProgress.Visibility = Visibility.Collapsed;
                btnRecord.Content         = "Start";
                btnRecord.IsEnabled       = true;
            }
        }
        private async void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            if (!_isRecording)
            {
                _isRecording = true;
                btnRecord.Content = "Stop";
                _soundRecorder.StartRecording();
            }
            else
            {
                statusProgress.Visibility = Visibility.Visible;
                _isRecording = false;
                btnRecord.Content = "Converting...";
                btnRecord.IsEnabled = false;
                _soundRecorder.StopRecording();

                clientId = "your_att_app_key";
                clientSecret = "your_att_secret_key";
                uriString = "https://api.att.com";
                try
                {
                    ContentInfo speechContentInfo = new ContentInfo();
                    speechContentInfo.Content = await _soundRecorder.GetBytes();
                    speechContentInfo.Name = _soundRecorder.FilePath;

                    SpeechService speechService = new SpeechService(new SDK.Entities.AttServiceSettings(clientId, clientSecret, new Uri(uriString)));
                    SpeechResponse speechResponse = await speechService.SpeechToText(speechContentInfo);
                    if (null != speechResponse)
                    {
                        txtSpeechOutput.Text = speechResponse.GetTranscription();
                    }
                }
                catch (Exception ex)
                {
                    txtSpeechOutput.Text = ex.Message;
                }

                statusProgress.Visibility = Visibility.Collapsed;
                btnRecord.Content = "Start";
                btnRecord.IsEnabled = true;
            }
        }
        /// <summary>
        /// Sends audio file to Speech service API and retrieves the recognition of call.
        /// </summary>
        /// <param name="attachment">Audio file.</param>
        /// <returns>Recognition of call.</returns>
        public async Task <SpeechResponse> Send(StorageFile attachment)
        {
            Argument.ExpectNotNull(() => attachment);

            var recognition = new StringBuilder();

            WinRTSDK.Entities.SpeechResponse taskResp = await _service.SpeechToText(attachment);

            foreach (NBest nBest in taskResp.Recognition.NBest)
            {
                foreach (var text in nBest.ResultText)
                {
                    recognition.Append(text);
                }
            }

            var response = new SpeechResponse(recognition.ToString());

            return(response);
        }