Example #1
0
 public IEnumerator GetCustomizations()
 {
     Log.Debug("ScriptReader", "Attempting to get a list of customizations");
     _textToSpeech.GetCustomizations(OnGetCustomizations);
     while (!_getCustomizationsTested)
     {
         yield return(null);
     }
 }
    private IEnumerator Examples()
    {
        //  Synthesize
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting synthesize.");
        _textToSpeech.Voice = VoiceType.en_US_Allison;
        _textToSpeech.ToSpeech(HandleToSpeechCallback, OnFail, _testString, true);
        while (!_synthesizeTested)
        {
            yield return(null);
        }

        //	Get Voices
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get voices.");
        _textToSpeech.GetVoices(OnGetVoices, OnFail);
        while (!_getVoicesTested)
        {
            yield return(null);
        }

        //	Get Voice
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get voice {0}.", VoiceType.en_US_Allison);
        _textToSpeech.GetVoice(OnGetVoice, OnFail, VoiceType.en_US_Allison);
        while (!_getVoiceTested)
        {
            yield return(null);
        }

        //	Get Pronunciation
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get pronunciation of {0}", _testWord);
        _textToSpeech.GetPronunciation(OnGetPronunciation, OnFail, _testWord, VoiceType.en_US_Allison);
        while (!_getPronuciationTested)
        {
            yield return(null);
        }

        //  Get Customizations
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get a list of customizations");
        _textToSpeech.GetCustomizations(OnGetCustomizations, OnFail);
        while (!_getCustomizationsTested)
        {
            yield return(null);
        }

        //  Create Customization
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to create a customization");
        _textToSpeech.CreateCustomization(OnCreateCustomization, OnFail, _customizationName, _customizationLanguage, _customizationDescription);
        while (!_createCustomizationTested)
        {
            yield return(null);
        }

        //  Get Customization
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get a customization");
        if (!_textToSpeech.GetCustomization(OnGetCustomization, OnFail, _createdCustomizationId))
        {
            Log.Debug("ExampleTextToSpeech.Examples()", "Failed to get custom voice model!");
        }
        while (!_getCustomizationTested)
        {
            yield return(null);
        }

        //  Update Customization
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to update a customization");
        Word[] wordsToUpdateCustomization =
        {
            new Word()
            {
                word        = "hello",
                translation = "hullo"
            },
            new Word()
            {
                word        = "goodbye",
                translation = "gbye"
            },
            new Word()
            {
                word        = "hi",
                translation = "ohioooo"
            }
        };

        _customVoiceUpdate = new CustomVoiceUpdate()
        {
            words       = wordsToUpdateCustomization,
            description = "My updated description",
            name        = "My updated name"
        };

        if (!_textToSpeech.UpdateCustomization(OnUpdateCustomization, OnFail, _createdCustomizationId, _customVoiceUpdate))
        {
            Log.Debug("ExampleTextToSpeech.Examples()", "Failed to update customization!");
        }
        while (!_updateCustomizationTested)
        {
            yield return(null);
        }

        //  Get Customization Words
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get a customization's words");
        if (!_textToSpeech.GetCustomizationWords(OnGetCustomizationWords, OnFail, _createdCustomizationId))
        {
            Log.Debug("ExampleTextToSpeech.GetCustomizationWords()", "Failed to get {0} words!", _createdCustomizationId);
        }
        while (!_getCustomizationWordsTested)
        {
            yield return(null);
        }

        //  Add Customization Words
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to add words to a customization");
        Word[] wordArrayToAddToCustomization =
        {
            new Word()
            {
                word        = "bananna",
                translation = "arange"
            },
            new Word()
            {
                word        = "orange",
                translation = "gbye"
            },
            new Word()
            {
                word        = "tomato",
                translation = "tomahto"
            }
        };

        Words wordsToAddToCustomization = new Words()
        {
            words = wordArrayToAddToCustomization
        };

        if (!_textToSpeech.AddCustomizationWords(OnAddCustomizationWords, OnFail, _createdCustomizationId, wordsToAddToCustomization))
        {
            Log.Debug("ExampleTextToSpeech.AddCustomizationWords()", "Failed to add words to {0}!", _createdCustomizationId);
        }
        while (!_addCustomizationWordsTested)
        {
            yield return(null);
        }

        //  Get Customization Word
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to get the translation of a custom voice model's word.");
        string customIdentifierWord = wordsToUpdateCustomization[0].word;

        if (!_textToSpeech.GetCustomizationWord(OnGetCustomizationWord, OnFail, _createdCustomizationId, customIdentifierWord))
        {
            Log.Debug("ExampleTextToSpeech.GetCustomizationWord()", "Failed to get the translation of {0} from {1}!", customIdentifierWord, _createdCustomizationId);
        }
        while (!_getCustomizationWordTested)
        {
            yield return(null);
        }

        //  Delete Customization Word
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to delete customization word from custom voice model.");
        string wordToDelete = "goodbye";

        if (!_textToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, OnFail, _createdCustomizationId, wordToDelete))
        {
            Log.Debug("ExampleTextToSpeech.DeleteCustomizationWord()", "Failed to delete {0} from {1}!", wordToDelete, _createdCustomizationId);
        }
        while (!_deleteCustomizationWordTested)
        {
            yield return(null);
        }

        //  Delete Customization
        Log.Debug("ExampleTextToSpeech.Examples()", "Attempting to delete a customization");
        if (!_textToSpeech.DeleteCustomization(OnDeleteCustomization, OnFail, _createdCustomizationId))
        {
            Log.Debug("ExampleTextToSpeech.DeleteCustomization()", "Failed to delete custom voice model!");
        }
        while (!_deleteCustomizationTested)
        {
            yield return(null);
        }

        Log.Debug("ExampleTextToSpeech.Examples()", "Text to Speech examples complete.");
    }
