AWS polly documentation change
Summary
Added Java code sample for synthesizing speech marks with AWS Polly
Security assessment
The change adds a code example for using Polly's speech marks feature. No security vulnerabilities or security features are mentioned or addressed in the code sample.
Diff
diff --git a/polly/latest/dg/SynthesizeSpeechMarksSample.md b/polly/latest/dg/SynthesizeSpeechMarksSample.md index 43b403723..d6b48b3f2 100644 --- a//polly/latest/dg/SynthesizeSpeechMarksSample.md +++ b//polly/latest/dg/SynthesizeSpeechMarksSample.md @@ -13,0 +14,72 @@ For more information on the API, see the reference for [`SynthesizeSpeech`](http + /* + 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.core.ResponseInputStream; + import software.amazon.awssdk.regions.Region; + import software.amazon.awssdk.services.polly.PollyClient; + import software.amazon.awssdk.services.polly.model.*; + + import java.io.File; + import java.io.FileOutputStream; + import java.io.InputStream; + + /** + * 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 SpeechMarksSample { + + public static void main(String args[]) { + + PollyClient polly = PollyClient.builder() + .region(Region.US_WEST_2) + .credentialsProvider(ProfileCredentialsProvider.create()) + .build(); + + speechMarksSample(polly) ; + polly.close(); + } + + private static final String OUTPUT_FILE = "./speechMarks.json"; + public static void speechMarksSample(PollyClient client) { + + try { + SynthesizeSpeechRequest speechMarksSampleRequest = SynthesizeSpeechRequest.builder() + .outputFormat(OutputFormat.JSON) + .speechMarkTypes(SpeechMarkType.VISEME, SpeechMarkType.WORD) + .voiceId(VoiceId.JOANNA) + .text("This is a sample text to be synthesized") + .build(); + try (FileOutputStream outputStream = new FileOutputStream(new File(OUTPUT_FILE))) { + ResponseInputStream<SynthesizeSpeechResponse> synthesizeSpeechResponse = client + .synthesizeSpeech(speechMarksSampleRequest); + byte[] buffer = new byte[2 * 1024]; + int readBytes; + + try (InputStream in = synthesizeSpeechResponse){ + while ((readBytes = in.read(buffer)) > 0) { + outputStream.write(buffer, 0, readBytes); + } + } + } catch (Exception e) { + System.err.println("Exception caught: " + e); + } + + } catch (PollyException e) { + System.err.println("Exception caught: " + e); + System.exit(1); + } + } + + } + + +