コード例 #1
0
        public void UpdateVoiceModel()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            TextToSpeechService service = new TextToSpeechService(authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var words = new List <Word>()
            {
                new Word()
                {
                    _Word       = "NCAA",
                    Translation = "N C double A"
                },
                new Word()
                {
                    _Word       = "iPhone",
                    Translation = "I phone"
                }
            };

            var result = service.UpdateCustomModel(
                customizationId: "{customizationId}",
                name: "First Model Update",
                description: "First custom voice model update",
                words: words
                );

            Console.WriteLine(result.Result);
        }
        public IEnumerator TestUpdateCustomModel()
        {
            Log.Debug("TextToSpeechServiceV1IntegrationTests", "Attempting to UpdateCustomModel...");
            object updateCustomModelResponse = null;

            service.UpdateCustomModel(
                callback: (DetailedResponse <object> response, IBMError error) =>
            {
                Log.Debug("TextToSpeechServiceV1IntegrationTests", "UpdateCustomModel result: {0}", response.Response);
                updateCustomModelResponse = response.Result;
                Assert.IsNotNull(updateCustomModelResponse);
                Assert.IsNull(error);
            },
                customizationId: customizationId,
                name: customModelNameUpdated,
                description: customModelDescriptionUpdated
                );

            while (updateCustomModelResponse == null)
            {
                yield return(null);
            }
        }
コード例 #3
0
        public void UpdateVoiceModel_Success()
        {
            IClient  client  = Substitute.For <IClient>();
            IRequest request = Substitute.For <IRequest>();

            client.PostAsync(Arg.Any <string>())
            .Returns(request);

            TextToSpeechService service = new TextToSpeechService(client);

            var customizationId = "customizationId";
            var name            = "name";
            var description     = "description";
            var words           = new List <Word>();

            var result = service.UpdateCustomModel(customizationId: customizationId, name: name, description: description, words: words);

            JObject bodyObject = new JObject();

            if (!string.IsNullOrEmpty(name))
            {
                bodyObject["name"] = JToken.FromObject(name);
            }
            if (!string.IsNullOrEmpty(description))
            {
                bodyObject["description"] = JToken.FromObject(description);
            }
            if (words != null && words.Count > 0)
            {
                bodyObject["words"] = JToken.FromObject(words);
            }
            var json = JsonConvert.SerializeObject(bodyObject);

            request.Received().WithBodyContent(Arg.Is <StringContent>(x => x.ReadAsStringAsync().Result.Equals(json)));
            client.Received().PostAsync($"{service.ServiceUrl}/v1/customizations/{customizationId}");
        }
コード例 #4
0
        public void CustomVoiceModels_Success()
        {
            service.WithHeader("X-Watson-Test", "1");
            var listVoiceModelsResult = service.ListCustomModels();

            service.WithHeader("X-Watson-Test", "1");
            var createVoiceModelResult = service.CreateCustomModel(
                name: voiceModelName,
                language: "en-US",
                description: voiceModelDescription);
            var customizationId = createVoiceModelResult.Result.CustomizationId;

            service.WithHeader("X-Watson-Test", "1");
            var getVoiceModelResult = service.GetCustomModel(
                customizationId: customizationId
                );

            var words = new List <Word>()
            {
                new Word()
                {
                    _Word       = "hello",
                    Translation = "hullo"
                },
                new Word()
                {
                    _Word       = "goodbye",
                    Translation = "gbye"
                },
                new Word()
                {
                    _Word       = "hi",
                    Translation = "ohioooo"
                }
            };

            service.WithHeader("X-Watson-Test", "1");
            var updateVoiceModelResult = service.UpdateCustomModel(
                customizationId: customizationId,
                name: voiceModelUpdatedName,
                description: voiceModelUpdatedDescription,
                words: words
                );

            service.WithHeader("X-Watson-Test", "1");
            var getVoiceModelResult2 = service.GetCustomModel(
                customizationId: customizationId
                );

            service.WithHeader("X-Watson-Test", "1");
            var deleteVoiceModelResult = service.DeleteCustomModel(
                customizationId: customizationId
                );

            Assert.IsNotNull(deleteVoiceModelResult.StatusCode == 204);
            Assert.IsNotNull(getVoiceModelResult2.Result);
            Assert.IsTrue(getVoiceModelResult2.Result.Name == voiceModelUpdatedName);
            Assert.IsTrue(getVoiceModelResult2.Result.Description == voiceModelUpdatedDescription);
            Assert.IsTrue(getVoiceModelResult2.Result.Words.Count == 3);
            Assert.IsNotNull(getVoiceModelResult.Result);
            Assert.IsTrue(getVoiceModelResult.Result.Name == voiceModelName);
            Assert.IsTrue(getVoiceModelResult.Result.Description == voiceModelDescription);
            Assert.IsNotNull(createVoiceModelResult.Result);
            Assert.IsNotNull(listVoiceModelsResult.Result);
            Assert.IsNotNull(listVoiceModelsResult.Result.Customizations);
        }