Example #3
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["text_to_speech"];

            _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
            //};

            _textToSpeech = new TextToSpeech(credentials);

            //  Synthesize
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting synthesize.");
            _textToSpeech.Voice = VoiceType.en_US_Allison;
            _textToSpeech.ToSpeech(HandleToSpeechCallback, OnFail, _testString, true);
            while (!_synthesizeTested)
            {
                yield return(null);
            }

            //  Synthesize Conversation string
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting synthesize a string as returned by Watson Conversation.");
            _textToSpeech.Voice = VoiceType.en_US_Allison;
            _textToSpeech.ToSpeech(HandleConversationToSpeechCallback, OnFail, _testConversationString, true);
            while (!_synthesizeConversationTested)
            {
                yield return(null);
            }

            //	Get Voices
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get voices.");
            _textToSpeech.GetVoices(OnGetVoices, OnFail);
            while (!_getVoicesTested)
            {
                yield return(null);
            }

            //	Get Voice
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get voice {0}.", VoiceType.en_US_Allison);
            _textToSpeech.GetVoice(OnGetVoice, OnFail, VoiceType.en_US_Allison);
            while (!_getVoiceTested)
            {
                yield return(null);
            }

            //	Get Pronunciation
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get pronunciation of {0}", _testWord);
            _textToSpeech.GetPronunciation(OnGetPronunciation, OnFail, _testWord, VoiceType.en_US_Allison);
            while (!_getPronuciationTested)
            {
                yield return(null);
            }

            //  Get Customizations
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get a list of customizations");
            _textToSpeech.GetCustomizations(OnGetCustomizations, OnFail);
            while (!_getCustomizationsTested)
            {
                yield return(null);
            }

            //  Create Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to create a customization");
            _textToSpeech.CreateCustomization(OnCreateCustomization, OnFail, _customizationName, _customizationLanguage, _customizationDescription);
            while (!_createCustomizationTested)
            {
                yield return(null);
            }

            //  Get Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get a customization");
            if (!_textToSpeech.GetCustomization(OnGetCustomization, OnFail, _createdCustomizationId))
            {
                Log.Debug("TestTextToSpeech.RunTest()", "Failed to get custom voice model!");
            }
            while (!_getCustomizationTested)
            {
                yield return(null);
            }

            //  Update Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to update a customization");
            Word[] wordsToUpdateCustomization =
            {
                new Word()
                {
                    word        = "hello",
                    translation = "hullo"
                },
                new Word()
                {
                    word        = "goodbye",
                    translation = "gbye"
                },
                new Word()
                {
                    word        = "hi",
                    translation = "ohioooo"
                }
            };

            _customVoiceUpdate = new CustomVoiceUpdate()
            {
                words       = wordsToUpdateCustomization,
                description = "My updated description",
                name        = "My updated name"
            };

            if (!_textToSpeech.UpdateCustomization(OnUpdateCustomization, OnFail, _createdCustomizationId, _customVoiceUpdate))
            {
                Log.Debug("TestTextToSpeech.UpdateCustomization()", "Failed to update customization!");
            }
            while (!_updateCustomizationTested)
            {
                yield return(null);
            }

            //  Get Customization Words
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get a customization's words");
            if (!_textToSpeech.GetCustomizationWords(OnGetCustomizationWords, OnFail, _createdCustomizationId))
            {
                Log.Debug("TestTextToSpeech.GetCustomizationWords()", "Failed to get {0} words!", _createdCustomizationId);
            }
            while (!_getCustomizationWordsTested)
            {
                yield return(null);
            }

            //  Add Customization Words
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to add words to a customization");
            Word[] wordArrayToAddToCustomization =
            {
                new Word()
                {
                    word        = "bananna",
                    translation = "arange"
                },
                new Word()
                {
                    word        = "orange",
                    translation = "gbye"
                },
                new Word()
                {
                    word        = "tomato",
                    translation = "tomahto"
                }
            };

            Words wordsToAddToCustomization = new Words()
            {
                words = wordArrayToAddToCustomization
            };

            if (!_textToSpeech.AddCustomizationWords(OnAddCustomizationWords, OnFail, _createdCustomizationId, wordsToAddToCustomization))
            {
                Log.Debug("TestTextToSpeech.AddCustomizationWords()", "Failed to add words to {0}!", _createdCustomizationId);
            }
            while (!_addCustomizationWordsTested)
            {
                yield return(null);
            }

            //  Get Customization Word
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get the translation of a custom voice model's word.");
            string customIdentifierWord = wordsToUpdateCustomization[0].word;

            if (!_textToSpeech.GetCustomizationWord(OnGetCustomizationWord, OnFail, _createdCustomizationId, customIdentifierWord))
            {
                Log.Debug("TestTextToSpeech.GetCustomizationWord()", "Failed to get the translation of {0} from {1}!", customIdentifierWord, _createdCustomizationId);
            }
            while (!_getCustomizationWordTested)
            {
                yield return(null);
            }

            //  Delete Customization Word
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to delete customization word from custom voice model.");
            string wordToDelete = "goodbye";

            if (!_textToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, OnFail, _createdCustomizationId, wordToDelete))
            {
                Log.Debug("TestTextToSpeech.DeleteCustomizationWord()", "Failed to delete {0} from {1}!", wordToDelete, _createdCustomizationId);
            }
            while (!_deleteCustomizationWordTested)
            {
                yield return(null);
            }

            //  Delete Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to delete a customization");
            if (!_textToSpeech.DeleteCustomization(OnDeleteCustomization, OnFail, _createdCustomizationId))
            {
                Log.Debug("TestTextToSpeech.DeleteCustomization()", "Failed to delete custom voice model!");
            }
            while (!_deleteCustomizationTested)
            {
                yield return(null);
            }

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

            yield break;
        }
        public override IEnumerator RunTest()
        {
            m_CustomizationIDToTest         = Config.Instance.GetVariableValue("TextToSpeech_IntegrationTestCustomVoiceModel");
            m_UpdateWordObject0.word        = m_UpdateWord0;
            m_UpdateWordObject0.translation = m_UpdateTranslation0;
            m_UpdateWordObject1.word        = m_UpdateWord1;
            m_UpdateWordObject1.translation = m_UpdateTranslation1;

            if (Config.Instance.FindCredentials(m_TextToSpeech.GetServiceID()) == null)
            {
                yield break;
            }

            // Test GET
            m_TextToSpeech.ToSpeech("Hello World using GET", OnSpeechGET);
            while (!m_GetTested)
            {
                yield return(null);
            }

            // Test POST
            m_TextToSpeech.ToSpeech("Hello World using POST", OnSpeechPOST, true);
            while (!m_PostTested)
            {
                yield return(null);
            }

            //	Get Pronunciation
            string testWord = "Watson";

            Log.Debug("ExampleTextToSpeech", "Attempting to get pronunciation of {0}", testWord);
            m_TextToSpeech.GetPronunciation(OnGetPronunciation, testWord, VoiceType.en_US_Allison);
            while (!m_GetPronunciationTested)
            {
                yield return(null);
            }

            //  Get Customizations
            Log.Debug("ExampleTextToSpeech", "Attempting to get a list of customizations");
            m_TextToSpeech.GetCustomizations(OnGetCustomizations);
            while (!m_GetCustomizationsTested)
            {
                yield return(null);
            }

            //  Create Customization
            //Log.Debug("ExampleTextToSpeech", "Attempting to create a customization");
            //m_TextToSpeech.CreateCustomization(OnCreateCustomization, m_CustomizationToCreateName, m_CustomizationToCreateLanguage, m_CustomizationToCreateDescription);
            //while (!m_CreateCustomizationTested)
            //    yield return null;

            //  Get Customization
            Log.Debug("ExampleTextToSpeech", "Attempting to get a customization");
            if (!m_TextToSpeech.GetCustomization(OnGetCustomization, m_CustomizationIDToTest))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to get custom voice model!");
            }
            while (!m_GetCustomizationTested)
            {
                yield return(null);
            }

            //  Update Customization
            Log.Debug("ExampleTextToSpeech", "Attempting to update a customization");
            Word[]            words             = { m_UpdateWordObject0 };
            CustomVoiceUpdate customVoiceUpdate = new CustomVoiceUpdate();

            customVoiceUpdate.words = words;
            if (!m_TextToSpeech.UpdateCustomization(OnUpdateCustomization, m_CustomizationIDToTest, customVoiceUpdate))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to update customization!");
            }
            while (!m_UpdateCustomizationTested)
            {
                yield return(null);
            }

            //  Get Customization Words
            Log.Debug("ExampleTextToSpeech", "Attempting to get a customization's words");
            if (!m_TextToSpeech.GetCustomizationWords(OnGetCustomizationWords, m_CustomizationIDToTest))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to get {0} words!", m_CustomizationIDToTest);
            }
            while (!m_GetCustomizationWordsTested)
            {
                yield return(null);
            }

            //  Add Customization Words
            Log.Debug("ExampleTextToSpeech", "Attempting to add words to a customization");
            Word[] wordArray   = { m_UpdateWordObject1 };
            Words  wordsObject = new Words();

            wordsObject.words = wordArray;
            if (!m_TextToSpeech.AddCustomizationWords(OnAddCustomizationWords, m_CustomizationIDToTest, wordsObject))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to add words to {0}!", wordsObject);
            }
            while (!m_AddCustomizationWordsTested)
            {
                yield return(null);
            }

            ////  Get Customization Word
            Log.Debug("ExampleTextToSpeech", "Attempting to get the translation of a custom voice model's word.");
            if (!m_TextToSpeech.GetCustomizationWord(OnGetCustomizationWord, m_CustomizationIDToTest, m_UpdateWord1))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to get the translation of {0} from {1}!", m_UpdateWord0, m_CustomizationIDToTest);
            }
            while (!m_GetCustomizationWordTested)
            {
                yield return(null);
            }

            //Delete Customization Word
            //Log.Debug("ExampleTextToSpeech", "Attempting to delete customization word from custom voice model.");
            //if (!m_TextToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, m_CustomizationIdCreated, m_UpdateWord1))
            //    Log.Debug("ExampleTextToSpeech", "Failed to delete {0} from {1}!", m_UpdateWord1, m_CustomizationIdCreated);
            //while (!m_DeleteCustomizationWordTested)
            //    yield return null;

            //  Delete Customization
            //Log.Debug("ExampleTextToSpeech", "Attempting to delete a customization");
            //if (!m_TextToSpeech.DeleteCustomization(OnDeleteCustomization, m_CustomizationIdCreated))
            //    Log.Debug("ExampleTextToSpeech", "Failed to delete custom voice model!");
            //while (!m_DeleteCustomizationTested)
            //    yield return null;

            yield break;
        }
