使用语音输入测试自动程序 (AWS CLI) - Amazon Lex V1

如果您使用的是 Amazon Lex V2,请改为参阅 Amazon Lex V2 指南

 

如果您使用的是 Amazon Lex V1,我们建议您将机器人升级到 Amazon Lex V2。我们不再向 V1 添加新功能,强烈建议使用 V2 以获得全新的机器人。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用语音输入测试自动程序 (AWS CLI)

要使用音频文件测试自动程序,请使用 PostContent 操作。您可以使用 Amazon Polly 文本到语音转换操作生成音频文件。

要运行本练习中的命令,您需要知道将在其中运行 Amazon Lex 和 Amazon Polly 命令的区域。有关 Amazon Lex 区域的列表,请参阅运行时服务配额。有关 Amazon Polly 区域的列表,请参阅《Amazon Web Services 一般参考》中的 AWS 区域和端点

注意

以下 AWS CLI 示例针对 Linux、Unix 和 macOS 编排了格式。对于 Windows,请将 "\$LATEST" 更改为 $LATEST 并将每行末尾的反斜杠 (\) 继续符替换为脱字号 (^)。

使用语音输入测试自动程序 (AWS CLI)
  1. 在 AWS CLI 中,使用 Amazon Polly 创建一个音频文件。此示例的格式适用于 Unix、Linux 和 macOS。对于 Windows,请将每行末尾的反斜杠 (\) Unix 行继续符替换为脱字号 (^)。

    aws polly synthesize-speech \ --region region \ --output-format pcm \ --text "i would like to order flowers" \ --voice-id "Salli" \ IntentSpeech.mpg
  2. 要将音频文件发送到 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?"
    }
  3. 要订购玫瑰,请创建以下音频文件并将其发送给 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. 要设置送货日期,请创建以下音频文件并将其发送给 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. 要设置送货时间,请创建以下音频文件并将其发送给 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. 要确认送货,请创建以下音频文件并将其发送给 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)