Example #1
0
        private static string Create(string subscriptionKey, string hostURI, BatchSynthesisDefinition batchSynthesisDefinition)
        {
            string scriptName = Path.GetFileName(batchSynthesisDefinition.InputTextPath);

            using (FileStream fsscript = new FileStream(batchSynthesisDefinition.InputTextPath, FileMode.Open))
                using (var client = new HttpClient())
                    using (var content = new MultipartFormDataContent())
                    {
                        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

                        content.Add(new StringContent(batchSynthesisDefinition.Name), "name");

                        if (!string.IsNullOrEmpty(batchSynthesisDefinition.OutputFormat))
                        {
                            content.Add(new StringContent(batchSynthesisDefinition.OutputFormat), "outputformat");
                        }

                        if (batchSynthesisDefinition.Description != null)
                        {
                            content.Add(new StringContent(batchSynthesisDefinition.Description), "description");
                        }

                        content.Add(new StringContent(JsonConvert.SerializeObject(batchSynthesisDefinition.Models)), "models");
                        content.Add(new StringContent(batchSynthesisDefinition.Locale), "locale");

                        if (batchSynthesisDefinition.Properties != null)
                        {
                            content.Add(new StringContent(JsonConvert.SerializeObject(batchSynthesisDefinition.Properties)), "properties");
                        }

                        var scriptContent = new StreamContent(fsscript);
                        scriptContent.Headers.Add("Content-Disposition", $@"form-data; name=""script""; filename=""{scriptName}""");
                        scriptContent.Headers.Add("Content-Type", "text/plain");
                        scriptContent.Headers.Add("Content-Length", $"{fsscript.Length}");
                        content.Add(scriptContent, "script", scriptName);

                        string url      = hostURI + API_V3.VoiceSynthesis_Create;
                        var    response = client.PostAsync(url, content).Result;

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

                        var returnUrl = GetLocationFromPostResponse(response);
                        if (returnUrl != null)
                        {
                            return(new Guid(returnUrl.ToString().Split('/').LastOrDefault()).ToString());
                        }
                        return(null);
                    }
        }
Example #2
0
        public static string Create(string subscriptionKey, string hostURI, string name, string description,
                                    string inputTextPath, string locale, IEnumerable <Guid> models, string outputFormat, bool isConcatenateResult)
        {
            var properties = new Dictionary <string, string>();

            if (isConcatenateResult)
            {
                properties.Add("ConcatenateResult", "true");
            }

            var batchSynthesisDefinition = BatchSynthesisDefinition.Create(name,
                                                                           description,
                                                                           inputTextPath,
                                                                           properties,
                                                                           locale,
                                                                           models,
                                                                           outputFormat);

            return(Create(subscriptionKey, hostURI, batchSynthesisDefinition));
        }
Example #3
0
        public void CreateBatchSynthesis(string name, string description, string locale, string inputTextPath, Guid modelId, string azureStorageConnectionString)
        {
            Console.WriteLine($"upload text to azure storage blob : {inputTextPath}");
            var containerName = "voicesynthesisinputfiles";

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azureStorageConnectionString);
            var blobClient         = storageAccount.CreateCloudBlobClient();
            var containerReference = blobClient.GetContainerReference(containerName);

            containerReference.CreateIfNotExists();

            var fileName = $"SubscriptionKey_{Guid.NewGuid().ToString()}.txt";

            StorageHelper.UploadFileAsync(containerReference, fileName, inputTextPath);

            var textUrl = StorageHelper.GetBlobSas(blobClient, containerName, fileName, DateTime.MaxValue);


            Console.WriteLine("Creating batch synthesiss.");
            var model = ModelIdentity.Create(modelId);
            var batchSynthesisDefinition = BatchSynthesisDefinition.Create(name, description, locale, new Uri($"{ textUrl }"), model);
            var submitResponse           = VoiceAPIHelper.Submit <BatchSynthesisDefinition>(batchSynthesisDefinition, VoiceSynthesisUrl, this.subscriptionKey);
        }