本文介绍了使用Python将音频文件发送到DialogFlow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过以下方式使用Python将数据(在这种情况下为Text)发送到DialogFlow:

I know that I can send data (Text in this case) to DialogFlow by using Python in the following way:

ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN)
request = ai.text_request()
request.lang = 'de'  # optional, default value equal 'en'
request.session_id = "<SESSION ID, UNIQUE FOR EACH USER>"
request.query = "Hello"
response = request.getresponse()
print (response.read())

但是我不确定是否可以将音频文件发送到DialogFlow,有人知道吗?

But I'm not sure if I could send an audio file to DialogFlow, does anyone know about that?

推荐答案

在Google Action/Dialogflow响应中使用音频文件有两种方法:带<audio>标签的SSML和媒体"响应.两者都希望通过HTTPS URL提供音频文件,该文件本身通常存储在Google Cloud Storage或Amazon S3之类的云存储服务中.

There are two ways to use audio files in Google Action/Dialogflow responses: SSML with the <audio> tag and Media responses. Both expect the audio file to be provided via a HTTPS URL, the file itself is usually stored in a cloud storage service like Google Cloud Storage or Amazon S3.

SSML(语音合成标记语言)是用于音频输出的标记语言,就像HTML用于视觉输出一样.它受Google Actions支持,可以用作常规文本响应的替代品,而不是像这样包含响应文本:

SSML (Speech Synthesis Markup Language) is a markup language for audio output, just like HTML is for visual output. It is supported by Google Actions and can be used as drop-in replacement for the normal text response Instead of including the response text like this:

{
    "speech": "This is the text that the users hears",
    ...
}

您将使用SSML对其进行标记,如下所示:

you would mark it up with SSML like this:

{
    "speech": "<speak><audio src="https://some_cloud_storage.com/my_audio_file.ogg"></audio></speak>",
    ...
}

请注意,<speak>标签必须始终围绕整个响应,以便Google现在必须使用SSML呈现文本(就像网站上的<html>标签一样). <audio>标记可以具有几个可选属性,有关详细信息,请参见文档.

Note that the <speak> tags must always surround the entire response so that Google nows that it has to render the text with SSML (just like the <html> tag on websites). The <audio> tag can take several optional attributes, see the documentation for details.

SSML的优势是非常易于您作为开发人员使用,但是音频文件的长度限制为120秒,文件大小为5MB,并且无法为用户提供播放控制.

SSML has the benefit of being very easy to use for you as the developer, but the audio files are limited to a length of 120 seconds and a file size of 5MB and it gives the user no playback control.

媒体回复没有上述限制,并显示为卡片带有图片和播放控件,但它们目前仅在Google Home和Android设备上运行.

Media responses do not have theses limits and are displayed as a card with an image and playback controls, but they currently work only on Google Home and Android devices.

这篇关于使用Python将音频文件发送到DialogFlow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 14:57