

支援終止通知：2025 年 9 月 15 日， AWS 將停止對 Amazon Lex 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)


若要使用音訊檔案測試機器人，請使用 [PostContent](API_runtime_PostContent.md) 操作。您可以使用 Amazon Polly text-to-speech操作產生音訊檔案。

若要執行本練習中的命令，您需要知道要執行 Amazon Lex 和 Amazon Polly 命令的區域。如需 Amazon Lex 的區域清單，請參閱 [執行時間服務配額](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 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

   ```
   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"
       }
   }
   ```

## 後續步驟


[練習 2：新增表達用語 (AWS CLI)](gs-cli-update-utterance.md)