Menu
Amazon Lex
Developer Guide

Test the Bot Using Speech Input (AWS CLI)

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

Note

The following AWS CLI example is formatted for Unix, Linux, and macOS. For Windows, change "\$LATEST" to $LATEST.

To use a speech input to test the bot (AWS CLI)

  1. In the AWS CLI, create an audio file using Amazon Polly:

    Copy
    aws polly synthesize-speech --output-format pcm --text "i would like to order flowers" --voice-id "Kendra" 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.

    Copy
    aws lex-runtime post-content --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 set the appointment type, create the following audio file and send it to Amazon Lex :

    Copy
    aws polly synthesize-speech --output-format pcm --text "roses" --voice-id "Kendra" FlowerTypeSpeech.mpg
    Copy
    aws lex-runtime post-content --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 appointment date, create the following audio file and send it to Amazon Lex:

    Copy
    aws polly synthesize-speech --output-format pcm --text "tuesday" --voice-id "Kendra" DateSpeech.mpg
    Copy
    aws lex-runtime post-content --bot-name OrderFlowersBot --bot-alias "\$LATEST" --user-id UserOne --content-type "audio/l16; rate=16000; channels=1" --input-stream DateSpeech.mpg DateOutputSpeech.mpg
  5. UTo set the appointment time, create the following audio file and send it to Amazon Lex:

    Copy
    aws polly synthesize-speech --output-format pcm --text "10:00 a.m." --voice-id "Kendra" TimeSpeech.mpg
    Copy
    aws lex-runtime post-content --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 appointment, create the following audio file and send it to Amazon Lex:

    Copy
    aws polly synthesize-speech --output-format pcm --text "yes" --voice-id "Kendra" ConfirmSpeech.mpg
    Copy
    aws lex-runtime post-content --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 appointment, 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: