如何接收用户发送给机器人的音频附件?

问题描述 投票:0回答:1

我在瀑布中添加了一个步骤来获取用户的附件,当用BotFramework模拟器测试时,我能够向机器人发送音频文件,并再次将同一文件回传给用户。

self.add_dialog(
        WaterfallDialog(
            WaterfallDialog.__name__,
            [
                self.project_step,
                self.name_step,
                self.description_step,
                **self.attachment_step**,
                self.confirm_step,
                self.final_step,
            ],
        )
    )

下面是附件步骤的代码。

async def attachment_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
    confluence_details = step_context.options

    # Capture the results of the previous step
    confluence_details.description = step_context.result
    message_text = "please add an attachment"
    prompt_options = PromptOptions(
        prompt=MessageFactory.text(
            "add an attachment"
        ),
        retry_prompt=MessageFactory.text(
            "The attachment must be a mp4/wav audio file."
        ),
    )


    return await step_context.prompt(AttachmentPrompt.__name__, prompt_options)





async def confirm_step(
    self, step_context: WaterfallStepContext
) -> DialogTurnResult:

    confluence_details = step_context.options

    confluence_details.audioFile = (
        None if not step_context.result else step_context.result[0]
    )
    if confluence_details.audioFile:
            await step_context.context.send_activity(
                MessageFactory.attachment(
                    confluence_details.audioFile, "This is your audio file."
                )
            )

@staticmethod
async def file_prompt_validator(prompt_context: PromptValidatorContext) -> bool:
    if not prompt_context.recognized.succeeded:
        await prompt_context.context.send_activity(
            "No attachments received. Proceeding without attachment..."
        )

        # We can return true from a validator function even if recognized.succeeded is false.
        return True

    attachments = prompt_context.recognized.value

    valid_file = [
        attachment
        for attachment in attachments
        if attachment.content_type in ["audio/mp3", "audio/mp4","audio/wav"]
    ]

    prompt_context.recognized.value = valid_file

    # If none of the attachments are valid images, the retry prompt should be sent.
    return len(valid_file) > 0

该代码在模拟器中工作正常。

我不明白的是,我如何从用户应用中发送一个音频文件到机器人上?

我可以在任何地方找到文件被发送的内容URL,其中包含文件所在的位置的URL.我无法接收从用户应用程序发送的文件到机器人。

我附上对话流程的截图供参考。converstaion flow

enter image description here

修改:-之前的问题已经解决了,我能够收到Base64编码的音频文件。我能够收到Base64编码的音频文件.问题是发送的JSON.在contentUrl中,它应该是一个附件数组.我的错。

编辑1:- 当试图发送一个base64编码的音频文件时,有些文件会出现错误。

{
    "error": {
        "code": "MessageSizeTooBig",
        "message": "Activity body too large for storage. Try using attachments to reduce the activity size."
    }
}

这到底是什么意思?

我可以看到,从这个 联系 有一个活动大小的上限.谁能建议最可行的方法来发送音频文件给机器人?

botframework azure-bot-service
1个回答
0
投票

当你得到一个错误,说 "消息大小太大",它的意思是什么,它说。当它建议你使用附件时,它的意思是链接到远程HTTPHTTPS位置的附件,而不是嵌入数据。你应该尝试上传文件,或者使用面向传输音频的服务,如 直线语音通道.

© www.soinside.com 2019 - 2024. All rights reserved.