Exemplo n.º 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;
            }
        }
Exemplo n.º 2
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;
            }
        }