Пример #1
0
        // The voice synthesis APIs are now only availabel in DC EastUS
        private static void VoiceSynthsisAPIs()
        {
            string endpoint        = "https://eastus.cris.ai/";
            string ibizaStsUrl     = "https://eastus.api.cognitive.microsoft.com/sts/v1.0/issueToken";
            string subscriptionKey = "Your SubscriptionKey";

            CustomVoiceAPI customVoiceAPI = new CustomVoiceAPI(endpoint, ibizaStsUrl, subscriptionKey);

            // Get available voices list
            var voices = customVoiceAPI.GetVoices();

            // Submit a voice synthesis request
            const string Name        = "Simple neural TTS batch synthesis";
            const string Description = "Simple neural TTS batch synthesis description";

            const string Locale             = "en-US";
            const string LocalInputTextFile = @"TestData\en-US_small.txt";
            const string VoiceName          = "Jessa";

            var voice = voices.Where(m => m.Locale == Locale && m.Name.Contains(VoiceName) && m.IsPublicVoice).FirstOrDefault();

            if (voice == null)
            {
                Console.WriteLine($"Does not have a available voice for local : {Locale} and name {VoiceName}");
                return;
            }

            customVoiceAPI.CreateVoiceSynthesis(Name, Description, Locale, LocalInputTextFile, voice.Id);

            // Get submitted synthesis request list and update a submitted synthesis request
            var syntheses = customVoiceAPI.GetSyntheses();

            var synthesis = syntheses.FirstOrDefault();

            if (synthesis != null)
            {
                customVoiceAPI.UpdateSynthesis(synthesis.Id, "Updated Name", "Updated Desc");
            }

            // Delete all pre-existing completed synthesis. If synthesis are still running or not started, they will not be deleted
            syntheses = customVoiceAPI.GetSyntheses();
            foreach (var item in syntheses)
            {
                // delete a synthesis
                customVoiceAPI.DeleteSynthesis(item.Id);
            }
        }
Пример #2
0
        private static async Task VoiceSynthsisAPIs()
        {
            string endpoint    = "https://centralindia.cris.ai/";
            string ibizaStsUrl = "https://centralindia.api.cognitive.microsoft.com/sts/v1.0/issueToken";
            // the Subscription key should be a standard one, not the free one.
            string subscriptionKey = "Your SubscriptionKey";

            CustomVoiceAPI customVoiceAPI = new CustomVoiceAPI(endpoint, ibizaStsUrl, subscriptionKey);

            const string name        = "Simple neural TTS batch synthesis";
            const string description = "Simple neural TTS batch synthesis description";

            // The input text file could contains only plain text or only SSML or mixed together(as shown in blow script)
            // The input text file encoding format should be UTF-8-BOM
            // The input text file should contains at least 50 lines of text
            const string localInputTextFile = @"TestData\en-US.txt";
            const string locale             = "en-US";
            const string voiceName          = "Jessa";
            // public voice means the voice could be used by all Subscriptions, if the voice is private(for your Subscription only), this should be set to false
            bool isPublicVoice = true;

            // you can directly set the voiceId or query the voice information by name/locale/ispublic properties from server.
            //var voiceId = new Guid("Your voice model Guid");
            var voiceId = GetVoiceId(customVoiceAPI, locale, voiceName, isPublicVoice);

            if (voiceId == Guid.Empty)
            {
                Console.WriteLine($"Does not have a available voice for locale : {locale} , name : {voiceName}, public : {isPublicVoice}");
                return;
            }

            // indicate if want concatenate the output waves with a single file or not.
            bool concatenateResult = true;

            // Submit a voice synthesis request and get a ID
            var synthesisLocation = await customVoiceAPI.CreateVoiceSynthesis(name, description, locale, localInputTextFile, voiceId, concatenateResult).ConfigureAwait(false);

            var synthesisId = new Guid(synthesisLocation.ToString().Split('/').LastOrDefault());

            Console.WriteLine("Checking status.");
            // check for the status of the submitted synthesis every 10 sec. (can also be 1, 2, 5 min depending on usage)
            bool completed = false;

            while (!completed)
            {
                var synthesis = customVoiceAPI.GetSynthesis(synthesisId);
                switch (synthesis.Status)
                {
                case "Failed":
                case "Succeeded":
                    completed = true;
                    // if the synthesis was successfull, download the results to local
                    if (synthesis.Status == "Succeeded")
                    {
                        var       resultsUri = synthesis.ResultsUrl;
                        WebClient webClient  = new WebClient();
                        var       filename   = $"{Path.GetTempFileName()}_{synthesis.Id}_.zip";
                        webClient.DownloadFile(resultsUri, filename);
                        Console.WriteLine($"Synthesis succeeded. Results: {filename}");
                    }
                    break;

                case "Running":
                    break;

                case "NotStarted":
                    break;
                }

                Console.WriteLine(string.Format("Syntheses status: {0}", synthesis.Status));
                await Task.Delay(TimeSpan.FromSeconds(10)).ConfigureAwait(false);
            }

            Console.WriteLine("Press any key...");
            Console.ReadKey();

            // Get submitted synthesis request list and update a submitted synthesis request

            /*
             * var syntheses = customVoiceAPI.GetSyntheses();
             *
             * var synthesis = syntheses.FirstOrDefault();
             * if (synthesis != null)
             * {
             *  customVoiceAPI.UpdateSynthesis(synthesis.Id, "Updated Name", "Updated Desc");
             * }
             */

            // Delete all pre-existing completed synthesis. If synthesis are still running or not started, they will not be deleted

            /*
             * syntheses = customVoiceAPI.GetSyntheses();
             * foreach (var item in syntheses)
             * {
             *  // delete a synthesis
             *  customVoiceAPI.DeleteSynthesis(item.Id);
             * }
             */
        }