static async Task Main()
        {
            polyClient = new AmazonPollyClient(serviceRegion);
            var response = await PollySynthesizeSpeech(polyClient, text);

            WriteSpeechToStream(response.AudioStream, outputFileName);
        }
        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);
        }
        public PollySpeechSynthesizer(IAmazonPolly amazonPolly, IOptions <PollySpeechSynthesizerConfiguration> configOptions)
        {
            if (configOptions != null && configOptions.Value != null)
            {
                voiceId = VoiceId.FindValue(configOptions.Value.VoiceId);
            }

            _amazonPolly = amazonPolly;
        }
 public TestController(DataContext context, IAmazonS3 s3Client,
                       IAmazonRekognition rekognitionClient, IAmazonTextract textractClient,
                       IAmazonPolly pollyClient, IAmazonTranscribeService transcribeClient)
 {
     _context               = context;
     this.S3Client          = s3Client;
     this.RekognitionClient = rekognitionClient;
     this.TextractClient    = textractClient;
     this.PollyClient       = pollyClient;
     this.TranscribeClient  = transcribeClient;
 }
 public StagesController(DataContext context,
                         IAmazonS3 s3Client, IAmazonRekognition rekognitionClient,
                         IAmazonTextract textractClient,
                         IAmazonPolly pollyClient)
 {
     _context               = context;
     this.S3Client          = s3Client;
     this.RekognitionClient = rekognitionClient;
     this.TextractClient    = textractClient;
     this.PollyClient       = pollyClient;
 }
Exemple #6
0
        //--- Constructors ---
        public Logic(IAmazonPolly pollyClient, IAmazonS3 s3Client, IAmazonSimpleNotificationService snsClient, IAmazonTranslate translateClient, ILogger logger, string s3BucketName, string notificationSnsTopic, HttpClient httpClient)
        {
            _pollyClient     = pollyClient ?? throw new ArgumentNullException(nameof(pollyClient));
            _s3Client        = s3Client ?? throw new ArgumentNullException(nameof(s3Client));
            _snsClient       = snsClient ?? throw new ArgumentNullException(nameof(snsClient));
            _translateClient = translateClient ?? throw new ArgumentNullException(nameof(translateClient));
            _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
            _httpClient      = httpClient ?? throw new ArgumentNullException(nameof(httpClient));

            // All the audio files should be stored here.  You can check it out in the Amazon S3 Console.
            _s3BucketName         = s3BucketName ?? throw new ArgumentNullException(nameof(s3BucketName));
            _notificationSnsTopic = notificationSnsTopic ?? throw new ArgumentNullException(nameof(notificationSnsTopic));
        }
        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);
        }
        /// <summary>
        /// Calls the Amazon Polly SynthesizeSpeechAsync method to convert text
        /// to speech.
        /// </summary>
        /// <param name="client">The Amazon Polly client object used to connect
        /// to the Amazon Polly service.</param>
        /// <param name="text">The text to convert to speech.</param>
        /// <returns>A SynthesizeSpeechResponse object that includes an AudioStream
        /// object with the converted text.</returns>
        private static async Task <SynthesizeSpeechResponse> PollySynthesizeSpeech(IAmazonPolly client, string text)
        {
            var synthesizeSpeechRequest = new SynthesizeSpeechRequest()
            {
                OutputFormat = OutputFormat.Mp3,
                VoiceId      = VoiceId.Joanna,
                Text         = text,
            };

            var synthesizeSpeechResponse =
                await client.SynthesizeSpeechAsync(synthesizeSpeechRequest);

            return(synthesizeSpeechResponse);
        }
 public AmazonPollyTextToSpeechProvider(Settings settings, IAmazonPolly awsPollyClient = null)
 {
     Settings        = settings;
     _awsPollyClient = awsPollyClient ??
                       new AmazonPollyClient(
         settings.AwsAccessKeyId,
         settings.AwsSecretAccessKey,
         new AmazonPollyConfig()
     {
         RegionEndpoint    = Amazon.RegionEndpoint.GetBySystemName(settings.AwsRegion),
         ThrottleRetries   = settings.ThrottleRetries,
         MaxErrorRetry     = (int)settings.MaxErrorRetries,
         UseNagleAlgorithm = settings.UseNagleAlgorithm
     }
         );
 }
        public async static Task <string> PollyDemo(IAmazonPolly pollyClient, IAmazonS3 S3Client, string text)
        {
            string result = null;
            SynthesizeSpeechRequest synthesizeRequest = new SynthesizeSpeechRequest()
            {
                LanguageCode = LanguageCode.EnUS,
                OutputFormat = "mp3",
                SampleRate   = "8000",
                Text         = text,
                TextType     = "text",
                VoiceId      = "Joanna"
            };

            try
            {
                Task <SynthesizeSpeechResponse> synthesizeTask    = pollyClient.SynthesizeSpeechAsync(synthesizeRequest);
                SynthesizeSpeechResponse        syntheizeResponse = await synthesizeTask;

                Console.WriteLine(syntheizeResponse.ContentType);
                Console.WriteLine(syntheizeResponse.RequestCharacters);

                using (MemoryStream ms = new MemoryStream())
                {
                    syntheizeResponse.AudioStream.CopyTo(ms);
                    Console.WriteLine(ms.Length);

                    // Upload image to S3 bucket
                    string bucketName = "reinvent-indiamazones";
                    //string key = dto.text;
                    string key = "pollytest";
                    await Task.Run(() => S3Util.UploadToS3(S3Client, bucketName, key, ms));

                    // TODO : need to check the file exists in S3
                    result = S3Util.GetPresignedURL(S3Client, bucketName, key);
                }
                //syntheizeResponse.AudioStream.CopyTo(result);
                //result.Flush();
            }
            catch (AmazonPollyException pollyException)
            {
                Console.WriteLine(pollyException.Message, pollyException.InnerException);
            }

            return(result);
        }
