スピーチマーク - Amazon Polly

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

スピーチマーク

次のコードサンプルは、Java ベースのアプリケーションを使用して入力テキストのスピーチマークを合成する方法を示しています。この機能は SynthesizeSpeech API を使用します。

この機能の詳細については、「スピーチマーク」を参照してください。

API の詳細については、SynthesizeSpeech API リファレンスを参照してください。

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); } } }