Exemple #1
0
    //----------------------------------------------------------------------
    //! @brief 録音処理
    //!
    //! @param[in] なし
    //!
    //! @return なし
    //----------------------------------------------------------------------
    IEnumerator RecMic(AudioSource audioSource)
    {
        if (m_voiceRecFlag)
        {
            MyDebug.Log("Start record");
            m_text.text              = "録音開始";
            audioSource.clip         = Microphone.Start(null, true, 10, 44100);
            audioSource.loop         = false;
            audioSource.spatialBlend = 0.0f;
            yield return(new WaitForSeconds(2.0f));

            Microphone.End(null);
            MyDebug.Log("Finish record");
            m_text.text = "録音終了";


            // SpeechToText を日本語指定して、録音音声をテキストに変換
            m_SpeechToText.RecognizeModel = "ja-JP_BroadbandModel";
            m_SpeechToText.Recognize(HandleOnRecognize, OnFail, audioSource.clip);

            m_voiceRecFlag = false;

            m_text.text = "認識中";
        }
    }
    private void AudioClipCallback(AudioClip clip)
    {
        if (player != null)
        {
            //player.StartPlaying(clip);
        }
        else
        {
            print("***PLAYER MISSING***");
        }

        //AudioData record = new AudioData( clip, Mathf.Max(clip.samples / 2) );

        //int midPoint = clip.samples / 2;
        //float[] samples = new float[midPoint];
        //clip.GetData(samples, 0);

        //AudioData record = new AudioData();
        //record.MaxLevel = Mathf.Max(samples);
        //record.Clip = AudioClip.Create("Recording", midPoint, clip.channels, clip.frequency, false);
        //record.Clip.SetData(samples, 0);

        //_speechToText.OnListen(record);

        AudioClip _audioClip = WaveFile.ParseWAV("testClip", AudioClipToByteArray(clip));

        _speechToText.Recognize(_audioClip, OnRecognize);


        print("AUDIO CLIP SENT");
    }
