

サポート終了通知: 2025 年 9 月 15 日、 AWS は Amazon Lex V1 のサポートを終了します。 V1 2025 年 9 月 15 日を過ぎると、Amazon Lex V1 コンソールまたは Amazon Lex V1 リソースにはアクセスできなくなります。Amazon Lex V2 を使用している場合は、代わりに [Amazon Lex V2 ガイド](https://docs.aws.amazon.com/lexv2/latest/dg/what-is.html)を参照してください。

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

# 音声入力を使用してボットをテストする (AWS CLI)
<a name="gs-create-test-speech"></a>

音声ファイルを使用してボットをテストするには、[PostContent](API_runtime_PostContent.md) オペレーションを使用します。音声ファイルは、Amazon Polly テキスト読み上げ機能のオペレーションを使用して生成します。

この演習のコマンドを実行するには、Amazon Lex および Amazon Polly コマンドが実行されるリージョンを確認しておく必要があります。Amazon Lex のリージョンのリストについては「[ランタイム Service Quotas](gl-limits.md#gl-limits-runtime)」を参照してください。Amazon Polly でサポートされているリージョンとエンドポイントの一覧については、*Amazon Web Services 全般のリファレンス*の「[AWS リージョンとエンドポイント](https://docs.aws.amazon.com/general/latest/gr/rande.html#pol_region)」を参照してください。

**注記**  
次の AWS CLI 例は、Unix、Linux、macOS 用にフォーマットされています。Windows の場合は、`"\$LATEST"` を `$LATEST` に変更し、各行末のバックスラッシュ (\$1) 連結文字をキャレット (^) に置き換えてください。

**音声入力を使用してボットをテストするには (AWS CLI)**

1. で AWS CLI、Amazon Polly を使用してオーディオファイルを作成します。例は、Unix、Linux、および macOS 用にフォーマットされています。Windows の場合は、各行末のバックスラッシュ (\$1) Unix 連結文字をキャレット (^) に置き換えてください。

   ```
   aws polly synthesize-speech \
       --region region \
       --output-format pcm \
       --text "i would like to order flowers" \
       --voice-id "Salli" \
       IntentSpeech.mpg
   ```

1. 音声ファイルを Amazon Lex に送信するには、次のコマンドを実行します。Amazon Lex は、レスポンスの音声を指定の出力ファイルに保存します。

   ```
   aws lex-runtime post-content \
       --region region \
       --bot-name OrderFlowersBot \
       --bot-alias "\$LATEST" \
       --user-id UserOne \
       --content-type "audio/l16; rate=16000; channels=1" \
       --input-stream IntentSpeech.mpg \
       IntentOutputSpeech.mpg
   ```

   Amazon Lex は、レスポンスで最初のスロットをリクエストします。音声レスポンスは指定の出力ファイルに保存されます。

   ```
   {
       "contentType": "audio/mpeg", 
       "slotToElicit": "FlowerType", 
       "dialogState": "ElicitSlot", 
       "intentName": "OrderFlowers", 
       "inputTranscript": "i would like to order some flowers", 
       "slots": {
           "PickupDate": null, 
           "PickupTime": null, 
           "FlowerType": null
       }, 
       "message": "What type of flowers would you like to order?"
   }
   ```

1. バラの花束を注文するには、次の音声ファイルを作成して Amazon Lex に送信します。

   ```
   aws polly synthesize-speech \
       --region region \
       --output-format pcm \
       --text "roses" \
       --voice-id "Salli" \ 
       FlowerTypeSpeech.mpg
   ```

   ```
   aws lex-runtime post-content \
       --region region \
       --bot-name OrderFlowersBot \
       --bot-alias "\$LATEST" \
       --user-id UserOne \
       --content-type "audio/l16; rate=16000; channels=1" \
       --input-stream FlowerTypeSpeech.mpg \
       FlowerTypeOutputSpeech.mpg
   ```

1. 配達日を設定するには、次の音声ファイルを作成して Amazon Lex に送信します:

   ```
   aws polly synthesize-speech \
       --region region \
       --output-format pcm \
       --text "tuesday" \
       --voice-id "Salli" \ 
       DateSpeech.mpg
   ```

   ```
   aws lex-runtime post-content \
       --region region \
       --bot-name OrderFlowersBot \
       --bot-alias "\$LATEST" \
       --user-id UserOne \
       --content-type "audio/l16; rate=16000; channels=1" \
       --input-stream DateSpeech.mpg \
       DateOutputSpeech.mpg
   ```

1. 配送時間を設定するには、次の音声ファイルを作成して Amazon Lex に送信します:

   ```
   aws polly synthesize-speech \
       --region region \
       --output-format pcm \
       --text "10:00 a.m." \
       --voice-id "Salli" \
       TimeSpeech.mpg
   ```

   ```
   aws lex-runtime post-content \
       --region region \
       --bot-name OrderFlowersBot \
       --bot-alias "\$LATEST" \
       --user-id UserOne \
       --content-type "audio/l16; rate=16000; channels=1" \
       --input-stream TimeSpeech.mpg \
       TimeOutputSpeech.mpg
   ```

1. 配達を確認するには、次の音声ファイルを作成して Amazon Lex に送信します。

   ```
   aws polly synthesize-speech \
       --region region \
       --output-format pcm \
       --text "yes" \
       --voice-id "Salli" \
       ConfirmSpeech.mpg
   ```

   ```
   aws lex-runtime post-content \
       --region region \
       --bot-name OrderFlowersBot \
       --bot-alias "\$LATEST" \
       --user-id UserOne \
       --content-type "audio/l16; rate=16000; channels=1" \
       --input-stream ConfirmSpeech.mpg \
       ConfirmOutputSpeech.mpg
   ```

   配達を確認すると、Amazon Lex からインテントの達成を確認するレスポンスが送信されます。

   ```
   {
       "contentType": "text/plain;charset=utf-8", 
       "dialogState": "ReadyForFulfillment", 
       "intentName": "OrderFlowers", 
       "inputTranscript": "yes", 
       "slots": {
           "PickupDate": "2017-05-16", 
           "PickupTime": "10:00", 
           "FlowerType": "roses"
       }
   }
   ```

## 次のステップ
<a name="gs-cli-next-exercise-2"></a>

[演習 2: 新しい発話を追加する (AWS CLI)](gs-cli-update-utterance.md)