public async static Task <List <PollyVoiceDTO> > GetVoiceList(IAmazonPolly pollyClient, string languageCode)
        {
            List <PollyVoiceDTO> result = new List <PollyVoiceDTO>();

            DescribeVoicesRequest describeVoicesRequest = new DescribeVoicesRequest()
            {
                LanguageCode = languageCode
            };

            String nextToken;

            do
            {
                DescribeVoicesResponse describeVoicesResponse = await pollyClient.DescribeVoicesAsync(describeVoicesRequest);

                nextToken = describeVoicesResponse.NextToken;
                describeVoicesRequest.NextToken = nextToken;

                //Console.WriteLine(languageCode + " Voices: ");
                foreach (var voice in describeVoicesResponse.Voices)
                {
                    // Console.WriteLine(" Name: {0}, Gender: {1}, LanguageName: {2}", voice.Name, voice.Gender, voice.LanguageName);
                    result.Add(new PollyVoiceDTO()
                    {
                        voice_name = voice.Name,
                        gender     = voice.Gender
                    });
                }
                ;
            } while (nextToken != null);

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the list of voices that are available for use when requesting speech synthesis.
        /// Each voice speaks a specified language, is either male or female, and is identified
        /// by an ID, which is the ASCII version of the voice name.
        ///
        ///
        /// <para>
        /// When synthesizing speech ( <code>SynthesizeSpeech</code> ), you provide the voice
        /// ID for the voice you want from the list of voices returned by <code>DescribeVoices</code>.
        /// </para>
        ///
        /// <para>
        /// For example, you want your news reader application to read news in a specific language,
        /// but giving a user the option to choose the voice. Using the <code>DescribeVoices</code>
        /// operation you can provide the user with a list of available voices to select from.
        /// </para>
        ///
        /// <para>
        ///  You can optionally specify a language code to filter the available voices. For example,
        /// if you specify <code>en-US</code>, the operation returns a list of all available US
        /// English voices.
        /// </para>
        ///
        /// <para>
        /// This operation requires permissions to perform the <code>polly:DescribeVoices</code>
        /// action.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the DescribeVoices service method.</param>
        ///
        /// <returns>The response from the DescribeVoices service method, as returned by Polly.</returns>
        /// <exception cref="Amazon.Polly.Model.InvalidNextTokenException">
        /// The NextToken is invalid. Verify that it's spelled correctly, and then try again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.ServiceFailureException">
        /// An unknown condition has caused a service failure.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/polly-2016-06-10/DescribeVoices">REST API Reference for DescribeVoices Operation</seealso>
        public DescribeVoicesResponse DescribeVoices(DescribeVoicesRequest request)
        {
            var marshaller   = new DescribeVoicesRequestMarshaller();
            var unmarshaller = DescribeVoicesResponseUnmarshaller.Instance;

            return(Invoke <DescribeVoicesRequest, DescribeVoicesResponse>(request, marshaller, unmarshaller));
        }
Esempio n. 3
0
        internal virtual DescribeVoicesResponse DescribeVoices(DescribeVoicesRequest request)
        {
            var marshaller   = DescribeVoicesRequestMarshaller.Instance;
            var unmarshaller = DescribeVoicesResponseUnmarshaller.Instance;

            return(Invoke <DescribeVoicesRequest, DescribeVoicesResponse>(request, marshaller, unmarshaller));
        }
Esempio n. 4
0
        /// <summary>
        /// Initiates the asynchronous execution of the DescribeVoices operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the DescribeVoices operation on AmazonPollyClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDescribeVoices
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/polly-2016-06-10/DescribeVoices">REST API Reference for DescribeVoices Operation</seealso>
        public IAsyncResult BeginDescribeVoices(DescribeVoicesRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = new DescribeVoicesRequestMarshaller();
            var unmarshaller = DescribeVoicesResponseUnmarshaller.Instance;

            return(BeginInvoke <DescribeVoicesRequest>(request, marshaller, unmarshaller,
                                                       callback, state));
        }
Esempio n. 5
0
        /// <summary>
        /// Initiates the asynchronous execution of the DescribeVoices operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the DescribeVoices operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/polly-2016-06-10/DescribeVoices">REST API Reference for DescribeVoices Operation</seealso>
        public virtual Task <DescribeVoicesResponse> DescribeVoicesAsync(DescribeVoicesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = DescribeVoicesRequestMarshaller.Instance;
            var unmarshaller = DescribeVoicesResponseUnmarshaller.Instance;

            return(InvokeAsync <DescribeVoicesRequest, DescribeVoicesResponse>(request, marshaller,
                                                                               unmarshaller, cancellationToken));
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the list of voices that are available for use when requesting speech synthesis.
        /// Each voice speaks a specified language, is either male or female, and is identified
        /// by an ID, which is the ASCII version of the voice name.
        ///
        ///
        /// <para>
        /// When synthesizing speech ( <code>SynthesizeSpeech</code> ), you provide the voice
        /// ID for the voice you want from the list of voices returned by <code>DescribeVoices</code>.
        /// </para>
        ///
        /// <para>
        /// For example, you want your news reader application to read news in a specific language,
        /// but giving a user the option to choose the voice. Using the <code>DescribeVoices</code>
        /// operation you can provide the user with a list of available voices to select from.
        /// </para>
        ///
        /// <para>
        ///  You can optionally specify a language code to filter the available voices. For example,
        /// if you specify <code>en-US</code>, the operation returns a list of all available US
        /// English voices.
        /// </para>
        ///
        /// <para>
        /// This operation requires permissions to perform the <code>polly:DescribeVoices</code>
        /// action.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the DescribeVoices service method.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>The response from the DescribeVoices service method, as returned by Polly.</returns>
        /// <exception cref="Amazon.Polly.Model.InvalidNextTokenException">
        /// The NextToken is invalid. Verify that it's spelled correctly, and then try again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.ServiceFailureException">
        /// An unknown condition has caused a service failure.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/polly-2016-06-10/DescribeVoices">REST API Reference for DescribeVoices Operation</seealso>
        public virtual Task <DescribeVoicesResponse> DescribeVoicesAsync(DescribeVoicesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = DescribeVoicesRequestMarshaller.Instance;
            options.ResponseUnmarshaller = DescribeVoicesResponseUnmarshaller.Instance;

            return(InvokeAsync <DescribeVoicesResponse>(request, options, cancellationToken));
        }
Esempio n. 7
0
        internal virtual DescribeVoicesResponse DescribeVoices(DescribeVoicesRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = DescribeVoicesRequestMarshaller.Instance;
            options.ResponseUnmarshaller = DescribeVoicesResponseUnmarshaller.Instance;

            return(Invoke <DescribeVoicesResponse>(request, options));
        }
        public async static Task <List <PollyLanguageDTO> > GetLanguageList(IAmazonPolly pollyClient)
        {
            List <PollyLanguageDTO> result = new List <PollyLanguageDTO>();

            Dictionary <string, string> dicLanguages          = new Dictionary <string, string>();
            DescribeVoicesRequest       describeVoicesRequest = new DescribeVoicesRequest();

            String nextToken;

            do
            {
                DescribeVoicesResponse describeVoicesResponse = await pollyClient.DescribeVoicesAsync(describeVoicesRequest);

                nextToken = describeVoicesResponse.NextToken;
                describeVoicesRequest.NextToken = nextToken;

                foreach (var voice in describeVoicesResponse.Voices)
                {
                    // Console.WriteLine(" Name: {0}, Gender: {1}, LanguageName: {2}", voice.Name, voice.Gender, voice.LanguageName);
                    if (dicLanguages.ContainsKey(voice.LanguageCode) == false)
                    {
                        string   langaugeName = null;
                        string[] words        = voice.LanguageName.Split(' ');
                        if (words.Length > 1)
                        {
                            langaugeName = words[1] + ", " + words[0];
                        }
                        else
                        {
                            langaugeName = voice.LanguageName;
                        }

                        dicLanguages.Add(voice.LanguageCode, voice.LanguageName);
                        result.Add(new PollyLanguageDTO()
                        {
                            language_code = voice.LanguageCode,
                            language_name = langaugeName
                        });
                    }
                }
                ;
            } while (nextToken != null);

            result.Sort(delegate(PollyLanguageDTO x, PollyLanguageDTO y)
            {
                return(x.language_name.CompareTo(y.language_name));
            });

            return(result);
        }
        public static void DescribeVoices()
        {
            var client = new AmazonPollyClient();

            var allVoicesRequest  = new DescribeVoicesRequest();
            var enUsVoicesRequest = new DescribeVoicesRequest()
            {
                LanguageCode = "en-US"
            };

            try
            {
                String nextToken;
                do
                {
                    var allVoicesResponse = client.DescribeVoices(allVoicesRequest);
                    nextToken = allVoicesResponse.NextToken;
                    allVoicesRequest.NextToken = nextToken;

                    Console.WriteLine("All voices: ");
                    foreach (var voice in allVoicesResponse.Voices)
                    {
                        Console.WriteLine(" Name: {0}, Gender: {1}, LanguageName: {2}", voice.Name,
                                          voice.Gender, voice.LanguageName);
                    }
                } while (nextToken != null);

                do
                {
                    var enUsVoicesResponse = client.DescribeVoices(enUsVoicesRequest);
                    nextToken = enUsVoicesResponse.NextToken;
                    enUsVoicesRequest.NextToken = nextToken;

                    Console.WriteLine("en-US voices: ");
                    foreach (var voice in enUsVoicesResponse.Voices)
                    {
                        Console.WriteLine(" Name: {0}, Gender: {1}, LanguageName: {2}", voice.Name,
                                          voice.Gender, voice.LanguageName);
                    }
                } while (nextToken != null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught: " + e.Message);
            }
        }
        public static async Task Main()
        {
            var client = new AmazonPollyClient();

            var allVoicesRequest  = new DescribeVoicesRequest();
            var enUsVoicesRequest = new DescribeVoicesRequest()
            {
                LanguageCode = "en-US",
            };

            try
            {
                string nextToken;
                do
                {
                    var allVoicesResponse = await client.DescribeVoicesAsync(allVoicesRequest);

                    nextToken = allVoicesResponse.NextToken;
                    allVoicesRequest.NextToken = nextToken;

                    Console.WriteLine("\nAll voices: ");
                    allVoicesResponse.Voices.ForEach(voice =>
                    {
                        DisplayVoiceInfo(voice);
                    });
                }while (nextToken is not null);

                do
                {
                    var enUsVoicesResponse = await client.DescribeVoicesAsync(enUsVoicesRequest);

                    nextToken = enUsVoicesResponse.NextToken;
                    enUsVoicesRequest.NextToken = nextToken;

                    Console.WriteLine("\nen-US voices: ");
                    enUsVoicesResponse.Voices.ForEach(voice =>
                    {
                        DisplayVoiceInfo(voice);
                    });
                }while (nextToken is not null);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught: " + ex.Message);
            }
        }
Esempio n. 11
0
        public IList <Voice> GetVoicesForEngine(Engine engine)
        {
            var voicesReq = new DescribeVoicesRequest
            {
                Engine = engine,
            };

            var    voices = new List <Voice>();
            string nextToken;

            do
            {
                var voicesRes = this.client.DescribeVoicesAsync(voicesReq).GetAwaiter().GetResult();
                voices.AddRange(voicesRes.Voices);
                nextToken = voicesRes.NextToken;
            } while (!string.IsNullOrEmpty(nextToken));

            return(voices);
        }
Esempio n. 12
0
        public List <Voice> GetVoices(DescribeVoicesRequest request = null, int millisecondsTimeout = 20000)
        {
            LastException = null;
            var voices  = new List <Voice>();
            var timeout = true;
            var ts      = new System.Threading.ThreadStart(delegate()
            {
                request = request ?? new DescribeVoicesRequest();
                string nextToken;
                try
                {
                    do
                    {
                        var response      = Client.DescribeVoices(request);
                        nextToken         = response.NextToken;
                        request.NextToken = nextToken;
                        foreach (var voice in response.Voices)
                        {
                            voices.Add(voice);
                        }
                    } while (nextToken != null);
                }
                catch (Exception ex)
                {
                    LastException = ex;
                    Console.WriteLine(ex.ToString());
                    //OnEvent(Exception, ex);
                }
                timeout = false;
            });
            var t = new System.Threading.Thread(ts);

            t.Start();
            t.Join(millisecondsTimeout);
            if (timeout)
            {
                var timeoutEx = new Exception("AmmazonPolly.GetVoices timed out (" + millisecondsTimeout.ToString() + "ms)");
                LastException = timeoutEx;
                Console.WriteLine(timeoutEx.ToString());
                //OnEvent(Exception, ex);
            }
            return(voices);
        }
Esempio n. 13
0
        public static string GetVoices(ref QuestToSpeech.Voice[] voices, AwsAPIConfig config)
        {
            List <QuestToSpeech.Voice> list = new List <QuestToSpeech.Voice>();

            try {
                using (AmazonPollyClient client = new AmazonPollyClient(config.AccessKey, config.SecretKey, Amazon.RegionEndpoint.GetBySystemName(config.Region))) {
                    DescribeVoicesRequest req = new DescribeVoicesRequest();
                    string nextToken;

                    do
                    {
                        DescribeVoicesResponse res = client.DescribeVoices(req);
                        nextToken     = res.NextToken;
                        req.NextToken = nextToken;

                        foreach (var voice in res.Voices)
                        {
                            list.Add(new QuestToSpeech.Voice()
                            {
                                Name     = string.Format("{0}-{1}", voice.LanguageCode, voice.Id.ToString()),
                                Gender   = voice.Gender == Gender.Female ? QuestToSpeech.Gender.Female : QuestToSpeech.Gender.Male,
                                LangCode = voice.LanguageCode,
                                Module   = QuestToSpeech.Module.AWS
                            });
                        }
                    } while (nextToken != null);

                    list.Sort(delegate(QuestToSpeech.Voice v1, QuestToSpeech.Voice v2) {
                        return(v1.Name.CompareTo(v2.Name));
                    });

                    voices = list.ToArray();
                }
            } catch (Exception ex) {
                return(ex.InnerException == null ? ex.Message : ex.InnerException.ToString());
            }

            return(null);
        }
Esempio n. 14
0
        string GetVoices(RegionTaskSettings settings)
        {
            var reg     = settings.Region;
            var engine  = settings.Engine;
            var culture = settings.Culture;

            settings.Voices = new List <InstalledVoiceEx>();
            //var engine = reg.e
            AmazonPolly client = null;

            try
            {
                client = new AmazonPolly(
                    SettingsManager.Options.AmazonAccessKey,
                    SettingsManager.Options.AmazonSecretKey,
                    reg.SystemName
                    );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(ex.Message);
            }
            var request = new DescribeVoicesRequest();

            if (engine != null)
            {
                request.Engine = engine;
            }
            if (culture != null)
            {
                request.LanguageCode = culture.Name;
            }
            // Create stop watch to measure speed with the servers.
            var sw = new Stopwatch();

            sw.Start();
            var voices  = client.GetVoices(request, 5000);
            var elapsed = sw.Elapsed;

            if (client.LastException != null)
            {
                return(string.Format("Exception: {0}", client.LastException.Message));
            }
            var vex = 0;

            for (int v = 0; v < voices.Count; v++)
            {
                var voice        = voices[v];
                var cultureNames = new List <string>();
                cultureNames.Add(voice.LanguageCode);
                cultureNames.AddRange(voice.AdditionalLanguageCodes);
                // Add extra cultures.
                foreach (var cultureName in cultureNames)
                {
                    // Add engines.
                    var c = new CultureInfo(cultureName);
                    foreach (var engineName in voice.SupportedEngines)
                    {
                        var vx = new InstalledVoiceEx(voice);
                        vx.SetCulture(c);
                        vx.SourceRequestSpeed = elapsed;
                        var keys = System.Web.HttpUtility.ParseQueryString("");
                        keys.Add(InstalledVoiceEx._KeySource, vx.Source.ToString());
                        keys.Add(InstalledVoiceEx._KeyRegion, reg.SystemName);
                        keys.Add(InstalledVoiceEx._KeyCulture, cultureName);
                        keys.Add(InstalledVoiceEx._KeyEngine, engineName);
                        keys.Add(InstalledVoiceEx._KeyVoiceId, voice.Id);
                        vx.SourceKeys = keys.ToString();
                        // Override Description.
                        vx.Description = string.Format("{0}, {1}, {2}, {3}",
                                                       vx.Source, reg.DisplayName, cultureName, engineName);
                        // Add voice.
                        settings.Voices.Add(vx);
                        vex++;
                        if (_CancelGetVoices)
                        {
                            return("Cancelled");
                        }
                    }
                }
            }
            return(string.Format("Time (ms): {0,4}, Voices: {1,2}", (int)elapsed.Milliseconds, voices.Count));
        }