如何在使用Amazon Lex时让Amazon Polly说话并显示文本

时间:2017-06-20 22:12:09

标签: python amazon-lex amazon-polly

所以我陷入困境。我正在构建一个亚马逊Lex Bot,当让Amazon Polly以音频格式给出最终确认时,它只提供音频输出,但文本没有显示在Lex控制台上。

例如在我的python代码中这是一个最终的确认部分:

if outputDialogMode == 'Text':

    return close(
        session_attributes,
        'Fulfilled',
        {
            'contentType': 'PlainText',
            'content': 'Your reservation has been confirmed from"+str(start_time)+" to "+str(end_time)+". Your Booking ID is " + str(booking_id)
        }
    )
elif outputDialogMode == 'Voice':
    return close(
        session_attributes,
        'Fulfilled',
        {
            'contentType': 'SSML',
            'content': '<speak>Your reservation has been confirmed from"+str(start_time)+" to "+str(end_time)+". Your Booking ID is " + str(booking_id) +'</speak>'

        }
    )

现在,当我希望Lex以音频格式(content)输出outputDialogMode == 'Voice'时,它只会说出来并且不会在控制台上显示文本。有没有办法让它说话并同时显示文字?

注意:上面的代码只是我整个代码中输出消息的一部分。

1 个答案:

答案 0 :(得分:0)

在HTTP响应的message字段中返回文本响应。

如果您只对用于记录/调试目的的输出文本感兴趣,可以log the result并在CloudWatch中查看