0

我有这个测试lambda function代码,每当我使用音频功能时,Amazon Lex我都会收到错误 -An error has occurred: Invalid SSML request (Service: AmazonParrot; Status Code: 400; Error Code: InvalidSsmlException

我的代码是:

def close(session_attributes, fulfillment_state, message):
    response = {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'Close',
            'fulfillmentState': fulfillment_state,
            'message': message
        }
    }

    return response

def testing(intent_request, outputDialogMode):

    slots = intent_request['currentIntent']['slots']
    name = slots['name']

    session_attributes = intent_request['sessionAttributes'] if 
    intent_request['sessionAttributes'] is not None else {}

    if outputDialogMode == 'Text':
        return close(
            session_attributes,
            'Fulfilled',
            {
                'contentType': 'PlainText',
                'content': 'Hi {}'.format(name)
            }
        )
    elif outputDialogMode == 'Voice':
        return close(
            session_attributes,
            'Fulfilled',
            {
                'contentType': 'SSML',
                'content': 'Hi {}'.format(name)
            }
        )

def dispatch(intent_request):
    """
    Called when the user specifies an intent for this bot.
    """
    logger.debug('input_request={}'.format(intent_request))



    intent_name = intent_request['currentIntent']['name']
    outputDialogMode = intent_request['outputDialogMode']

    # Dispatch to your bot's intent handlers
    if intent_name == 'testing':
        return testing(intent_request, outputDialogMode)


    raise Exception('Intent with name ' + intent_name + ' not supported')


# --- Main handler ---


def lambda_handler(event, context):
    """
    Route the incoming request based on intent.
    The JSON body of the request is provided in the event slot.
    """
    # By default, treat the user request as coming from the America/New_York time zone.
    os.environ['TZ'] = 'America/New_York'
    time.tzset()

    return dispatch(event)

根据本文档,支持的两个contentTypePlainTextSSML。当我输入我的输入时,它可以工作,但是当我说话时,它最后会抛出错误。可能是什么原因?

4

1 回答 1

1

语音响应中的Content必须采用SSML格式。

尝试将您的更改Content'<speak>Hi {}</speak>'.format(name).

于 2017-06-27T21:36:29.190 回答