AWS polly documentation change
Summary
Added Java V2 code example demonstrating asynchronous speech synthesis with polling
Security assessment
The change adds a code sample for long-running synthesis tasks with S3 output and SNS notifications. While the example includes sensitive resources (S3 bucket, SNS topic), there's no security guidance or vulnerability fixes shown - just normal API usage patterns.
Diff
diff --git a/polly/latest/dg/StartSpeechSynthesisTask.md b/polly/latest/dg/StartSpeechSynthesisTask.md index d4207bce0..d9a8c515c 100644 --- a//polly/latest/dg/StartSpeechSynthesisTask.md +++ b//polly/latest/dg/StartSpeechSynthesisTask.md @@ -11,0 +12,79 @@ For more information, see the reference for [`StartSpeechSynthesisTask`](https:/ + /* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + SPDX-License-Identifier: Apache-2.0 + */ + + package com.example.polly; + + import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; + import software.amazon.awssdk.regions.Region; + import software.amazon.awssdk.services.polly.PollyClient; + import software.amazon.awssdk.services.polly.model.*; + + import java.time.Duration; + import org.awaitility.Durations; + import org.awaitility.Awaitility; + + /** + * Before running this Java V2 code example, set up your development environment, including your credentials. + * + * For more information, see the following documentation topic: + * + * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html + */ + public class StartSpeechSynthesisTaskSample { + + public static void main(String args[]) { + + PollyClient polly = PollyClient.builder() + .region(Region.US_WEST_2) + .credentialsProvider(ProfileCredentialsProvider.create()) + .build(); + + startSpeechSynthesisTask(polly) ; + polly.close(); + } + + private static final String PLAIN_TEXT = "This is a sample text to be synthesized."; + private static final String OUTPUT_FORMAT_MP3 = OutputFormat.MP3.toString(); + private static final String OUTPUT_BUCKET = "synth-books-buckets"; + private static final String SNS_TOPIC_ARN = "arn:aws:sns:eu-west-2:123456789012:synthesize-finish-topic"; + private static final Duration SYNTHESIS_TASK_POLL_INTERVAL = Durations.FIVE_SECONDS; + private static final Duration SYNTHESIS_TASK_POLL_DELAY = Durations.TEN_SECONDS; + private static final Duration SYNTHESIS_TASK_TIMEOUT = Durations.FIVE_MINUTES; + public static void startSpeechSynthesisTask(PollyClient client) { + + try { + StartSpeechSynthesisTaskRequest startSpeechSynthesisTaskRequest = StartSpeechSynthesisTaskRequest.builder() + .outputFormat(OUTPUT_FORMAT_MP3).text(PLAIN_TEXT).textType(TextType.TEXT) + .voiceId(VoiceId.AMY).outputS3BucketName(OUTPUT_BUCKET).snsTopicArn(SNS_TOPIC_ARN) + .engine("neural").build(); + + StartSpeechSynthesisTaskResponse startSpeechSynthesisTaskResponse = + client.startSpeechSynthesisTask(startSpeechSynthesisTaskRequest); + String taskId = startSpeechSynthesisTaskResponse.synthesisTask().taskId(); + + Awaitility.await().with() + .pollInterval(SYNTHESIS_TASK_POLL_INTERVAL) + .pollDelay(SYNTHESIS_TASK_POLL_DELAY) + .atMost(SYNTHESIS_TASK_TIMEOUT) + .until( + () -> getSynthesisTaskStatus(client, taskId).equals(TaskStatus.COMPLETED.toString()) + ); + + } catch (PollyException e) { + System.err.println("Exception caught: " + e); + System.exit(1); + } + } + + private static String getSynthesisTaskStatus(PollyClient client, String taskId) { + GetSpeechSynthesisTaskRequest getSpeechSynthesisTaskRequest = GetSpeechSynthesisTaskRequest.builder() + .taskId(taskId).build(); + GetSpeechSynthesisTaskResponse result = client.getSpeechSynthesisTask(getSpeechSynthesisTaskRequest); + return result.synthesisTask().taskStatusAsString(); + } + + } + +