Esempio n. 1
0
        public async Task <IEnumerable <TranslationOption> > GetTranslationsAsync(CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(GoogleTranslationOptionsRetriever)}.{nameof(GetTranslationsAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            var voices = await _client.ListVoicesAsync(new ListVoicesRequest(), cancellationToken);

            return(voices.Voices.Select(v => new TranslationOption(v.Name, TranslationType.Google)));
        }
        /// <summary>Snippet for ListVoicesAsync</summary>
        public async Task ListVoicesAsync()
        {
            // Snippet: ListVoicesAsync(string, CallSettings)
            // Additional: ListVoicesAsync(string, CancellationToken)
            // Create client
            TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();

            // Initialize request argument(s)
            string languageCode = "";
            // Make the request
            ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(languageCode);

            // End snippet
        }
        /// <summary>Snippet for ListVoicesAsync</summary>
        public async Task ListVoicesAsync_RequestObject()
        {
            // Snippet: ListVoicesAsync(ListVoicesRequest,CallSettings)
            // Additional: ListVoicesAsync(ListVoicesRequest,CancellationToken)
            // Create client
            TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();

            // Initialize request argument(s)
            ListVoicesRequest request = new ListVoicesRequest();
            // Make the request
            ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(request);

            // End snippet
        }
Esempio n. 4
0
        private async Task <List <SToSVoice> > FetchVoices(string language)
        {
            try
            {
                var voices = await voiceRepository.GetAllByService(WEB_SERVICE_ID);

                if (voices.Count == 0)
                {
                    var request  = new ListVoicesRequest();
                    var response = await toSpeechClient.ListVoicesAsync(request);

                    voiceCache = response.Voices.Select(voice =>
                                                        new SToSVoice
                    {
                        ServiceId  = WEB_SERVICE_ID,
                        Name       = voice.Name,
                        SsmlGender = voice.SsmlGender,
                        Gender     = voice.SsmlGender.ToString(),
                        Language   = string.Join(",", voice.LanguageCodes.ToArray())
                    }
                                                        ).ToList();
                    voiceRepository.InsertMultiple(voiceCache);
                }
                else
                {
                    voiceCache = voices;
                }
                return(voiceCache.Where(voice => voice.Language.Contains(language)).ToList());
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught: " + e);
                MessageBox.Show("Exception caught: " + e);
            }
            return(new List <SToSVoice>());
        }