Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Test the Bot Using Speech Input (AWS CLI)

Focus mode
Test the Bot Using Speech Input (AWS CLI) - Amazon Lex V1

End of support notice: On September 15, 2025, AWS will discontinue support for Amazon Lex V1. After September 15, 2025, you will no longer be able to access the Amazon Lex V1 console or Amazon Lex V1 resources. If you are using Amazon Lex V2, refer to the Amazon Lex V2 guide instead. .

End of support notice: On September 15, 2025, AWS will discontinue support for Amazon Lex V1. After September 15, 2025, you will no longer be able to access the Amazon Lex V1 console or Amazon Lex V1 resources. If you are using Amazon Lex V2, refer to the Amazon Lex V2 guide instead. .

To test the bot using audio files, use the PostContent operation. You generate the audio files using Amazon Polly text-to-speech operations.

To run the commands in this exercise, you need to know the region the Amazon Lex and Amazon Polly commands will be run. For a list of regions for Amazon Lex, see Runtime Service Quotas. For a list of regions for Amazon Polly see AWS Regions and Endpoints in the Amazon Web Services General Reference.

Note

The following AWS CLI example is formatted for Unix, Linux, and macOS. For Windows, change "\$LATEST" to $LATEST and replace the backslash (\) continuation character at the end of each line with a caret (^).

To use a speech input to test the bot (AWS CLI)
  1. In the AWS CLI, create an audio file using Amazon Polly. The example is formatted for Unix, Linux, and macOS. For Windows, replace the backslash (\) Unix continuation character at the end of each line with a caret (^).

    aws polly synthesize-speech \ --region region \ --output-format pcm \ --text "i would like to order flowers" \ --voice-id "Salli" \ IntentSpeech.mpg
  2. To send the audio file to Amazon Lex, run the following command. Amazon Lex saves the audio from the response in the specified output file.

    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 responds with a request for the first slot. It saves the audio response in the specified output file.

    {
        "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?"
    }
  3. To order roses, create the following audio file and send it to 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
  4. To set the delivery date, create the following audio file and send it to 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
  5. To set the delivery time, create the following audio file and send it to 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
  6. To confirm the delivery, create the following audio file and send it to 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

    After you confirm the delivery, Amazon Lex sends a response that confirms fulfillment of the intent:

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

Next Step

Exercise 2: Add a New Utterance (AWS CLI)

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.