Exemple #1
0
        public static bool Create(string subscriptionKey, string hostURI, string name, string description, string gender, string locale)
        {
            var properties = new Dictionary <string, string>();

            properties.Add("Gender", gender.Substring(0, 1).ToUpper() + gender.Substring(1));

            var projectDefinition = ProjectDefinition.Create(
                name,
                name,
                description,
                locale,
                properties,
                "TextToSpeech");

            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(projectDefinition);

            var response = APIHelper.Submit(subscriptionKey, hostURI + API_V3.VoiceProject_Create, jsonString);


            if (response.StatusCode != HttpStatusCode.Accepted && response.StatusCode != HttpStatusCode.Created)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }

            System.Console.WriteLine(response.Headers.Location);
            return(true);
        }
        public static bool Create(string subscriptionKey, string hostURI, string name, string description,
                                  string local, Guid projectId, Guid modelId, bool wait = true)
        {
            var properties = new Dictionary <string, string>();

            properties.Add("PortalAPIVersion", "3");

            System.Net.Http.HttpResponseMessage response;


            var endpointDefinition = EndpointDefinition.Create(
                name,
                description,
                local,
                new Identity(projectId),
                new List <Identity> {
                new Identity(modelId)
            },
                properties);
            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(endpointDefinition);

            response = APIHelper.Submit(subscriptionKey, hostURI + API_V3.VoiceEndpoints_Create, jsonString);

            if (response.StatusCode != HttpStatusCode.Accepted)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }

            Console.WriteLine("endpoint created: " + response.Headers.Location.ToString());

            return(true);
        }
Exemple #3
0
        public static bool Create(string subscriptionKey, string hostURI, string name, string description,
                                  Guid projectId, string gender, string locale, List <Identity> dataset, bool isNeuralTTS, bool isMixlingual,
                                  IDictionary <string, string> neuralProperties)
        {
            var properties = new Dictionary <string, string>();

            properties.Add("Gender", gender.Substring(0, 1).ToUpper() + gender.Substring(1));

            if (isMixlingual)
            {
                locale = "zh-CN";
                properties.Add("IsMixLingual", "true");
            }
            else
            {
                properties.Add("IsMixLingual", "false");
            }

            if (isNeuralTTS)
            {
                properties.Add("VoiceModelKind", "NeuralTts");
                properties.Add("PortalAPIVersion", "3");
                properties.Add("Purpose", "Realtime");

                foreach (var neuralProperty in neuralProperties)
                {
                    properties.Add(neuralProperty.Key, neuralProperty.Value);
                }
            }

            var modelDefinition = ModelDefinition.Create(
                name,
                description,
                properties,
                locale,
                "CustomVoice",
                null,
                dataset,
                new Identity(projectId));

            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(modelDefinition);

            var response = APIHelper.Submit(subscriptionKey, hostURI + API_V3.VoiceModels_Create, jsonString);

            if (response.StatusCode != HttpStatusCode.Accepted)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }

            System.Console.WriteLine(response.Headers.Location);
            return(true);
        }
Exemple #4
0
        public static bool Create(string subscriptionKey, string hostURI, string name, string description,
                                  Guid projectId, string gender, string locale, List <Identity> dataset, bool isNeuralTTS, bool isMixlingual,
                                  IDictionary <string, string> neuralProperties)
        {
            var properties = new Dictionary <string, string>();

            properties.Add("Gender", gender.Substring(0, 1).ToUpper() + gender.Substring(1));

            if (isMixlingual)
            {
                locale = "zh-CN";
                properties.Add("IsMixLingual", "true");
            }
            else
            {
                properties.Add("IsMixLingual", "false");
            }

            if (isNeuralTTS)
            {
                properties.Add("VoiceModelKind", "NeuralTts");
                foreach (var neuralProperty in neuralProperties)
                {
                    properties.Add(neuralProperty.Key, neuralProperty.Value);
                }
            }

            var modelDefinition = ModelDefinition.Create(
                name,
                description,
                properties,
                locale,
                "CustomVoice",
                null,
                dataset,
                new Identity(projectId));
            var response = APIHelper.Submit <ModelDefinition>(subscriptionKey, hostURI + API_V3.VoiceModels_Create, modelDefinition);

            if (response.StatusCode != HttpStatusCode.Accepted)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }
            return(true);
        }
Exemple #5
0
        public static bool Create(string subscriptionKey, string hostURI, string name, string description,
                                  string local, Guid projectId, Guid modelId)
        {
            var endpointDefinition = EndpointDefinition.Create(
                name,
                description,
                local,
                new Identity(projectId),
                new List <Identity> {
                new Identity(modelId)
            },
                null);
            var response = APIHelper.Submit <EndpointDefinition>(subscriptionKey, hostURI + API_V3.VoiceEndpoints_Create, endpointDefinition);

            if (response.StatusCode != HttpStatusCode.Accepted)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }
            return(true);
        }
Exemple #6
0
        public static bool AddToProject(string subscriptionKey, string hostURI, Guid projectId, Guid modelId)
        {
            string url         = string.Format(CultureInfo.InvariantCulture, hostURI + API_V3.VoiceModels_AddToProject, projectId);
            var    modelsToAdd = new List <Identity> {
                Identity.Create(modelId)
            };
            var response = APIHelper.Submit(subscriptionKey, url, modelsToAdd);

            if (!response.IsSuccessStatusCode)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }

            var content         = response.Content.ReadAsStringAsync().Result;
            var beautifyContent = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(content), Formatting.Indented);

            Console.WriteLine(beautifyContent);

            return(true);
        }
Exemple #7
0
        public static bool Copy(string subscriptionKey, string hostURI, Guid modelId, string targetSubscriptionKey)
        {
            string       url = string.Format(CultureInfo.InvariantCulture, hostURI + API_V3.VoiceModels_Copy, modelId);
            const string targetSubscriptionKeyName = "targetSubscriptionKey";
            var          payload = new Dictionary <string, string> {
                { targetSubscriptionKeyName, targetSubscriptionKey }
            };
            var response = APIHelper.Submit(subscriptionKey, url, payload);

            if (!response.IsSuccessStatusCode)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }

            var uri = APIHelper.GetLocationFromPostResponseAsync(response);

            Console.WriteLine($"Copied model: {uri}");

            return(true);
        }
        public static bool Create(string subscriptionKey, string hostURI, string name, string description, string gender, string locale)
        {
            var properties = new Dictionary <string, string>();

            properties.Add("Gender", gender.Substring(0, 1).ToUpper() + gender.Substring(1));

            var projectDefinition = ProjectDefinition.Create(
                name,
                description,
                locale,
                properties,
                "TextToSpeech");
            var response = APIHelper.Submit <ProjectDefinition>(subscriptionKey, hostURI + API_V3.VoiceProject_Create, projectDefinition);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }
            return(true);
        }
Exemple #9
0
        public static bool Create(string subscriptionKey, string hostURI, Guid projectId, Guid modelId, string script, bool isSSML)
        {
            string TextKind = "Text";

            if (isSSML)
            {
                TextKind = "SSML";
            }

            var voiceTestDefinition = VoiceTestDefinition.Create(
                new Identity(modelId),
                script,
                TextKind,
                new Identity(projectId));

            var response = APIHelper.Submit <VoiceTestDefinition>(subscriptionKey, hostURI + API_V3.VoiceTests_Create, voiceTestDefinition);

            if (response.StatusCode != HttpStatusCode.Accepted)
            {
                APIHelper.PrintErrorMessage(response);
                return(false);
            }
            return(true);
        }