Exemple #3
0
        private async void textRecognizerButton_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(filePathTextBox.Text))
            {
                // Usando esse tipo de reconhecimento de fala, você terá apenas o texto extraído do áudio
                // que não possui nenhum tipo processamento de linguagem natural, dificultando a identificação da intenção no comando de voz
                var result = await _speechToText.Recognize(filePathTextBox.Text);

                if (result.Success)
                {
                    MessageBox.Show("Conteúdo reconhecido:\r\n\r\n" + result.Data);

                    if (result.Data.ToLower().Contains("desligar"))
                    {
                        _iotHubService.DeviceControl(false, "lampada");
                        ChangePicture(false);
                    }
                    else if (result.Data.ToLower().Contains("ligar"))
                    {
                        _iotHubService.DeviceControl(true, "lampada");
                        ChangePicture(true);
                    }
                }
                else
                {
                    MessageBox.Show(result.Error, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Selecione um arquivo de áudio!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (CaptureMedia == null)
            {
                btnRecognition.Content = "Stop Voice Recognition";
                CaptureMedia           = new MediaCapture();
                var captureInitSettings = new MediaCaptureInitializationSettings();
                captureInitSettings.StreamingCaptureMode = StreamingCaptureMode.Audio;
                await CaptureMedia.InitializeAsync(captureInitSettings);

                CaptureMedia.Failed += MediaCaptureOnFailed;
                CaptureMedia.RecordLimitationExceeded += MediaCaptureOnRecordLimitationExceeded;

                MediaEncodingProfile encodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Medium);
                AudioStream = new InMemoryRandomAccessStream();

                await CaptureMedia.StartRecordToStreamAsync(encodingProfile, AudioStream);
            }
            else
            {
                btnRecognition.Content = "Start Voice Recognition";
                await CaptureMedia.StopRecordAsync();

                var    auth  = new Authenticator();
                string token = await auth.Authenticate("97ca907166a84fa7baf8e3a7a3faca3f");

                var a = new SpeechToText();
                a.AuthorizationToken = token;

                byte[] buffer = null;

                //var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///whatstheweatherlike.wav"));
                //using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
                //{
                //    buffer = new byte[stream.Size];

                //    using (DataReader reader = new DataReader(stream))
                //    {
                //        await reader.LoadAsync((uint)stream.Size);
                //        reader.ReadBytes(buffer);
                //    }
                //}

                using (var dataReader = new DataReader(AudioStream.GetInputStreamAt(0)))
                {
                    await dataReader.LoadAsync((uint)AudioStream.Size);

                    buffer = new byte[(int)AudioStream.Size];
                    dataReader.ReadBytes(buffer);
                }

                var response = await a.Recognize(CancellationToken.None, buffer);
            }
        }
Exemple #5
0
    private void Recognize()
    {
        //  create AudioClip with clip bytearray data
        _audioClip = clip;

        _speechToText.Keywords          = new string[] { "E1", "E2", "E3", "E4", "E5" };
        _speechToText.KeywordsThreshold = 0.3f;
        if (!_speechToText.Recognize(HandleRecognize, OnFail, _audioClip))
        {
            Debug.Log("ExampleSpeechToText.Recognize() Failed to recognize!");
        }
    }
    private IEnumerator RecordingHandler2()
    {
        m_readytosend = false;
        Log.Debug("ExampleStreaming", "devices: {0}", Microphone.devices);
        m_Recording = Microphone.Start(m_MicrophoneID, false, m_RecordingBufferSize, m_RecordingHZ);
        yield return(null);             // let m_RecordingRoutine get set..

        if (m_Recording == null)
        {
            StopRecording();
            yield break;
        }

        //m_textField.text = "Recording";
        while (m_RecordingRoutine != 0 && m_Recording != null)
        {
            int writePos = Microphone.GetPosition(m_MicrophoneID);
            if (writePos > m_Recording.samples || !Microphone.IsRecording(m_MicrophoneID))
            {
                Log.Error("MicrophoneWidget", "Microphone disconnected.");

                StopRecording();
                yield break;
            }
            else if (m_readytosend)
            {
                float[] samples = null;
                samples = new float[writePos];

                Microphone.End(m_MicrophoneID);

                m_Recording.GetData(samples, 0);

                AudioData record = new AudioData();
                record.MaxLevel = Mathf.Max(samples);
                record.Clip     = AudioClip.Create("Recording", writePos, m_Recording.channels, m_RecordingHZ, false);
                record.Clip.SetData(samples, 0);

                m_mostRecentClip = AudioClip.Create("clipx", writePos, 1, m_RecordingHZ, false);
                m_mostRecentClip.SetData(samples, 0);
                m_SpeechToText.Recognize(m_mostRecentClip, OnRecognize);
                StopRecording();
            }
            else
            {
                yield return(new WaitUntil(() => m_readytosend == true));
            }
        }

        yield break;
    }
Exemple #7
0
    // Use this for initialization
    void Start()
    {
        List <string> keywords = new List <string>();

        keywords.Add("speech");
        speechToText.KeywordsThreshold = 0.5f;
        speechToText.InactivityTimeout = 120;
        speechToText.StreamMultipart   = false;
        speechToText.Keywords          = keywords.ToArray();

        Debug.Log("Attempting to recognize", gameObject);
        //Recognize
        speechToText.Recognize(HandleOnRecognize, OnFail, resource, resourceType);
    }
    // ------------------------------------------
    //  GOOGLE
    // ------------------------------------------

    protected String ProcessAudioStream(Stream stream, String language, String text) {
      Host.Log(this,"ProcessAudioStream: " + language + " " + text);

      // See: https://github.com/gillesdemey/google-speech-v2
      CultureInfo culture = new System.Globalization.CultureInfo(language);
      var stt = new SpeechToText("https://www.google.com/speech-api/v2/recognize?output=json&xjerr=1&client=chromium&maxresults=2&key=" + GoogleKey, culture);

      using (var audio = new MemoryStream()) {
        stream.Position = 0;
        stream.CopyTo(audio);

        audio.Position = 0;
        return stt.Recognize(audio);
      }
    }
Exemple #9
0
        // ------------------------------------------
        //  GOOGLE
        // ------------------------------------------

        protected String ProcessAudioStream(Stream stream, String language, String text)
        {
            Host.Log(this, "ProcessAudioStream: " + language + " " + text);

            // See: https://github.com/gillesdemey/google-speech-v2
            CultureInfo culture = new System.Globalization.CultureInfo(language);
            var         stt     = new SpeechToText("https://www.google.com/speech-api/v2/recognize?output=json&xjerr=1&client=chromium&maxresults=2&key=" + GoogleKey, culture);

            using (var audio = new MemoryStream()) {
                stream.Position = 0;
                stream.CopyTo(audio);

                audio.Position = 0;
                return(stt.Recognize(audio));
            }
        }
    IEnumerator RecMic(AudioSource audioSource)
    {
        Debug.Log("Start record");
        audioSource.clip         = Microphone.Start(null, true, 4, 44100);
        audioSource.loop         = false;
        audioSource.spatialBlend = 0.0f;
        yield return(new WaitForSeconds(2.0f));

        Microphone.End(null);
        Debug.Log("Finish record");

        // 音声の認識言語を日本語に指定
        m_SpeechToText.RecognizeModel = "ja-JP_BroadbandModel";
        // 音声をテキストに変換し、関数:HandleOnRecognize()を呼ぶ
        m_SpeechToText.Recognize(audioSource.clip, HandleOnRecognize);
    }
    IEnumerator transformSpeechToText()
    {
        // 音声をマイクから 3 秒間取得する
                Debug.Log("Start record"); //集音開始
        recText.SetActive(true);
                var audioSource = GetComponent <AudioSource>();

                audioSource.clip         = Microphone.Start(null, true, 10, 44100);
                audioSource.loop         = false;
                audioSource.spatialBlend = 0.0f;
                yield return(new WaitForSeconds(3f));

                Microphone.End(null); //集音終了
                Debug.Log("Finish record");
        recText.SetActive(false);
         
                m_SpeechToText.Recognize(HandleOnRecognize, OnFail, audioSource.clip);
    }
Exemple #12
0
    private void OnRecordingEnd(AudioClip clip)
    {
        if (player != null)
        {
            print("AUDIO PLAYBACK");
        }
        //player.StartPlaying(clip);
        else
        {
            OnPlayingEnd(false);
        }

        AudioClip _audioClip = WaveFile.ParseWAV("testClip", AudioClipToByteArray(clip));

        _speechToText.Recognize(_audioClip, OnRecognize);


        //apiAiUnity.StartVoiceRequestThread(_aiClip);
    }
Exemple #13
0
    // Use this for initialization
    void Start()
    {
        //Get Resource
        string resourcePath = Application.dataPath + "/sound/1.mp3";

        byte[] resource     = File.ReadAllBytes(resourcePath);
        string resourceType = Utility.GetMimeType(Path.GetExtension(resourcePath));

        //Create keyword list
        List <string> keywords = new List <string>();

        keywords.Add("speech");
        speechToText.KeywordsThreshold = 0.5f;
        speechToText.InactivityTimeout = 120;
        speechToText.StreamMultipart   = false;
        speechToText.Keywords          = keywords.ToArray();

        Debug.Log("Attempting to recognize", gameObject);
        //Recognize
        speechToText.Recognize(HandleOnRecognize, OnFail, resource, resourceType);
    }
    // Use this for initialization
    IEnumerator Start()
    {
        // 音声をマイクから 3 秒間取得する
        Debug.Log("Start record");  //集音開始
        var audioSource = GetComponent <AudioSource>();

        audioSource.clip         = Microphone.Start(null, true, 10, 44100);
        audioSource.loop         = false;
        audioSource.spatialBlend = 0.0f;
        yield return(new WaitForSeconds(3f));

        Microphone.End(null);  //集音終了
        Debug.Log("Finish record");

        // ためしに録音内容を再生してみる
        audioSource.Play();

        // SpeechToText を日本語指定して、録音音声をテキストに変換
        m_SpeechToText.RecognizeModel = "ja-JP_BroadbandModel";
        m_SpeechToText.Recognize(audioSource.clip, HandleOnRecognize);
    }
Exemple #15
0
    IEnumerator Start()
    {
        Debug.Log("Start");
        Credentials credentials = new Credentials(cre_id, cre_pw, cre_url);

        m_SpeechToText                   = new SpeechToText(credentials);
        m_SpeechToText.Keywords          = new string[] { "ibm" };
        m_SpeechToText.KeywordsThreshold = 0.1f;

        yield return(new WaitForSeconds(1f));

        Debug.Log("Start record");
        this.audioSource.Play();
        yield return(new WaitForSeconds(0.1f));

        var audioSource = GetComponent <AudioSource>();

        audioSource.clip         = Microphone.Start(null, true, 10, 44100);
        audioSource.loop         = false;
        audioSource.spatialBlend = 0.0f;

        yield return(new WaitForSeconds(MAXIMUM_LENGTH));

        Microphone.End(null);
        Debug.Log("Finish record");

        Debug.Log("Playing");
        audioSource.Play();
        Debug.Log("Play Finished");
        this.audioSource.Play();
        yield return(new WaitForSeconds(1f));

        // SpeechToText を日本語指定して、録音音声をテキストに変換
        m_SpeechToText.RecognizeModel = "ja-JP_BroadbandModel";
        m_SpeechToText.Recognize(HandleOnRecognize, OnFail, audioSource.clip);

        yield return(new WaitForSeconds(1f));
    }
    private IEnumerator Examples()
    {
        //  Recognize
        Log.Debug("ExampleSpeechToText", "Attempting to recognize");
        List <string> keywords = new List <string>();

        keywords.Add("speech");
        _speechToText.KeywordsThreshold = 0.5f;
        _speechToText.Keywords          = keywords.ToArray();
        _speechToText.Recognize(_audioClip, HandleOnRecognize);
        while (!_recognizeTested)
        {
            yield return(null);
        }

        //  Get models
        Log.Debug("ExampleSpeechToText", "Attempting to get models");
        _speechToText.GetModels(HandleGetModels);
        while (!_getModelsTested)
        {
            yield return(null);
        }

        //  Get model
        Log.Debug("ExampleSpeechToText", "Attempting to get model {0}", _modelNameToGet);
        _speechToText.GetModel(HandleGetModel, _modelNameToGet);
        while (!_getModelTested)
        {
            yield return(null);
        }

        //  Get customizations
        Log.Debug("ExampleSpeechToText", "Attempting to get customizations");
        _speechToText.GetCustomizations(HandleGetCustomizations);
        while (!_getCustomizationsTested)
        {
            yield return(null);
        }

        //  Create customization
        Log.Debug("ExampleSpeechToText", "Attempting create customization");
        _speechToText.CreateCustomization(HandleCreateCustomization, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity");
        while (!_createCustomizationsTested)
        {
            yield return(null);
        }

        //  Get customization
        Log.Debug("ExampleSpeechToText", "Attempting to get customization {0}", _createdCustomizationID);
        _speechToText.GetCustomization(HandleGetCustomization, _createdCustomizationID);
        while (!_getCustomizationTested)
        {
            yield return(null);
        }

        //  Get custom corpora
        Log.Debug("ExampleSpeechToText", "Attempting to get custom corpora for {0}", _createdCustomizationID);
        _speechToText.GetCustomCorpora(HandleGetCustomCorpora, _createdCustomizationID);
        while (!_getCustomCorporaTested)
        {
            yield return(null);
        }

        //  Add custom corpus
        Log.Debug("ExampleSpeechToText", "Attempting to add custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
        _speechToText.AddCustomCorpus(HandleAddCustomCorpus, _createdCustomizationID, _createdCorpusName, true, _customCorpusFilePath);
        while (!_addCustomCorpusTested)
        {
            yield return(null);
        }

        //  Get custom corpus
        Log.Debug("ExampleSpeechToText", "Attempting to get custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
        _speechToText.GetCustomCorpus(HandleGetCustomCorpus, _createdCustomizationID, _createdCorpusName);
        while (!_getCustomCorpusTested)
        {
            yield return(null);
        }

        //  Wait for customization
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Get custom words
        Log.Debug("ExampleSpeechToText", "Attempting to get custom words.");
        _speechToText.GetCustomWords(HandleGetCustomWords, _createdCustomizationID);
        while (!_getCustomWordsTested)
        {
            yield return(null);
        }

        //  Add custom words from path
        Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words json path {1}", _createdCustomizationID, _customWordsFilePath);
        string customWords = File.ReadAllText(_customWordsFilePath);

        _speechToText.AddCustomWords(HandleAddCustomWordsFromPath, _createdCustomizationID, customWords);
        while (!_addCustomWordsFromPathTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isCustomizationReady = false;
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Add custom words from object
        Words       words    = new Words();
        Word        w0       = new Word();
        List <Word> wordList = new List <Word>();

        w0.word           = "mikey";
        w0.sounds_like    = new string[1];
        w0.sounds_like[0] = "my key";
        w0.display_as     = "Mikey";
        wordList.Add(w0);
        Word w1 = new Word();

        w1.word           = "charlie";
        w1.sounds_like    = new string[1];
        w1.sounds_like[0] = "char lee";
        w1.display_as     = "Charlie";
        wordList.Add(w1);
        Word w2 = new Word();

        w2.word           = "bijou";
        w2.sounds_like    = new string[1];
        w2.sounds_like[0] = "be joo";
        w2.display_as     = "Bijou";
        wordList.Add(w2);
        words.words = wordList.ToArray();

        Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words object", _createdCustomizationID);
        _speechToText.AddCustomWords(HandleAddCustomWordsFromObject, _createdCustomizationID, words);
        while (!_addCustomWordsFromObjectTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isCustomizationReady = false;
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Get custom word
        Log.Debug("ExampleSpeechToText", "Attempting to get custom word {1} in customization {0}", _createdCustomizationID, words.words[0].word);
        _speechToText.GetCustomWord(HandleGetCustomWord, _createdCustomizationID, words.words[0].word);
        while (!_getCustomWordTested)
        {
            yield return(null);
        }

        //  Train customization
        Log.Debug("ExampleSpeechToText", "Attempting to train customization {0}", _createdCustomizationID);
        _speechToText.TrainCustomization(HandleTrainCustomization, _createdCustomizationID);
        while (!_trainCustomizationTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isCustomizationReady = false;
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Upgrade customization - not currently implemented in service
        //Log.Debug("ExampleSpeechToText", "Attempting to upgrade customization {0}", _createdCustomizationID);
        //_speechToText.UpgradeCustomization(HandleUpgradeCustomization, _createdCustomizationID);
        //while (!_upgradeCustomizationTested)
        //    yield return null;

        //  Delete custom word
        Log.Debug("ExampleSpeechToText", "Attempting to delete custom word {1} in customization {0}", _createdCustomizationID, words.words[2].word);
        _speechToText.DeleteCustomWord(HandleDeleteCustomWord, _createdCustomizationID, words.words[2].word);
        while (!_deleteCustomWordTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleDiscovery", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete custom corpus
        Log.Debug("ExampleSpeechToText", "Attempting to delete custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
        _speechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, _createdCustomizationID, _createdCorpusName);
        while (!_deleteCustomCorpusTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleDiscovery", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Reset customization
        Log.Debug("ExampleSpeechToText", "Attempting to reset customization {0}", _createdCustomizationID);
        _speechToText.ResetCustomization(HandleResetCustomization, _createdCustomizationID);
        while (!_resetCustomizationTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleDiscovery", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete customization
        Log.Debug("ExampleSpeechToText", "Attempting to delete customization {0}", _createdCustomizationID);
        _speechToText.DeleteCustomization(HandleDeleteCustomization, _createdCustomizationID);
        while (!_deleteCustomizationsTested)
        {
            yield return(null);
        }

        Log.Debug("ExampleSpeechToText", "Speech to Text examples complete.");
    }
 public void dectateOn()
 {
     m_SpeechToText.Recognize(m_AudioClip, HandleOnRecognize);
 }
        public override IEnumerator RunTest()
        {
            LogSystem.InstallDefaultReactors();

            VcapCredentials vcapCredentials = new VcapCredentials();
            fsData          data            = null;

            string result = null;
            string credentialsFilepath = "../sdk-credentials/credentials.json";

            //  Load credentials file if it exists. If it doesn't exist, don't run the tests.
            if (File.Exists(credentialsFilepath))
            {
                result = File.ReadAllText(credentialsFilepath);
            }
            else
            {
                yield break;
            }

            //  Add in a parent object because Unity does not like to deserialize root level collection types.
            result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");

            //  Convert json to fsResult
            fsResult r = fsJsonParser.Parse(result, out data);

            if (!r.Succeeded)
            {
                throw new WatsonException(r.FormattedMessages);
            }

            //  Convert fsResult to VcapCredentials
            object obj = vcapCredentials;

            r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
            if (!r.Succeeded)
            {
                throw new WatsonException(r.FormattedMessages);
            }

            //  Set credentials from imported credntials
            Credential credential = vcapCredentials.GetCredentialByname("speech-to-text-sdk")[0].Credentials;
            //  Create credential and instantiate service
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey = credential.IamApikey,
            };

            //  Create credential and instantiate service
            Credentials credentials = new Credentials(tokenOptions, credential.Url);

            //  Wait for tokendata
            while (!credentials.HasIamTokenData())
            {
                yield return(null);
            }

            _speechToText             = new SpeechToText(credentials);
            _customCorpusFilePath     = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/speech-to-text/theJabberwocky-utf8.txt";
            _customWordsFilePath      = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/speech-to-text/test-stt-words.json";
            _grammarFilePath          = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/speech-to-text/confirm.abnf";
            _acousticResourceMimeType = Utility.GetMimeType(Path.GetExtension(_acousticResourceUrl));

            Runnable.Run(DownloadAcousticResource());
            while (!_isAudioLoaded)
            {
                yield return(null);
            }

            //  Recognize
            Log.Debug("TestSpeechToText.Examples()", "Attempting to recognize");
            List <string> keywords = new List <string>();

            keywords.Add("speech");
            _speechToText.KeywordsThreshold = 0.5f;
            _speechToText.InactivityTimeout = 120;
            _speechToText.StreamMultipart   = false;
            _speechToText.Keywords          = keywords.ToArray();
            _speechToText.Recognize(HandleOnRecognize, OnFail, _acousticResourceData, _acousticResourceMimeType);
            while (!_recognizeTested)
            {
                yield return(null);
            }

            //  Get models
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get models");
            _speechToText.GetModels(HandleGetModels, OnFail);
            while (!_getModelsTested)
            {
                yield return(null);
            }

            //  Get model
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get model {0}", _modelNameToGet);
            _speechToText.GetModel(HandleGetModel, OnFail, _modelNameToGet);
            while (!_getModelTested)
            {
                yield return(null);
            }

            //  Get customizations
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get customizations");
            _speechToText.GetCustomizations(HandleGetCustomizations, OnFail);
            while (!_getCustomizationsTested)
            {
                yield return(null);
            }

            //  Create customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting create customization");
            _speechToText.CreateCustomization(HandleCreateCustomization, OnFail, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity");
            while (!_createCustomizationsTested)
            {
                yield return(null);
            }

            //  Get customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get customization {0}", _createdCustomizationID);
            _speechToText.GetCustomization(HandleGetCustomization, OnFail, _createdCustomizationID);
            while (!_getCustomizationTested)
            {
                yield return(null);
            }

            //  Get custom corpora
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get custom corpora for {0}", _createdCustomizationID);
            _speechToText.GetCustomCorpora(HandleGetCustomCorpora, OnFail, _createdCustomizationID);
            while (!_getCustomCorporaTested)
            {
                yield return(null);
            }

            //  Add custom corpus
            Log.Debug("TestSpeechToText.Examples()", "Attempting to add custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            string corpusData = File.ReadAllText(_customCorpusFilePath);

            _speechToText.AddCustomCorpus(HandleAddCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName, true, corpusData);
            while (!_addCustomCorpusTested)
            {
                yield return(null);
            }

            //  Get custom corpus
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            _speechToText.GetCustomCorpus(HandleGetCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName);
            while (!_getCustomCorpusTested)
            {
                yield return(null);
            }

            //  Wait for customization
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Get custom words
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get custom words.");
            _speechToText.GetCustomWords(HandleGetCustomWords, OnFail, _createdCustomizationID);
            while (!_getCustomWordsTested)
            {
                yield return(null);
            }

            //  Add custom words from path
            Log.Debug("TestSpeechToText.Examples()", "Attempting to add custom words in customization {0} using Words json path {1}", _createdCustomizationID, _customWordsFilePath);
            string customWords = File.ReadAllText(_customWordsFilePath);

            _speechToText.AddCustomWords(HandleAddCustomWordsFromPath, OnFail, _createdCustomizationID, customWords);
            while (!_addCustomWordsFromPathTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Add custom words from object
            Words       words    = new Words();
            Word        w0       = new Word();
            List <Word> wordList = new List <Word>();

            w0.word           = "mikey";
            w0.sounds_like    = new string[1];
            w0.sounds_like[0] = "my key";
            w0.display_as     = "Mikey";
            wordList.Add(w0);
            Word w1 = new Word();

            w1.word           = "charlie";
            w1.sounds_like    = new string[1];
            w1.sounds_like[0] = "char lee";
            w1.display_as     = "Charlie";
            wordList.Add(w1);
            Word w2 = new Word();

            w2.word           = "bijou";
            w2.sounds_like    = new string[1];
            w2.sounds_like[0] = "be joo";
            w2.display_as     = "Bijou";
            wordList.Add(w2);
            words.words = wordList.ToArray();

            Log.Debug("TestSpeechToText.Examples()", "Attempting to add custom words in customization {0} using Words object", _createdCustomizationID);
            _speechToText.AddCustomWords(HandleAddCustomWordsFromObject, OnFail, _createdCustomizationID, words);
            while (!_addCustomWordsFromObjectTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Get custom word
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get custom word {1} in customization {0}", _createdCustomizationID, words.words[0].word);
            _speechToText.GetCustomWord(HandleGetCustomWord, OnFail, _createdCustomizationID, words.words[0].word);
            while (!_getCustomWordTested)
            {
                yield return(null);
            }

            //  Train customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to train customization {0}", _createdCustomizationID);
            _speechToText.TrainCustomization(HandleTrainCustomization, OnFail, _createdCustomizationID);
            while (!_trainCustomizationTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Delete custom word
            Log.Debug("TestSpeechToText.Examples()", "Attempting to delete custom word {1} in customization {0}", _createdCustomizationID, words.words[2].word);
            _speechToText.DeleteCustomWord(HandleDeleteCustomWord, OnFail, _createdCustomizationID, words.words[2].word);
            while (!_deleteCustomWordTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("TestSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete custom corpus
            Log.Debug("TestSpeechToText.Examples()", "Attempting to delete custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            _speechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName);
            while (!_deleteCustomCorpusTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("TestSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Reset customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to reset customization {0}", _createdCustomizationID);
            _speechToText.ResetCustomization(HandleResetCustomization, OnFail, _createdCustomizationID);
            while (!_resetCustomizationTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("TestSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            //  List Grammars
            Log.Debug("TestSpeechToText.Examples()", "Attempting to list grammars {0}", _createdCustomizationID);
            _speechToText.ListGrammars(OnListGrammars, OnFail, _createdCustomizationID);
            while (!_listGrammarsTested)
            {
                yield return(null);
            }

            //  Add Grammar
            Log.Debug("TestSpeechToText.Examples()", "Attempting to add grammar {0}", _createdCustomizationID);
            string grammarFile = File.ReadAllText(_grammarFilePath);

            _speechToText.AddGrammar(OnAddGrammar, OnFail, _createdCustomizationID, _grammarName, grammarFile, _grammarFileContentType);
            while (!_addGrammarTested)
            {
                yield return(null);
            }

            //  Get Grammar
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get grammar {0}", _createdCustomizationID);
            _speechToText.GetGrammar(OnGetGrammar, OnFail, _createdCustomizationID, _grammarName);
            while (!_getGrammarTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Delete Grammar
            Log.Debug("TestSpeechToText.Examples()", "Attempting to delete grammar {0}", _createdCustomizationID);
            _speechToText.DeleteGrammar(OnDeleteGrammar, OnFail, _createdCustomizationID, _grammarName);
            while (!_deleteGrammarTested)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to delete customization {0}", _createdCustomizationID);
            _speechToText.DeleteCustomization(HandleDeleteCustomization, OnFail, _createdCustomizationID);
            while (!_deleteCustomizationsTested)
            {
                yield return(null);
            }

            //  List acoustic customizations
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get acoustic customizations");
            _speechToText.GetCustomAcousticModels(HandleGetCustomAcousticModels, OnFail);
            while (!_getAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Create acoustic customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to create acoustic customization");
            _speechToText.CreateAcousticCustomization(HandleCreateAcousticCustomization, OnFail, _createdAcousticModelName);
            while (!_createAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Get acoustic customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get acoustic customization {0}", _createdAcousticModelId);
            _speechToText.GetCustomAcousticModel(HandleGetCustomAcousticModel, OnFail, _createdAcousticModelId);
            while (!_getAcousticCustomizationTested)
            {
                yield return(null);
            }

            while (!_isAudioLoaded)
            {
                yield return(null);
            }

            //  Create acoustic resource
            Log.Debug("TestSpeechToText.Examples()", "Attempting to create audio resource {1} on {0}", _createdAcousticModelId, _acousticResourceName);
            string mimeType = Utility.GetMimeType(Path.GetExtension(_acousticResourceUrl));

            _speechToText.AddAcousticResource(HandleAddAcousticResource, OnFail, _createdAcousticModelId, _acousticResourceName, mimeType, mimeType, true, _acousticResourceData);
            while (!_addAcousticResourcesTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isAcousticCustomizationReady = false;
            Runnable.Run(CheckAcousticCustomizationStatus(_createdAcousticModelId));
            while (!_isAcousticCustomizationReady)
            {
                yield return(null);
            }

            //  List acoustic resources
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get audio resources {0}", _createdAcousticModelId);
            _speechToText.GetCustomAcousticResources(HandleGetCustomAcousticResources, OnFail, _createdAcousticModelId);
            while (!_getAcousticResourcesTested)
            {
                yield return(null);
            }

            //  Train acoustic customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to train acoustic customization {0}", _createdAcousticModelId);
            _speechToText.TrainAcousticCustomization(HandleTrainAcousticCustomization, OnFail, _createdAcousticModelId, null, true);
            while (!_trainAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Get acoustic resource
            Log.Debug("TestSpeechToText.Examples()", "Attempting to get audio resource {1} from {0}", _createdAcousticModelId, _acousticResourceName);
            _speechToText.GetCustomAcousticResource(HandleGetCustomAcousticResource, OnFail, _createdAcousticModelId, _acousticResourceName);
            while (!_getAcousticResourceTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isAcousticCustomizationReady = false;
            Runnable.Run(CheckAcousticCustomizationStatus(_createdAcousticModelId));
            while (!_isAcousticCustomizationReady)
            {
                yield return(null);
            }

            //  Delete acoustic resource
            DeleteAcousticResource();
            while (!_deleteAcousticResource)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("TestSpeechToText.Examples()", string.Format("Delaying delete acoustic resource for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            //  Reset acoustic customization
            Log.Debug("TestSpeechToText.Examples()", "Attempting to reset acoustic customization {0}", _createdAcousticModelId);
            _speechToText.ResetAcousticCustomization(HandleResetAcousticCustomization, OnFail, _createdAcousticModelId);
            while (!_resetAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("TestSpeechToText.Examples()", string.Format("Delaying delete acoustic customization for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            //  Delete acoustic customization
            DeleteAcousticCustomization();
            while (!_deleteAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("TestSpeechToText.Examples()", string.Format("Delaying complete for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            Log.Debug("TestSpeechToText.RunTest()", "Speech to Text examples complete.");

            yield break;
        }
Exemple #19
0
 void Start()
 {
     m_SpeechToText.Recognize(m_AudioClip, HandleOnRecognize);
 }
Exemple #20
0
        public override IEnumerator RunTest()
        {
            LogSystem.InstallDefaultReactors();

            VcapCredentials vcapCredentials = new VcapCredentials();
            fsData          data            = null;

            string result = null;

            var vcapUrl      = Environment.GetEnvironmentVariable("VCAP_URL");
            var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME");
            var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD");

            using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
            {
                while (!simpleGet.IsComplete)
                {
                    yield return(null);
                }

                result = simpleGet.Result;
            }

            //  Add in a parent object because Unity does not like to deserialize root level collection types.
            result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");

            //  Convert json to fsResult
            fsResult r = fsJsonParser.Parse(result, out data);

            if (!r.Succeeded)
            {
                throw new WatsonException(r.FormattedMessages);
            }

            //  Convert fsResult to VcapCredentials
            object obj = vcapCredentials;

            r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
            if (!r.Succeeded)
            {
                throw new WatsonException(r.FormattedMessages);
            }

            //  Set credentials from imported credntials
            Credential credential = vcapCredentials.VCAP_SERVICES["speech_to_text"];

            _username = credential.Username.ToString();
            _password = credential.Password.ToString();
            _url      = credential.Url.ToString();

            //  Create credential and instantiate service
            Credentials credentials = new Credentials(_username, _password, _url);

            //  Or authenticate using token
            //Credentials credentials = new Credentials(_url)
            //{
            //    AuthenticationToken = _token
            //};

            _speechToText             = new SpeechToText(credentials);
            _customCorpusFilePath     = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/theJabberwocky-utf8.txt";
            _customWordsFilePath      = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-words.json";
            _acousticResourceMimeType = Utility.GetMimeType(Path.GetExtension(_acousticResourceUrl));

            Runnable.Run(DownloadAcousticResource());
            while (!_isAudioLoaded)
            {
                yield return(null);
            }

            //  Recognize
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to recognize");
            List <string> keywords = new List <string>();

            keywords.Add("speech");
            _speechToText.KeywordsThreshold = 0.5f;
            _speechToText.InactivityTimeout = 120;
            _speechToText.StreamMultipart   = false;
            _speechToText.Keywords          = keywords.ToArray();
            _speechToText.Recognize(HandleOnRecognize, OnFail, _acousticResourceData, _acousticResourceMimeType);
            while (!_recognizeTested)
            {
                yield return(null);
            }

            //  Get models
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get models");
            _speechToText.GetModels(HandleGetModels, OnFail);
            while (!_getModelsTested)
            {
                yield return(null);
            }

            //  Get model
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get model {0}", _modelNameToGet);
            _speechToText.GetModel(HandleGetModel, OnFail, _modelNameToGet);
            while (!_getModelTested)
            {
                yield return(null);
            }

            //  Get customizations
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get customizations");
            _speechToText.GetCustomizations(HandleGetCustomizations, OnFail);
            while (!_getCustomizationsTested)
            {
                yield return(null);
            }

            //  Create customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting create customization");
            _speechToText.CreateCustomization(HandleCreateCustomization, OnFail, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity");
            while (!_createCustomizationsTested)
            {
                yield return(null);
            }

            //  Get customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get customization {0}", _createdCustomizationID);
            _speechToText.GetCustomization(HandleGetCustomization, OnFail, _createdCustomizationID);
            while (!_getCustomizationTested)
            {
                yield return(null);
            }

            //  Get custom corpora
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom corpora for {0}", _createdCustomizationID);
            _speechToText.GetCustomCorpora(HandleGetCustomCorpora, OnFail, _createdCustomizationID);
            while (!_getCustomCorporaTested)
            {
                yield return(null);
            }

            //  Add custom corpus
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to add custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            string corpusData = File.ReadAllText(_customCorpusFilePath);

            _speechToText.AddCustomCorpus(HandleAddCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName, true, corpusData);
            while (!_addCustomCorpusTested)
            {
                yield return(null);
            }

            //  Get custom corpus
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            _speechToText.GetCustomCorpus(HandleGetCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName);
            while (!_getCustomCorpusTested)
            {
                yield return(null);
            }

            //  Wait for customization
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Get custom words
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom words.");
            _speechToText.GetCustomWords(HandleGetCustomWords, OnFail, _createdCustomizationID);
            while (!_getCustomWordsTested)
            {
                yield return(null);
            }

            //  Add custom words from path
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to add custom words in customization {0} using Words json path {1}", _createdCustomizationID, _customWordsFilePath);
            string customWords = File.ReadAllText(_customWordsFilePath);

            _speechToText.AddCustomWords(HandleAddCustomWordsFromPath, OnFail, _createdCustomizationID, customWords);
            while (!_addCustomWordsFromPathTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Add custom words from object
            Words       words    = new Words();
            Word        w0       = new Word();
            List <Word> wordList = new List <Word>();

            w0.word           = "mikey";
            w0.sounds_like    = new string[1];
            w0.sounds_like[0] = "my key";
            w0.display_as     = "Mikey";
            wordList.Add(w0);
            Word w1 = new Word();

            w1.word           = "charlie";
            w1.sounds_like    = new string[1];
            w1.sounds_like[0] = "char lee";
            w1.display_as     = "Charlie";
            wordList.Add(w1);
            Word w2 = new Word();

            w2.word           = "bijou";
            w2.sounds_like    = new string[1];
            w2.sounds_like[0] = "be joo";
            w2.display_as     = "Bijou";
            wordList.Add(w2);
            words.words = wordList.ToArray();

            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to add custom words in customization {0} using Words object", _createdCustomizationID);
            _speechToText.AddCustomWords(HandleAddCustomWordsFromObject, OnFail, _createdCustomizationID, words);
            while (!_addCustomWordsFromObjectTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Get custom word
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom word {1} in customization {0}", _createdCustomizationID, words.words[0].word);
            _speechToText.GetCustomWord(HandleGetCustomWord, OnFail, _createdCustomizationID, words.words[0].word);
            while (!_getCustomWordTested)
            {
                yield return(null);
            }

            //  Train customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to train customization {0}", _createdCustomizationID);
            _speechToText.TrainCustomization(HandleTrainCustomization, OnFail, _createdCustomizationID);
            while (!_trainCustomizationTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Upgrade customization - not currently implemented in service
            //Log.Debug("ExampleSpeechToText.Examples()", "Attempting to upgrade customization {0}", _createdCustomizationID);
            //_speechToText.UpgradeCustomization(HandleUpgradeCustomization, _createdCustomizationID);
            //while (!_upgradeCustomizationTested)
            //    yield return null;

            //  Delete custom word
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to delete custom word {1} in customization {0}", _createdCustomizationID, words.words[2].word);
            _speechToText.DeleteCustomWord(HandleDeleteCustomWord, OnFail, _createdCustomizationID, words.words[2].word);
            while (!_deleteCustomWordTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete custom corpus
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to delete custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            _speechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName);
            while (!_deleteCustomCorpusTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Reset customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to reset customization {0}", _createdCustomizationID);
            _speechToText.ResetCustomization(HandleResetCustomization, OnFail, _createdCustomizationID);
            while (!_resetCustomizationTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to delete customization {0}", _createdCustomizationID);
            _speechToText.DeleteCustomization(HandleDeleteCustomization, OnFail, _createdCustomizationID);
            while (!_deleteCustomizationsTested)
            {
                yield return(null);
            }

            //  List acoustic customizations
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get acoustic customizations");
            _speechToText.GetCustomAcousticModels(HandleGetCustomAcousticModels, OnFail);
            while (!_getAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Create acoustic customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to create acoustic customization");
            _speechToText.CreateAcousticCustomization(HandleCreateAcousticCustomization, OnFail, _createdAcousticModelName);
            while (!_createAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Get acoustic customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get acoustic customization {0}", _createdAcousticModelId);
            _speechToText.GetCustomAcousticModel(HandleGetCustomAcousticModel, OnFail, _createdAcousticModelId);
            while (!_getAcousticCustomizationTested)
            {
                yield return(null);
            }

            while (!_isAudioLoaded)
            {
                yield return(null);
            }

            //  Create acoustic resource
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to create audio resource {1} on {0}", _createdAcousticModelId, _acousticResourceName);
            string mimeType = Utility.GetMimeType(Path.GetExtension(_acousticResourceUrl));

            _speechToText.AddAcousticResource(HandleAddAcousticResource, OnFail, _createdAcousticModelId, _acousticResourceName, mimeType, mimeType, true, _acousticResourceData);
            while (!_addAcousticResourcesTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isAcousticCustomizationReady = false;
            Runnable.Run(CheckAcousticCustomizationStatus(_createdAcousticModelId));
            while (!_isAcousticCustomizationReady)
            {
                yield return(null);
            }

            //  List acoustic resources
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get audio resources {0}", _createdAcousticModelId);
            _speechToText.GetCustomAcousticResources(HandleGetCustomAcousticResources, OnFail, _createdAcousticModelId);
            while (!_getAcousticResourcesTested)
            {
                yield return(null);
            }

            //  Train acoustic customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to train acoustic customization {0}", _createdAcousticModelId);
            _speechToText.TrainAcousticCustomization(HandleTrainAcousticCustomization, OnFail, _createdAcousticModelId, null, true);
            while (!_trainAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Get acoustic resource
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get audio resource {1} from {0}", _createdAcousticModelId, _acousticResourceName);
            _speechToText.GetCustomAcousticResource(HandleGetCustomAcousticResource, OnFail, _createdAcousticModelId, _acousticResourceName);
            while (!_getAcousticResourceTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isAcousticCustomizationReady = false;
            Runnable.Run(CheckAcousticCustomizationStatus(_createdAcousticModelId));
            while (!_isAcousticCustomizationReady)
            {
                yield return(null);
            }

            //  Delete acoustic resource
            DeleteAcousticResource();
            while (!_deleteAcousticResource)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete acoustic resource for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            //  Reset acoustic customization
            Log.Debug("ExampleSpeechToText.Examples()", "Attempting to reset acoustic customization {0}", _createdAcousticModelId);
            _speechToText.ResetAcousticCustomization(HandleResetAcousticCustomization, OnFail, _createdAcousticModelId);
            while (!_resetAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete acoustic customization for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            //  Delete acoustic customization
            DeleteAcousticCustomization();
            while (!_deleteAcousticCustomizationsTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying complete for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            Log.Debug("TestSpeechToText.RunTest()", "Speech to Text examples complete.");

            yield break;
        }
Exemple #21
0
 public void onUp()
 {
     playStatic();
     m_SpeechToText.Recognize(m_AudioClip, HandleOnRecognize);
 }
    private IEnumerator Examples()
    {
        Runnable.Run(DownloadAcousticResource());
        while (!_isAudioLoaded)
        {
            yield return(null);
        }

        Runnable.Run(DownloadOggResource());
        while (!_isOggLoaded)
        {
            yield return(null);
        }

        //  Recognize
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to recognize");
        List <string> keywords = new List <string>();

        keywords.Add("speech");
        _speechToText.KeywordsThreshold = 0.5f;
        _speechToText.InactivityTimeout = 120;
        _speechToText.StreamMultipart   = false;
        _speechToText.Keywords          = keywords.ToArray();
        _speechToText.Recognize(HandleOnRecognize, OnFail, _acousticResourceData, _acousticResourceMimeType);
        while (!_recognizeTested)
        {
            yield return(null);
        }

        //  Recognize ogg
        Log.Debug("ExampleSpeechToText", "Attempting to recognize ogg: mimeType: {0} | _speechTText.StreamMultipart: {1}", _oggResourceMimeType, _speechToText.StreamMultipart);
        _speechToText.Recognize(HandleOnRecognizeOgg, OnFail, _oggResourceData, _oggResourceMimeType + ";codecs=vorbis");
        while (!_recognizeOggTested)
        {
            yield return(null);
        }

        //  Get models
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get models");
        _speechToText.GetModels(HandleGetModels, OnFail);
        while (!_getModelsTested)
        {
            yield return(null);
        }

        //  Get model
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get model {0}", _modelNameToGet);
        _speechToText.GetModel(HandleGetModel, OnFail, _modelNameToGet);
        while (!_getModelTested)
        {
            yield return(null);
        }

        //  Get customizations
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get customizations");
        _speechToText.GetCustomizations(HandleGetCustomizations, OnFail);
        while (!_getCustomizationsTested)
        {
            yield return(null);
        }

        //  Create customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting create customization");
        _speechToText.CreateCustomization(HandleCreateCustomization, OnFail, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity");
        while (!_createCustomizationsTested)
        {
            yield return(null);
        }

        //  Get customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get customization {0}", _createdCustomizationID);
        _speechToText.GetCustomization(HandleGetCustomization, OnFail, _createdCustomizationID);
        while (!_getCustomizationTested)
        {
            yield return(null);
        }

        //  Get custom corpora
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom corpora for {0}", _createdCustomizationID);
        _speechToText.GetCustomCorpora(HandleGetCustomCorpora, OnFail, _createdCustomizationID);
        while (!_getCustomCorporaTested)
        {
            yield return(null);
        }

        //  Add custom corpus
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to add custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
        string corpusData = File.ReadAllText(_customCorpusFilePath);

        _speechToText.AddCustomCorpus(HandleAddCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName, true, corpusData);
        while (!_addCustomCorpusTested)
        {
            yield return(null);
        }

        //  Get custom corpus
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
        _speechToText.GetCustomCorpus(HandleGetCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName);
        while (!_getCustomCorpusTested)
        {
            yield return(null);
        }

        //  Wait for customization
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Get custom words
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom words.");
        _speechToText.GetCustomWords(HandleGetCustomWords, OnFail, _createdCustomizationID);
        while (!_getCustomWordsTested)
        {
            yield return(null);
        }

        //  Add custom words from path
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to add custom words in customization {0} using Words json path {1}", _createdCustomizationID, _customWordsFilePath);
        string customWords = File.ReadAllText(_customWordsFilePath);

        _speechToText.AddCustomWords(HandleAddCustomWordsFromPath, OnFail, _createdCustomizationID, customWords);
        while (!_addCustomWordsFromPathTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isCustomizationReady = false;
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Add custom words from object
        Words       words    = new Words();
        Word        w0       = new Word();
        List <Word> wordList = new List <Word>();

        w0.word           = "mikey";
        w0.sounds_like    = new string[1];
        w0.sounds_like[0] = "my key";
        w0.display_as     = "Mikey";
        wordList.Add(w0);
        Word w1 = new Word();

        w1.word           = "charlie";
        w1.sounds_like    = new string[1];
        w1.sounds_like[0] = "char lee";
        w1.display_as     = "Charlie";
        wordList.Add(w1);
        Word w2 = new Word();

        w2.word           = "bijou";
        w2.sounds_like    = new string[1];
        w2.sounds_like[0] = "be joo";
        w2.display_as     = "Bijou";
        wordList.Add(w2);
        words.words = wordList.ToArray();

        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to add custom words in customization {0} using Words object", _createdCustomizationID);
        _speechToText.AddCustomWords(HandleAddCustomWordsFromObject, OnFail, _createdCustomizationID, words);
        while (!_addCustomWordsFromObjectTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isCustomizationReady = false;
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Get custom word
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get custom word {1} in customization {0}", _createdCustomizationID, words.words[0].word);
        _speechToText.GetCustomWord(HandleGetCustomWord, OnFail, _createdCustomizationID, words.words[0].word);
        while (!_getCustomWordTested)
        {
            yield return(null);
        }

        //  Train customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to train customization {0}", _createdCustomizationID);
        _speechToText.TrainCustomization(HandleTrainCustomization, OnFail, _createdCustomizationID);
        while (!_trainCustomizationTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isCustomizationReady = false;
        Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
        while (!_isCustomizationReady)
        {
            yield return(null);
        }

        //  Upgrade customization - not currently implemented in service
        //Log.Debug("ExampleSpeechToText.Examples()", "Attempting to upgrade customization {0}", _createdCustomizationID);
        //_speechToText.UpgradeCustomization(HandleUpgradeCustomization, _createdCustomizationID);
        //while (!_upgradeCustomizationTested)
        //    yield return null;

        //  Delete custom word
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to delete custom word {1} in customization {0}", _createdCustomizationID, words.words[2].word);
        _speechToText.DeleteCustomWord(HandleDeleteCustomWord, OnFail, _createdCustomizationID, words.words[2].word);
        while (!_deleteCustomWordTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete custom corpus
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to delete custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
        _speechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, OnFail, _createdCustomizationID, _createdCorpusName);
        while (!_deleteCustomCorpusTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Reset customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to reset customization {0}", _createdCustomizationID);
        _speechToText.ResetCustomization(HandleResetCustomization, OnFail, _createdCustomizationID);
        while (!_resetCustomizationTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to delete customization {0}", _createdCustomizationID);
        _speechToText.DeleteCustomization(HandleDeleteCustomization, OnFail, _createdCustomizationID);
        while (!_deleteCustomizationsTested)
        {
            yield return(null);
        }

        //  List acoustic customizations
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get acoustic customizations");
        _speechToText.GetCustomAcousticModels(HandleGetCustomAcousticModels, OnFail);
        while (!_getAcousticCustomizationsTested)
        {
            yield return(null);
        }

        //  Create acoustic customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to create acoustic customization");
        _speechToText.CreateAcousticCustomization(HandleCreateAcousticCustomization, OnFail, _createdAcousticModelName);
        while (!_createAcousticCustomizationsTested)
        {
            yield return(null);
        }

        //  Get acoustic customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get acoustic customization {0}", _createdAcousticModelId);
        _speechToText.GetCustomAcousticModel(HandleGetCustomAcousticModel, OnFail, _createdAcousticModelId);
        while (!_getAcousticCustomizationTested)
        {
            yield return(null);
        }

        while (!_isAudioLoaded)
        {
            yield return(null);
        }

        //  Create acoustic resource
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to create audio resource {1} on {0}", _createdAcousticModelId, _acousticResourceName);
        string mimeType = Utility.GetMimeType(Path.GetExtension(_acousticResourceUrl));

        _speechToText.AddAcousticResource(HandleAddAcousticResource, OnFail, _createdAcousticModelId, _acousticResourceName, mimeType, mimeType, true, _acousticResourceData);
        while (!_addAcousticResourcesTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isAcousticCustomizationReady = false;
        Runnable.Run(CheckAcousticCustomizationStatus(_createdAcousticModelId));
        while (!_isAcousticCustomizationReady)
        {
            yield return(null);
        }

        //  List acoustic resources
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get audio resources {0}", _createdAcousticModelId);
        _speechToText.GetCustomAcousticResources(HandleGetCustomAcousticResources, OnFail, _createdAcousticModelId);
        while (!_getAcousticResourcesTested)
        {
            yield return(null);
        }

        //  Train acoustic customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to train acoustic customization {0}", _createdAcousticModelId);
        _speechToText.TrainAcousticCustomization(HandleTrainAcousticCustomization, OnFail, _createdAcousticModelId, null, true);
        while (!_trainAcousticCustomizationsTested)
        {
            yield return(null);
        }

        //  Get acoustic resource
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to get audio resource {1} from {0}", _createdAcousticModelId, _acousticResourceName);
        _speechToText.GetCustomAcousticResource(HandleGetCustomAcousticResource, OnFail, _createdAcousticModelId, _acousticResourceName);
        while (!_getAcousticResourceTested)
        {
            yield return(null);
        }

        //  Wait for customization
        _isAcousticCustomizationReady = false;
        Runnable.Run(CheckAcousticCustomizationStatus(_createdAcousticModelId));
        while (!_isAcousticCustomizationReady)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete acoustic resource for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        //  Delete acoustic resource
        DeleteAcousticResource();
        while (!_deleteAcousticResource)
        {
            yield return(null);
        }

        //  Reset acoustic customization
        Log.Debug("ExampleSpeechToText.Examples()", "Attempting to reset acoustic customization {0}", _createdAcousticModelId);
        _speechToText.ResetAcousticCustomization(HandleResetAcousticCustomization, OnFail, _createdAcousticModelId);
        while (!_resetAcousticCustomizationsTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying delete acoustic customization for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        //  Delete acoustic customization
        DeleteAcousticCustomization();
        while (!_deleteAcousticCustomizationsTested)
        {
            yield return(null);
        }

        //  Delay
        Log.Debug("ExampleSpeechToText.Examples()", string.Format("Delaying complete for {0} sec", _delayTimeInSeconds));
        Runnable.Run(Delay(_delayTimeInSeconds));
        while (!_readyToContinue)
        {
            yield return(null);
        }

        Log.Debug("ExampleSpeechToText.Examples()", "Speech to Text examples complete.");
    }
        public override IEnumerator RunTest()
        {
            LogSystem.InstallDefaultReactors();

            try
            {
                VcapCredentials vcapCredentials = new VcapCredentials();
                fsData          data            = null;

                //  Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
                //  See https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html.
                var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
                var fileContent           = File.ReadAllText(environmentalVariable);

                //  Add in a parent object because Unity does not like to deserialize root level collection types.
                fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");

                //  Convert json to fsResult
                fsResult r = fsJsonParser.Parse(fileContent, out data);
                if (!r.Succeeded)
                {
                    throw new WatsonException(r.FormattedMessages);
                }

                //  Convert fsResult to VcapCredentials
                object obj = vcapCredentials;
                r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
                if (!r.Succeeded)
                {
                    throw new WatsonException(r.FormattedMessages);
                }

                //  Set credentials from imported credntials
                Credential credential = vcapCredentials.VCAP_SERVICES["speech_to_text"][TestCredentialIndex].Credentials;
                _username = credential.Username.ToString();
                _password = credential.Password.ToString();
                _url      = credential.Url.ToString();
            }
            catch
            {
                Log.Debug("TestSpeechToText", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication");
            }

            //  Create credential and instantiate service
            Credentials credentials = new Credentials(_username, _password, _url);

            //  Or authenticate using token
            //Credentials credentials = new Credentials(_url)
            //{
            //    AuthenticationToken = _token
            //};

            _speechToText         = new SpeechToText(credentials);
            _customCorpusFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-corpus.txt";
            _customWordsFilePath  = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-words.json";
            _wavFilePath          = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-audio.wav";
            _audioClip            = WaveFile.ParseWAV("testClip", File.ReadAllBytes(_wavFilePath));

            Log.Debug("ExampleSpeechToText", "Attempting to recognize");
            _speechToText.Recognize(_audioClip, HandleOnRecognize);
            while (!_recognizeTested)
            {
                yield return(null);
            }

            //  Get models
            Log.Debug("ExampleSpeechToText", "Attempting to get models");
            _speechToText.GetModels(HandleGetModels);
            while (!_getModelsTested)
            {
                yield return(null);
            }

            //  Get model
            Log.Debug("ExampleSpeechToText", "Attempting to get model {0}", _modelNameToGet);
            _speechToText.GetModel(HandleGetModel, _modelNameToGet);
            while (!_getModelTested)
            {
                yield return(null);
            }

            //  Get customizations
            Log.Debug("ExampleSpeechToText", "Attempting to get customizations");
            _speechToText.GetCustomizations(HandleGetCustomizations);
            while (!_getCustomizationsTested)
            {
                yield return(null);
            }

            //  Create customization
            Log.Debug("ExampleSpeechToText", "Attempting create customization");
            _speechToText.CreateCustomization(HandleCreateCustomization, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity");
            while (!_createCustomizationsTested)
            {
                yield return(null);
            }

            //  Get customization
            Log.Debug("ExampleSpeechToText", "Attempting to get customization {0}", _createdCustomizationID);
            _speechToText.GetCustomization(HandleGetCustomization, _createdCustomizationID);
            while (!_getCustomizationTested)
            {
                yield return(null);
            }

            //  Get custom corpora
            Log.Debug("ExampleSpeechToText", "Attempting to get custom corpora for {0}", _createdCustomizationID);
            _speechToText.GetCustomCorpora(HandleGetCustomCorpora, _createdCustomizationID);
            while (!_getCustomCorporaTested)
            {
                yield return(null);
            }

            //  Add custom corpus
            Log.Debug("ExampleSpeechToText", "Attempting to add custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            _speechToText.AddCustomCorpus(HandleAddCustomCorpus, _createdCustomizationID, _createdCorpusName, true, _customCorpusFilePath);
            while (!_addCustomCorpusTested)
            {
                yield return(null);
            }

            //  Get custom corpus
            Log.Debug("ExampleSpeechToText", "Attempting to get custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            _speechToText.GetCustomCorpus(HandleGetCustomCorpus, _createdCustomizationID, _createdCorpusName);
            while (!_getCustomCorpusTested)
            {
                yield return(null);
            }

            //  Wait for customization
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Get custom words
            Log.Debug("ExampleSpeechToText", "Attempting to get custom words.");
            _speechToText.GetCustomWords(HandleGetCustomWords, _createdCustomizationID);
            while (!_getCustomWordsTested)
            {
                yield return(null);
            }

            //  Add custom words from path
            Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words json path {1}", _createdCustomizationID, _customWordsFilePath);
            string customWords = File.ReadAllText(_customWordsFilePath);

            _speechToText.AddCustomWords(HandleAddCustomWordsFromPath, _createdCustomizationID, customWords);
            while (!_addCustomWordsFromPathTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Add custom words from object
            Words       words    = new Words();
            Word        w0       = new Word();
            List <Word> wordList = new List <Word>();

            w0.word           = "mikey";
            w0.sounds_like    = new string[1];
            w0.sounds_like[0] = "my key";
            w0.display_as     = "Mikey";
            wordList.Add(w0);
            Word w1 = new Word();

            w1.word           = "charlie";
            w1.sounds_like    = new string[1];
            w1.sounds_like[0] = "char lee";
            w1.display_as     = "Charlie";
            wordList.Add(w1);
            Word w2 = new Word();

            w2.word           = "bijou";
            w2.sounds_like    = new string[1];
            w2.sounds_like[0] = "be joo";
            w2.display_as     = "Bijou";
            wordList.Add(w2);
            words.words = wordList.ToArray();

            Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words object", _createdCustomizationID);
            _speechToText.AddCustomWords(HandleAddCustomWordsFromObject, _createdCustomizationID, words);
            while (!_addCustomWordsFromObjectTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Get custom word
            Log.Debug("ExampleSpeechToText", "Attempting to get custom word {1} in customization {0}", _createdCustomizationID, words.words[0].word);
            _speechToText.GetCustomWord(HandleGetCustomWord, _createdCustomizationID, words.words[0].word);
            while (!_getCustomWordTested)
            {
                yield return(null);
            }

            //  Train customization
            Log.Debug("ExampleSpeechToText", "Attempting to train customization {0}", _createdCustomizationID);
            _speechToText.TrainCustomization(HandleTrainCustomization, _createdCustomizationID);
            while (!_trainCustomizationTested)
            {
                yield return(null);
            }

            //  Wait for customization
            _isCustomizationReady = false;
            Runnable.Run(CheckCustomizationStatus(_createdCustomizationID));
            while (!_isCustomizationReady)
            {
                yield return(null);
            }

            //  Upgrade customization - not currently implemented in service
            //Log.Debug("ExampleSpeechToText", "Attempting to upgrade customization {0}", _createdCustomizationID);
            //_speechToText.UpgradeCustomization(HandleUpgradeCustomization, _createdCustomizationID);
            //while (!_upgradeCustomizationTested)
            //    yield return null;

            //  Delete custom word
            Log.Debug("ExampleSpeechToText", "Attempting to delete custom word {1} in customization {0}", _createdCustomizationID, words.words[2].word);
            _speechToText.DeleteCustomWord(HandleDeleteCustomWord, _createdCustomizationID, words.words[2].word);
            while (!_deleteCustomWordTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleDiscovery", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete custom corpus
            Log.Debug("ExampleSpeechToText", "Attempting to delete custom corpus {1} in customization {0}", _createdCustomizationID, _createdCorpusName);
            _speechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, _createdCustomizationID, _createdCorpusName);
            while (!_deleteCustomCorpusTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleDiscovery", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Reset customization
            Log.Debug("ExampleSpeechToText", "Attempting to reset customization {0}", _createdCustomizationID);
            _speechToText.ResetCustomization(HandleResetCustomization, _createdCustomizationID);
            while (!_resetCustomizationTested)
            {
                yield return(null);
            }

            //  Delay
            Log.Debug("ExampleDiscovery", string.Format("Delaying delete environment for {0} sec", _delayTimeInSeconds));
            Runnable.Run(Delay(_delayTimeInSeconds));
            while (!_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete customization
            Log.Debug("ExampleSpeechToText", "Attempting to delete customization {0}", _createdCustomizationID);
            _speechToText.DeleteCustomization(HandleDeleteCustomization, _createdCustomizationID);
            while (!_deleteCustomizationsTested)
            {
                yield return(null);
            }

            Log.Debug("ExampleSpeechToText", "Speech to Text examples complete.");

            yield break;
        }