Cookie の設定を選択する

当社は、当社のサイトおよびサービスを提供するために必要な必須 Cookie および類似のツールを使用しています。当社は、パフォーマンス Cookie を使用して匿名の統計情報を収集することで、お客様が当社のサイトをどのように利用しているかを把握し、改善に役立てています。必須 Cookie は無効化できませんが、[カスタマイズ] または [拒否] をクリックしてパフォーマンス Cookie を拒否することはできます。

お客様が同意した場合、AWS および承認された第三者は、Cookie を使用して便利なサイト機能を提供したり、お客様の選択を記憶したり、関連する広告を含む関連コンテンツを表示したりします。すべての必須ではない Cookie を受け入れるか拒否するには、[受け入れる] または [拒否] をクリックしてください。より詳細な選択を行うには、[カスタマイズ] をクリックしてください。

Android の例

フォーカスモード
Android の例 - Amazon Polly

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

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

次の例では、Android SDK for Amazon Polly を使用して、音声のリストから選択された音声で指定されたテキストを読み上げます。

ここに示すコードは、主要なタスクを実行するものであり、エラーは処理しません。完全なコードについては、AWS Mobile SDK for Android Amazon Polly のデモを参照してください。

Initialize

// Cognito pool ID. Pool needs to be unauthenticated pool with // Amazon Polly permissions. String COGNITO_POOL_ID = "YourCognitoIdentityPoolId"; // Region of Amazon Polly. Regions MY_REGION = Regions.US_EAST_1;   // Initialize the Amazon Cognito credentials provider. CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(         getApplicationContext(),         COGNITO_POOL_ID,         MY_REGION ); // Create a client that supports generation of presigned URLs. AmazonPollyPresigningClient client = new AmazonPollyPresigningClient(credentialsProvider);
使用可能な音声のリストの取得

// Create describe voices request. DescribeVoicesRequest describeVoicesRequest = new DescribeVoicesRequest(); // Synchronously ask Amazon Polly to describe available TTS voices. DescribeVoicesResult describeVoicesResult = client.describeVoices(describeVoicesRequest); List<Voice> voices = describeVoicesResult.getVoices();
音声ストリームの URL の取得

// Create speech synthesis request. SynthesizeSpeechPresignRequest synthesizeSpeechPresignRequest =         new SynthesizeSpeechPresignRequest()         // Set the text to synthesize.         .withText("Hello world!")         // Select voice for synthesis.         .withVoiceId(voices.get(0).getId()) // "Joanna"         // Set format to MP3.         .withOutputFormat(OutputFormat.Mp3); // Get the presigned URL for synthesized speech audio stream. URL presignedSynthesizeSpeechUrl =         client.getPresignedSynthesizeSpeechUrl(synthesizeSpeechPresignRequest);
合成された音声の再生

// Use MediaPlayer: https://developer.android.com/guide/topics/media/mediaplayer.html // Create a media player to play the synthesized audio stream. MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try {     // Set media player's data source to previously obtained URL.     mediaPlayer.setDataSource(presignedSynthesizeSpeechUrl.toString()); } catch (IOException e) {     Log.e(TAG, "Unable to set data source for the media player! " + e.getMessage()); } // Prepare the MediaPlayer asynchronously (since the data source is a network stream). mediaPlayer.prepareAsync(); // Set the callback to start the MediaPlayer when it's prepared. mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {     @Override     public void onPrepared(MediaPlayer mp) {         mp.start();     } }); // Set the callback to release the MediaPlayer after playback is completed. mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } });
プライバシーサイト規約Cookie の設定
© 2025, Amazon Web Services, Inc. or its affiliates.All rights reserved.