스피치 마크 - Amazon Polly

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

스피치 마크

다음 코드 샘플은 Java 기반 애플리케이션을 사용하여 입력된 텍스트의 스피치 마크를 합성하는 방법을 보여줍니다. 이 기능은 SynthesizeSpeech API를 사용합니다.

이 기능에 대한 자세한 내용은 스피치 마크을(를) 참조하세요.

해당 API에 대한 자세한 내용은 SynthesizeSpeech API 참조를 참조하세요.

/* 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); } } }
package com.amazonaws.polly.samples; import com.amazonaws.services.polly.AmazonPolly; import com.amazonaws.services.polly.AmazonPollyClientBuilder; import com.amazonaws.services.polly.model.OutputFormat; import com.amazonaws.services.polly.model.SpeechMarkType; import com.amazonaws.services.polly.model.SynthesizeSpeechRequest; import com.amazonaws.services.polly.model.SynthesizeSpeechResult; import com.amazonaws.services.polly.model.VoiceId; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; public class SynthesizeSpeechMarksSample { AmazonPolly client = AmazonPollyClientBuilder.defaultClient(); public void synthesizeSpeechMarks() { String outputFileName = "/tmp/speechMarks.json"; SynthesizeSpeechRequest synthesizeSpeechRequest = new SynthesizeSpeechRequest() .withOutputFormat(OutputFormat.Json) .withSpeechMarkTypes(SpeechMarkType.Viseme, SpeechMarkType.Word) .withVoiceId(VoiceId.Joanna) .withText("This is a sample text to be synthesized."); try (FileOutputStream outputStream = new FileOutputStream(new File(outputFileName))) { SynthesizeSpeechResult synthesizeSpeechResult = client.synthesizeSpeech(synthesizeSpeechRequest); byte[] buffer = new byte[2 * 1024]; int readBytes; try (InputStream in = synthesizeSpeechResult.getAudioStream()){ while ((readBytes = in.read(buffer)) > 0) { outputStream.write(buffer, 0, readBytes); } } } catch (Exception e) { System.err.println("Exception caught: " + e); } } }