コード例 #1
0
        /// <summary>
        /// Create a custom model. Creates a new empty custom voice model. You must specify a name for the new custom model; you can optionally specify the language and a description of the new model. The model is owned by the instance of the service whose credentials are used to create it.  **Note:** This method is currently a beta release.
        /// </summary>
        /// <param name="createVoiceModel">A `CreateVoiceModel` object that contains information about the new custom voice model.</param>
        /// <param name="customData">Custom data object to pass data including custom request headers.</param>
        /// <returns><see cref="VoiceModel" />VoiceModel</returns>
        public VoiceModel CreateVoiceModel(CreateVoiceModel createVoiceModel, Dictionary <string, object> customData = null)
        {
            if (createVoiceModel == null)
            {
                throw new ArgumentNullException(nameof(createVoiceModel));
            }
            VoiceModel result = null;

            try
            {
                var request = this.Client.WithAuthentication(this.UserName, this.Password)
                              .PostAsync($"{this.Endpoint}/v1/customizations");
                request.WithBody <CreateVoiceModel>(createVoiceModel);
                if (customData != null)
                {
                    request.WithCustomData(customData);
                }
                result = request.As <VoiceModel>().Result;
                if (result == null)
                {
                    result = new VoiceModel();
                }
                result.CustomData = request.CustomData;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
コード例 #2
0
        //[TestMethod]
        public void CustomVoiceModels_Success()
        {
            var listVoiceModelsResult = ListVoiceModels();

            var createVoiceModel = new CreateVoiceModel
            {
                Name        = voiceModelName,
                Description = voiceModelDescription,
                Language    = Model.CreateVoiceModel.LanguageEnum.EN_US
            };

            var createVoiceModelResult = CreateVoiceModel(createVoiceModel);
            var customizationId        = createVoiceModelResult.CustomizationId;

            var getVoiceModelResult = GetVoiceModel(customizationId);

            var updateVoiceModel = new UpdateVoiceModel
            {
                Name        = voiceModelUpdatedName,
                Description = voiceModelUpdatedDescription,
                Words       = new System.Collections.Generic.List <Word>()
                {
                    new Word()
                    {
                        _Word       = "hello",
                        Translation = "hullo"
                    },
                    new Word()
                    {
                        _Word       = "goodbye",
                        Translation = "gbye"
                    },
                    new Word()
                    {
                        _Word       = "hi",
                        Translation = "ohioooo"
                    }
                }
            };

            var updateVoiceModelResult = UpdateVoiceModel(customizationId, updateVoiceModel);

            var deleteVoiceModelResult = DeleteVoiceModel(customizationId);

            Assert.IsNotNull(updateVoiceModel);
            Assert.IsTrue(updateVoiceModel.Name == voiceModelUpdatedName);
            Assert.IsTrue(updateVoiceModel.Description == voiceModelUpdatedDescription);
            Assert.IsTrue(updateVoiceModel.Words.Count == 3);
            Assert.IsNotNull(getVoiceModelResult);
            Assert.IsTrue(getVoiceModelResult.Name == voiceModelName);
            Assert.IsTrue(getVoiceModelResult.Description == voiceModelDescription);
            Assert.IsNotNull(createVoiceModelResult);
            Assert.IsNotNull(listVoiceModelsResult);
            Assert.IsNotNull(listVoiceModelsResult.Customizations);
        }
コード例 #3
0
        private VoiceModel CreateVoiceModel(CreateVoiceModel createVoiceModel, Dictionary <string, object> customData = null)
        {
            Console.WriteLine("\nAttempting to CreateVoiceModel()");
            var result = service.CreateVoiceModel(createVoiceModel: createVoiceModel, customData: customData);

            if (result != null)
            {
                Console.WriteLine("CreateVoiceModel() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
            }
            else
            {
                Console.WriteLine("Failed to CreateVoiceModel()");
            }

            return(result);
        }
コード例 #4
0
        private void Words_Success()
        {
            var createVoiceModel = new CreateVoiceModel
            {
                Name        = voiceModelName,
                Description = voiceModelDescription,
                Language    = Model.CreateVoiceModel.LanguageEnum.EN_US
            };

            var createVoiceModelResult = CreateVoiceModel(createVoiceModel);
            var customizationId        = createVoiceModelResult.CustomizationId;

            var customWords = new Words
            {
                _Words = new System.Collections.Generic.List <Word>()
                {
                    new Word()
                    {
                        _Word       = "hello",
                        Translation = "hullo"
                    },
                    new Word()
                    {
                        _Word       = "goodbye",
                        Translation = "gbye"
                    },
                    new Word()
                    {
                        _Word       = "hi",
                        Translation = "ohioooo"
                    }
                }
            };

            var addWordsResult = AddWords(customizationId, customWords);

            var listWordsResult = ListWords(customizationId);

            var getWordResult = GetWord(customizationId, "hello");

            var wordTranslation = new Translation
            {
                _Translation = "eye bee m"
            };

            var addWordResult = AddWord(customizationId, "IBM", wordTranslation);

            var checkAddWordResult = ListWords(customizationId);

            var deleteWordResult = DeleteWord(customizationId, "hi");

            var checkDeleteWordResult = ListWords(customizationId);

            var deleteVoiceModelResult = DeleteVoiceModel(customizationId);

            Assert.IsNotNull(checkDeleteWordResult);
            Assert.IsNotNull(checkDeleteWordResult._Words);
            Assert.IsTrue(checkDeleteWordResult._Words.Count == 3);
            Assert.IsNotNull(checkAddWordResult);
            Assert.IsNotNull(checkAddWordResult._Words);
            Assert.IsTrue(checkAddWordResult._Words.Count == 4);
            Assert.IsNotNull(getWordResult);
            Assert.IsTrue(getWordResult._Translation == "hullo");
            Assert.IsNotNull(listWordsResult);
            Assert.IsNotNull(listWordsResult._Words);
            Assert.IsTrue(listWordsResult._Words.Count == 3);
            Assert.IsNotNull(addWordsResult);
        }