Ejemplo n.º 1
0
        /// <summary>
        /// Allows the creation of an asynchronous synthesis task, by starting a new <code>SpeechSynthesisTask</code>.
        /// This operation requires all the standard information needed for speech synthesis,
        /// plus the name of an Amazon S3 bucket for the service to store the output of the synthesis
        /// task and two optional parameters (OutputS3KeyPrefix and SnsTopicArn). Once the synthesis
        /// task is created, this operation will return a SpeechSynthesisTask object, which will
        /// include an identifier of this task as well as the current status.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the StartSpeechSynthesisTask service method.</param>
        ///
        /// <returns>The response from the StartSpeechSynthesisTask service method, as returned by Polly.</returns>
        /// <exception cref="Amazon.Polly.Model.InvalidS3BucketException">
        /// The provided Amazon S3 bucket name is invalid. Please check your input with S3 bucket
        /// naming requirements and try again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidS3KeyException">
        /// The provided Amazon S3 key prefix is invalid. Please provide a valid S3 object key
        /// name.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidSampleRateException">
        /// The specified sample rate is not valid.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidSnsTopicArnException">
        /// The provided SNS topic ARN is invalid. Please provide a valid SNS topic ARN and try
        /// again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidSsmlException">
        /// The SSML you provided is invalid. Verify the SSML syntax, spelling of tags and values,
        /// and then try again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.LexiconNotFoundException">
        /// Amazon Polly can't find the specified lexicon. This could be caused by a lexicon that
        /// is missing, its name is misspelled or specifying a lexicon that is in a different
        /// region.
        ///
        ///
        /// <para>
        /// Verify that the lexicon exists, is in the region (see <a>ListLexicons</a>) and that
        /// you spelled its name is spelled correctly. Then try again.
        /// </para>
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.MarksNotSupportedForFormatException">
        /// Speech marks are not supported for the <code>OutputFormat</code> selected. Speech
        /// marks are only available for content in <code>json</code> format.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.ServiceFailureException">
        /// An unknown condition has caused a service failure.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.SsmlMarksNotSupportedForTextTypeException">
        /// SSML speech marks are not supported for plain text-type input.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.TextLengthExceededException">
        /// The value of the "Text" parameter is longer than the accepted limits. For the <code>SynthesizeSpeech</code>
        /// API, the limit for input text is a maximum of 6000 characters total, of which no more
        /// than 3000 can be billed characters. For the <code>SetSpeechSynthesisTask</code> API,
        /// the maximum is 200,000 characters, of which no more than 100,000 can be billed characters.
        /// SSML tags are not counted as billed characters.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/polly-2016-06-10/StartSpeechSynthesisTask">REST API Reference for StartSpeechSynthesisTask Operation</seealso>
        public virtual StartSpeechSynthesisTaskResponse StartSpeechSynthesisTask(StartSpeechSynthesisTaskRequest request)
        {
            var marshaller   = StartSpeechSynthesisTaskRequestMarshaller.Instance;
            var unmarshaller = StartSpeechSynthesisTaskResponseUnmarshaller.Instance;

            return(Invoke <StartSpeechSynthesisTaskRequest, StartSpeechSynthesisTaskResponse>(request, marshaller, unmarshaller));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initiates the asynchronous execution of the StartSpeechSynthesisTask operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the StartSpeechSynthesisTask 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 EndStartSpeechSynthesisTask
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/polly-2016-06-10/StartSpeechSynthesisTask">REST API Reference for StartSpeechSynthesisTask Operation</seealso>
        public virtual IAsyncResult BeginStartSpeechSynthesisTask(StartSpeechSynthesisTaskRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = StartSpeechSynthesisTaskRequestMarshaller.Instance;
            var unmarshaller = StartSpeechSynthesisTaskResponseUnmarshaller.Instance;

            return(BeginInvoke <StartSpeechSynthesisTaskRequest>(request, marshaller, unmarshaller,
                                                                 callback, state));
        }
Ejemplo n.º 3
0
        internal virtual StartSpeechSynthesisTaskResponse StartSpeechSynthesisTask(StartSpeechSynthesisTaskRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = StartSpeechSynthesisTaskRequestMarshaller.Instance;
            options.ResponseUnmarshaller = StartSpeechSynthesisTaskResponseUnmarshaller.Instance;

            return(Invoke <StartSpeechSynthesisTaskResponse>(request, options));
        }
Ejemplo n.º 4
0
        public static async Task <string> SynthesizeAudioAsync(string article, string title)
        {
            AmazonPollyClient apc = new AmazonPollyClient(Secret.AWSAccessKey, Secret.AWSSecretKey, Amazon.RegionEndpoint.USEast1);
            StartSpeechSynthesisTaskRequest req = new StartSpeechSynthesisTaskRequest();

            req.Engine             = "neural";
            req.OutputFormat       = "mp3";
            req.OutputS3BucketName = "lrnr-neural";
            req.Text    = article;
            req.VoiceId = "Matthew";

            StartSpeechSynthesisTaskResponse response = await apc.StartSpeechSynthesisTaskAsync(req);

            return(response.SynthesisTask.OutputUri);
        }
Ejemplo n.º 5
0
        private async Task QueueText(string text, int index, AWSSpeechRequest request, AWSSpeechResult result)
        {
            var synthesizeSpeechRequest = new StartSpeechSynthesisTaskRequest
            {
                OutputFormat       = request.OutputFormat,
                VoiceId            = request.VoiceId,
                Text               = text,
                OutputS3BucketName = _translationOptions.Bucket,
                OutputS3KeyPrefix  = Guid.NewGuid().ToString()
            };

            var response = await _pollyClient.StartSpeechSynthesisTaskAsync(synthesizeSpeechRequest);

            using (var waitHandle = new AutoResetEvent(false))
                using (new Timer(
                           callback: async(e) => { await CheckSynthesisTask(response.SynthesisTask.TaskId, waitHandle); },
                           state: null,
                           dueTime: TimeSpan.Zero,
                           period: TimeSpan.FromSeconds(_translationOptions.PollRate)
                           )
                       )
                {
                    waitHandle.WaitOne();
                }

            var task = await _pollyClient.GetSpeechSynthesisTaskAsync(new GetSpeechSynthesisTaskRequest { TaskId = response.SynthesisTask.TaskId });

            if (task.SynthesisTask.TaskStatus == Amazon.Polly.TaskStatus.Failed)
            {
                throw new InvalidOperationException();
            }

            var key        = task.SynthesisTask.OutputUri.Split('/').Last();
            var fileResult = await _fileClient.DownloadAsync(key, "");

            using (var stream = await fileResult.OpenStreamAsync())
            {
                await result.DigestBytes(index, stream);
            }

            if (request.CallBack != null)
            {
                await request.CallBack(text.Length);
            }

            await _fileClient.DeleteAsync(key, "");
        }
Ejemplo n.º 6
0
        public override async Task ProcessMessageAsync(QueueEvent queueEvent)
        {
            LogInfo($"queueEvent {JsonConvert.SerializeObject(queueEvent)}");

            if (queueEvent.Event != null)
            {
                LogInfo($"testEvent {JsonConvert.SerializeObject(queueEvent)}");
                return;
            }

            // read results from s3 bucket
            var bucket              = queueEvent.Records.FirstOrDefault()?.S3.Bucket.Name;
            var plaintextFile       = queueEvent.Records.FirstOrDefault()?.S3.Object.Key;
            var jobId               = plaintextFile.Split('/')[1];
            var getPlaintextRequest = new GetObjectRequest {
                Key        = plaintextFile,
                BucketName = bucket
            };
            var getPlaintextResponse = await _s3Client.GetObjectAsync(getPlaintextRequest);

            var plaintextList = new List <string>();

            using (var streamReader = new StreamReader(getPlaintextResponse.ResponseStream)) {
                plaintextList = (streamReader.ReadToEnd()).SplitInParts(100000).ToList();
            }
            LogInfo($"plaintextList {JsonConvert.SerializeObject(plaintextList)}");

            foreach (var plaintextString in plaintextList)
            {
                // send text to polly
                var startPollyRequest = new StartSpeechSynthesisTaskRequest {
                    Text               = plaintextString,
                    VoiceId            = VoiceId.Kendra,
                    OutputFormat       = OutputFormat.Mp3,
                    OutputS3BucketName = bucket,
                    OutputS3KeyPrefix  = $"mp3/{jobId}/",
                    SnsTopicArn        = _topicArn
                };
                var response = await _pollyClient.StartSpeechSynthesisTaskAsync(startPollyRequest);

                LogInfo($"response {JsonConvert.SerializeObject(response)}");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Allows the creation of an asynchronous synthesis task, by starting a new <code>SpeechSynthesisTask</code>.
        /// This operation requires all the standard information needed for speech synthesis,
        /// plus the name of an Amazon S3 bucket for the service to store the output of the synthesis
        /// task and two optional parameters (OutputS3KeyPrefix and SnsTopicArn). Once the synthesis
        /// task is created, this operation will return a SpeechSynthesisTask object, which will
        /// include an identifier of this task as well as the current status.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the StartSpeechSynthesisTask 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 StartSpeechSynthesisTask service method, as returned by Polly.</returns>
        /// <exception cref="Amazon.Polly.Model.EngineNotSupportedException">
        /// This engine is not compatible with the voice that you have designated. Choose a new
        /// voice that is compatible with the engine or change the engine and restart the operation.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidS3BucketException">
        /// The provided Amazon S3 bucket name is invalid. Please check your input with S3 bucket
        /// naming requirements and try again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidS3KeyException">
        /// The provided Amazon S3 key prefix is invalid. Please provide a valid S3 object key
        /// name.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidSampleRateException">
        /// The specified sample rate is not valid.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidSnsTopicArnException">
        /// The provided SNS topic ARN is invalid. Please provide a valid SNS topic ARN and try
        /// again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.InvalidSsmlException">
        /// The SSML you provided is invalid. Verify the SSML syntax, spelling of tags and values,
        /// and then try again.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.LanguageNotSupportedException">
        /// The language specified is not currently supported by Amazon Polly in this capacity.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.LexiconNotFoundException">
        /// Amazon Polly can't find the specified lexicon. This could be caused by a lexicon that
        /// is missing, its name is misspelled or specifying a lexicon that is in a different
        /// region.
        ///
        ///
        /// <para>
        /// Verify that the lexicon exists, is in the region (see <a>ListLexicons</a>) and that
        /// you spelled its name is spelled correctly. Then try again.
        /// </para>
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.MarksNotSupportedForFormatException">
        /// Speech marks are not supported for the <code>OutputFormat</code> selected. Speech
        /// marks are only available for content in <code>json</code> format.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.ServiceFailureException">
        /// An unknown condition has caused a service failure.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.SsmlMarksNotSupportedForTextTypeException">
        /// SSML speech marks are not supported for plain text-type input.
        /// </exception>
        /// <exception cref="Amazon.Polly.Model.TextLengthExceededException">
        /// The value of the "Text" parameter is longer than the accepted limits. For the <code>SynthesizeSpeech</code>
        /// API, the limit for input text is a maximum of 6000 characters total, of which no more
        /// than 3000 can be billed characters. For the <code>StartSpeechSynthesisTask</code>
        /// API, the maximum is 200,000 characters, of which no more than 100,000 can be billed
        /// characters. SSML tags are not counted as billed characters.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/polly-2016-06-10/StartSpeechSynthesisTask">REST API Reference for StartSpeechSynthesisTask Operation</seealso>
        public virtual Task <StartSpeechSynthesisTaskResponse> StartSpeechSynthesisTaskAsync(StartSpeechSynthesisTaskRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = StartSpeechSynthesisTaskRequestMarshaller.Instance;
            options.ResponseUnmarshaller = StartSpeechSynthesisTaskResponseUnmarshaller.Instance;

            return(InvokeAsync <StartSpeechSynthesisTaskResponse>(request, options, cancellationToken));
        }