Esempio n. 1
0
    protected IEnumerator DoMicrophoneTest()
    {
        microphoneTestMessage.SetActive(true);
        bool   repeat = false;
        string wavFilePath;

        do
        {
            yield return(PressAnyKey("Press the spacebar to record a sound after the beep.", new KeyCode[] { KeyCode.Space }, textDisplayer));

            lowBeep.Play();
            textDisplayer.DisplayText("microphone test recording", "Recording...");
            textDisplayer.ChangeColor(Color.red);
            yield return(new WaitForSeconds(lowBeep.clip.length));

            wavFilePath = System.IO.Path.Combine(UnityEPL.GetDataPath(), "microphone_test_" + DataReporter.RealWorldTime().ToString("yyyy-MM-dd_HH_mm_ss") + ".wav");
            soundRecorder.StartRecording();
            yield return(new WaitForSeconds(5f));

            soundRecorder.StopRecording(wavFilePath);
            textDisplayer.ClearText();

            yield return(new WaitForSeconds(1f));

            textDisplayer.DisplayText("microphone test playing", "Playing...");
            textDisplayer.ChangeColor(Color.green);
            audioPlayback.clip = soundRecorder.AudioClipFromDatapath(wavFilePath);
            audioPlayback.Play();
            yield return(new WaitForSeconds(5f));

            textDisplayer.ClearText();
            textDisplayer.OriginalColor();

            textDisplayer.DisplayText("microphone test confirmation", "Did you hear the recording? \n(Y=Continue / N=Try Again / C=Cancel).");
            while (!Input.GetKeyDown(KeyCode.Y) && !Input.GetKeyDown(KeyCode.N) && !Input.GetKeyDown(KeyCode.C))
            {
                yield return(null);
            }
            textDisplayer.ClearText();

            if (Input.GetKey(KeyCode.C))
            {
                Quit();
            }
            repeat = Input.GetKey(KeyCode.N);
        }while (repeat);

        if (!System.IO.File.Exists(wavFilePath))
        {
            yield return(PressAnyKey("WARNING: Wav output file not detected.  Sounds may not be successfully recorded to disk.", new KeyCode[] { KeyCode.Return }, textDisplayer));
        }

        microphoneTestMessage.SetActive(false);
    }
        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.IsEnabled = false;
                _soundRecorder.StopRecording();

                try
                {
                    btnSpeech.AudioContent = await _soundRecorder.GetBytes();

                    btnSpeech.AudioContentName = _soundRecorder.FilePath;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                btnRecord.Content   = "Start";
                btnRecord.IsEnabled = true;
            }
        }
Esempio n. 3
0
    protected IEnumerator DoMicrophoneTest(string title, string press_any_key, string recording, string playing, string confirmation)
    {
        DisplayTitle(title);
        bool   repeat = false;
        string wavFilePath;

        do
        {
            yield return(PressAnyKey(press_any_key));

            lowBeep.Play();
            textDisplayer.DisplayText("microphone test recording", recording);
            textDisplayer.ChangeColor(Color.red);
            yield return(new WaitForSeconds(lowBeep.clip.length));

            wavFilePath = System.IO.Path.Combine(UnityEPL.GetDataPath(), "microphone_test_" + DataReporter.RealWorldTime().ToString("yyyy-MM-dd_HH_mm_ss") + ".wav");
            soundRecorder.StartRecording(wavFilePath);
            yield return(new WaitForSeconds(MICROPHONE_TEST_LENGTH));

            soundRecorder.StopRecording();

            textDisplayer.DisplayText("microphone test playing", playing);
            textDisplayer.ChangeColor(Color.green);

            audioPlayback.clip = soundRecorder.AudioClipFromDatapath(wavFilePath);
            audioPlayback.Play();
            yield return(new WaitForSeconds(MICROPHONE_TEST_LENGTH));

            textDisplayer.ClearText();
            textDisplayer.OriginalColor();

            SetRamulatorState("WAITING", true, new Dictionary <string, object>());
            textDisplayer.DisplayText("microphone test confirmation", confirmation);
            while (!Input.GetKeyDown(KeyCode.Y) && !Input.GetKeyDown(KeyCode.N) && !Input.GetKeyDown(KeyCode.C))
            {
                yield return(null);
            }
            textDisplayer.ClearText();
            SetRamulatorState("WAITING", false, new Dictionary <string, object>());
            if (Input.GetKey(KeyCode.C))
            {
                Quit();
            }
            repeat = Input.GetKey(KeyCode.N);
        }while (repeat);

        if (!System.IO.File.Exists(wavFilePath))
        {
            yield return(PressAnyKey("WARNING: Wav output file not detected.  Sounds may not be successfully recorded to disk."));
        }

        ClearTitle();
    }
Esempio n. 4
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;
            }
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
0
        private async void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            if (!_isRecording)
            {
                _isRecording      = true;
                btnRecord.Content = AppResources.txtStopRecord;
                _soundRecorder.StartRecording();
                btnSpeech.AudioContent      = null;
                tbErrorMessage.ErrorMessage = String.Empty;
            }
            else
            {
                _isRecording      = false;
                btnRecord.Content = AppResources.txtStartRecord;
                _soundRecorder.StopRecording();
                btnSpeech.AudioContent = await _soundRecorder.GetBytes();

                btnSpeech.AudioContentName = _soundRecorder.FilePath;
            }
        }