Example #5
0
        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["text_to_speech"][TestCredentialIndex].Credentials;
                _username = credential.Username.ToString();
                _password = credential.Password.ToString();
                _url      = credential.Url.ToString();
            }
            catch
            {
                Log.Debug("TestTextToSpeech", "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
            //};

            _textToSpeech = new TextToSpeech(credentials);

            //  Synthesize
            Log.Debug("ExampleTextToSpeech", "Attempting synthesize.");
            _textToSpeech.Voice = VoiceType.en_US_Allison;
            _textToSpeech.ToSpeech(_testString, HandleToSpeechCallback, true);
            while (!_synthesizeTested)
            {
                yield return(null);
            }

            //	Get Voices
            Log.Debug("ExampleTextToSpeech", "Attempting to get voices.");
            _textToSpeech.GetVoices(OnGetVoices);
            while (!_getVoicesTested)
            {
                yield return(null);
            }

            //	Get Voice
            Log.Debug("ExampleTextToSpeech", "Attempting to get voice {0}.", VoiceType.en_US_Allison);
            _textToSpeech.GetVoice(OnGetVoice, VoiceType.en_US_Allison);
            while (!_getVoiceTested)
            {
                yield return(null);
            }

            //	Get Pronunciation
            Log.Debug("ExampleTextToSpeech", "Attempting to get pronunciation of {0}", _testWord);
            _textToSpeech.GetPronunciation(OnGetPronunciation, _testWord, VoiceType.en_US_Allison);
            while (!_getPronuciationTested)
            {
                yield return(null);
            }

            //  Get Customizations
            Log.Debug("ExampleTextToSpeech", "Attempting to get a list of customizations");
            _textToSpeech.GetCustomizations(OnGetCustomizations);
            while (!_getCustomizationsTested)
            {
                yield return(null);
            }

            //  Create Customization
            Log.Debug("ExampleTextToSpeech", "Attempting to create a customization");
            _textToSpeech.CreateCustomization(OnCreateCustomization, _customizationName, _customizationLanguage, _customizationDescription);
            while (!_createCustomizationTested)
            {
                yield return(null);
            }

            //  Get Customization
            Log.Debug("ExampleTextToSpeech", "Attempting to get a customization");
            if (!_textToSpeech.GetCustomization(OnGetCustomization, _createdCustomizationId))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to get custom voice model!");
            }
            while (!_getCustomizationTested)
            {
                yield return(null);
            }

            //  Update Customization
            Log.Debug("ExampleTextToSpeech", "Attempting to update a customization");
            Word[] wordsToUpdateCustomization =
            {
                new Word()
                {
                    word        = "hello",
                    translation = "hullo"
                },
                new Word()
                {
                    word        = "goodbye",
                    translation = "gbye"
                },
                new Word()
                {
                    word        = "hi",
                    translation = "ohioooo"
                }
            };

            _customVoiceUpdate = new CustomVoiceUpdate()
            {
                words       = wordsToUpdateCustomization,
                description = "My updated description",
                name        = "My updated name"
            };

            if (!_textToSpeech.UpdateCustomization(OnUpdateCustomization, _createdCustomizationId, _customVoiceUpdate))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to update customization!");
            }
            while (!_updateCustomizationTested)
            {
                yield return(null);
            }

            //  Get Customization Words
            Log.Debug("ExampleTextToSpeech", "Attempting to get a customization's words");
            string customIdentifierToGetWords = "1476ea80-5355-4911-ac99-ba39162a2d34";

            if (!_textToSpeech.GetCustomizationWords(OnGetCustomizationWords, customIdentifierToGetWords))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to get {0} words!", customIdentifierToGetWords);
            }
            while (!_getCustomizationWordsTested)
            {
                yield return(null);
            }

            //  Add Customization Words
            Log.Debug("ExampleTextToSpeech", "Attempting to add words to a customization");
            Word[] wordArrayToAddToCustomization =
            {
                new Word()
                {
                    word        = "bananna",
                    translation = "arange"
                },
                new Word()
                {
                    word        = "orange",
                    translation = "gbye"
                },
                new Word()
                {
                    word        = "tomato",
                    translation = "tomahto"
                }
            };

            Words wordsToAddToCustomization = new Words()
            {
                words = wordArrayToAddToCustomization
            };

            if (!_textToSpeech.AddCustomizationWords(OnAddCustomizationWords, _createdCustomizationId, wordsToAddToCustomization))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to add words to {0}!", _createdCustomizationId);
            }
            while (!_addCustomizationWordsTested)
            {
                yield return(null);
            }

            //  Get Customization Word
            Log.Debug("ExampleTextToSpeech", "Attempting to get the translation of a custom voice model's word.");
            string customIdentifierWord = wordsToUpdateCustomization[0].word;

            if (!_textToSpeech.GetCustomizationWord(OnGetCustomizationWord, _createdCustomizationId, customIdentifierWord))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to get the translation of {0} from {1}!", customIdentifierWord, _createdCustomizationId);
            }
            while (!_getCustomizationWordTested)
            {
                yield return(null);
            }

            //  Delete Customization Word
            Log.Debug("ExampleTextToSpeech", "Attempting to delete customization word from custom voice model.");
            string wordToDelete = "goodbye";

            if (!_textToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, _createdCustomizationId, wordToDelete))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to delete {0} from {1}!", wordToDelete, _createdCustomizationId);
            }
            while (!_deleteCustomizationWordTested)
            {
                yield return(null);
            }

            //  Delete Customization
            Log.Debug("ExampleTextToSpeech", "Attempting to delete a customization");
            if (!_textToSpeech.DeleteCustomization(OnDeleteCustomization, _createdCustomizationId))
            {
                Log.Debug("ExampleTextToSpeech", "Failed to delete custom voice model!");
            }
            while (!_deleteCustomizationTested)
            {
                yield return(null);
            }

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

            yield break;
        }
        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("text-to-speech-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);
            }

            _textToSpeech = new TextToSpeech(credentials);

            ////  Synthesize
            //Log.Debug("TestTextToSpeech.RunTest()", "Attempting synthesize.");
            //_textToSpeech.Voice = VoiceType.en_US_Allison;
            //_textToSpeech.ToSpeech(HandleToSpeechCallback, OnFail, _testString, true);
            //while (!_synthesizeTested)
            //    yield return null;

            ////  Synthesize Conversation string
            //Log.Debug("TestTextToSpeech.RunTest()", "Attempting synthesize a string as returned by Watson Conversation.");
            //_textToSpeech.Voice = VoiceType.en_US_Allison;
            //_textToSpeech.ToSpeech(HandleConversationToSpeechCallback, OnFail, _testConversationString, true);
            //while (!_synthesizeConversationTested)
            //    yield return null;

            //	Get Voices
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get voices.");
            _textToSpeech.GetVoices(OnGetVoices, OnFail);
            while (!_getVoicesTested)
            {
                yield return(null);
            }

            //	Get Voice
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get voice {0}.", VoiceType.en_US_Allison);
            _textToSpeech.GetVoice(OnGetVoice, OnFail, VoiceType.en_US_Allison);
            while (!_getVoiceTested)
            {
                yield return(null);
            }

            //	Get Pronunciation
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get pronunciation of {0}", _testWord);
            _textToSpeech.GetPronunciation(OnGetPronunciation, OnFail, _testWord, VoiceType.en_US_Allison);
            while (!_getPronuciationTested)
            {
                yield return(null);
            }

            //  Get Customizations
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get a list of customizations");
            _textToSpeech.GetCustomizations(OnGetCustomizations, OnFail);
            while (!_getCustomizationsTested)
            {
                yield return(null);
            }

            //  Create Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to create a customization");
            _textToSpeech.CreateCustomization(OnCreateCustomization, OnFail, _customizationName, _customizationLanguage, _customizationDescription);
            while (!_createCustomizationTested)
            {
                yield return(null);
            }

            //  Get Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get a customization");
            if (!_textToSpeech.GetCustomization(OnGetCustomization, OnFail, _createdCustomizationId))
            {
                Log.Debug("TestTextToSpeech.RunTest()", "Failed to get custom voice model!");
            }
            while (!_getCustomizationTested)
            {
                yield return(null);
            }

            //  Update Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to update a customization");
            Word[] wordsToUpdateCustomization =
            {
                new Word()
                {
                    word        = "hello",
                    translation = "hullo"
                },
                new Word()
                {
                    word        = "goodbye",
                    translation = "gbye"
                },
                new Word()
                {
                    word        = "hi",
                    translation = "ohioooo"
                }
            };

            _customVoiceUpdate = new CustomVoiceUpdate()
            {
                words       = wordsToUpdateCustomization,
                description = "My updated description",
                name        = "My updated name"
            };

            if (!_textToSpeech.UpdateCustomization(OnUpdateCustomization, OnFail, _createdCustomizationId, _customVoiceUpdate))
            {
                Log.Debug("TestTextToSpeech.UpdateCustomization()", "Failed to update customization!");
            }
            while (!_updateCustomizationTested)
            {
                yield return(null);
            }

            //  Get Customization Words
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get a customization's words");
            if (!_textToSpeech.GetCustomizationWords(OnGetCustomizationWords, OnFail, _createdCustomizationId))
            {
                Log.Debug("TestTextToSpeech.GetCustomizationWords()", "Failed to get {0} words!", _createdCustomizationId);
            }
            while (!_getCustomizationWordsTested)
            {
                yield return(null);
            }

            //  Add Customization Words
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to add words to a customization");
            Word[] wordArrayToAddToCustomization =
            {
                new Word()
                {
                    word        = "bananna",
                    translation = "arange"
                },
                new Word()
                {
                    word        = "orange",
                    translation = "gbye"
                },
                new Word()
                {
                    word        = "tomato",
                    translation = "tomahto"
                }
            };

            Words wordsToAddToCustomization = new Words()
            {
                words = wordArrayToAddToCustomization
            };

            if (!_textToSpeech.AddCustomizationWords(OnAddCustomizationWords, OnFail, _createdCustomizationId, wordsToAddToCustomization))
            {
                Log.Debug("TestTextToSpeech.AddCustomizationWords()", "Failed to add words to {0}!", _createdCustomizationId);
            }
            while (!_addCustomizationWordsTested)
            {
                yield return(null);
            }

            //  Get Customization Word
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to get the translation of a custom voice model's word.");
            string customIdentifierWord = wordsToUpdateCustomization[0].word;

            if (!_textToSpeech.GetCustomizationWord(OnGetCustomizationWord, OnFail, _createdCustomizationId, customIdentifierWord))
            {
                Log.Debug("TestTextToSpeech.GetCustomizationWord()", "Failed to get the translation of {0} from {1}!", customIdentifierWord, _createdCustomizationId);
            }
            while (!_getCustomizationWordTested)
            {
                yield return(null);
            }

            //  Delete Customization Word
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to delete customization word from custom voice model.");
            string wordToDelete = "goodbye";

            if (!_textToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, OnFail, _createdCustomizationId, wordToDelete))
            {
                Log.Debug("TestTextToSpeech.DeleteCustomizationWord()", "Failed to delete {0} from {1}!", wordToDelete, _createdCustomizationId);
            }
            while (!_deleteCustomizationWordTested)
            {
                yield return(null);
            }

            //  Delete Customization
            Log.Debug("TestTextToSpeech.RunTest()", "Attempting to delete a customization");
            if (!_textToSpeech.DeleteCustomization(OnDeleteCustomization, OnFail, _createdCustomizationId))
            {
                Log.Debug("TestTextToSpeech.DeleteCustomization()", "Failed to delete custom voice model!");
            }
            while (!_deleteCustomizationTested)
            {
                yield return(null);
            }

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

            yield break;
        }