Exemple #11
0
        public AWSSpeechSynthesizer(IFileClient fileClient, IOptions <AWSCredentialOptions> awsCredentialOptions, IOptions <AWSTranslationOptions> translationOptions)
        {
            if (fileClient == null)
            {
                throw new ArgumentNullException(nameof(fileClient));
            }
            if (awsCredentialOptions == null)
            {
                throw new ArgumentNullException(nameof(awsCredentialOptions));
            }
            if (translationOptions == null)
            {
                throw new ArgumentNullException(nameof(translationOptions));
            }

            _fileClient         = fileClient;
            _pollyClient        = new AmazonPollyClient(new BasicAWSCredentials(awsCredentialOptions.Value.AccessKey, awsCredentialOptions.Value.SecretKey), RegionEndpoint.EUWest2);
            _translationOptions = translationOptions.Value;
        }
 private Amazon.Polly.Model.PutLexiconResponse CallAWSServiceOperation(IAmazonPolly client, Amazon.Polly.Model.PutLexiconRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Polly", "PutLexicon");
     try
     {
         #if DESKTOP
         return(client.PutLexicon(request));
         #elif CORECLR
         return(client.PutLexiconAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
Exemple #13
0
 public Polly(ILogger <Polly> logger, IAmazonPolly amazonPolly)
 {
     _logger      = logger;
     _amazonPolly = amazonPolly;
 }
 /// <summary>
 /// Default constructor that Lambda will invoke.
 /// </summary>
 public Function()
 {
     _dbClient    = new AmazonDynamoDBClient();
     _s3Client    = new AmazonS3Client();
     _pollyClient = new AmazonPollyClient();
 }
 /// <summary>
 /// A constructor with all the dependencies passed in
 /// for testing.
 /// </summary>
 /// <param name="dbClient"></param>
 public Function(IAmazonDynamoDB dbClient, IAmazonS3 s3Client, IAmazonPolly pollyClient)
 {
     _dbClient    = dbClient ?? throw new ArgumentNullException(nameof(dbClient));
     _s3Client    = s3Client ?? throw new ArgumentNullException(nameof(s3Client));
     _pollyClient = pollyClient ?? throw new ArgumentNullException(nameof(pollyClient));
 }
Exemple #16
0
 /// <summary>
 /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment
 /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the
 /// region the Lambda function is executed in.
 /// </summary>
 public Function()
 {
     _s3Client    = new AmazonS3Client();
     _pollyClient = new AmazonPollyClient(RegionEndpoint.EUWest1);
     _blazegraph  = new BlazegraphConnector(BLAZEGRAPH_ENDPOINT);
 }
Exemple #17
0
 internal PollyPaginatorFactory(IAmazonPolly client)
 {
     this.client = client;
 }
 //--- Methods ---
 public override async Task InitializeAsync(LambdaConfig config)
 {
     _s3Client    = new AmazonS3Client();
     _pollyClient = new AmazonPollyClient();
     _topicArn    = config.ReadText("StartPollyConversionCompleteSns");
 }
Exemple #19
0
 internal ListSpeechSynthesisTasksPaginator(IAmazonPolly client, ListSpeechSynthesisTasksRequest request)
 {
     this._client  = client;
     this._request = request;
 }
 public PollyService(IAmazonPolly polly)
 {
     Polly = polly;
 }