如何从 DialogFlow webhook 访问 Firebase 存储中的音频文件
How to access an audio file from Firebase Storage from DialogFlow webhook
我可以使用以下内容从我的 DialogFlow fulfillment 内联编辑器 webhook 播放声音。
function saySSML (request, response) {
const app = new DialogflowApp({request: request, response: response});
const textToSpeech = '<speak>'
+ 'I can play a sound'
+ '<audio src="https://actions.google.com/sounds/v1/animals/animal_bark_and_growl.ogg">a digital watch alarm</audio>'
+ '</speak>';
app.ask(textToSpeech);
}
但是,我不知道如何在 Firebase 存储中播放音频文件。我已尝试将音频 url 替换为文件的存储位置以及 DownloadUrl1 url,如单击 Firebase 存储中的文件时所示。
我还查看了根据 https://firebase.google.com/docs/storage/web/create-reference 创建存储参考
但是当我添加对存储服务的引用时,出现 'firebase not defined' 错误。
function saySSML (request, response) {
const app = new DialogflowApp({request: request, response: response});
// Get a reference to the storage service, which is used to create references in your storage bucket
var storage = firebase.storage();
// Create a storage reference from our storage service
var storageRef = storage.ref();
const textToSpeech = '<speak>'
+ 'I can play a sound'
+ '<audio src="https://firebasestorage.googleapis.com/v0/b/andrewdittmer-c301f.appspot.com/o/alarm_clock.ogg?alt=media&token=d66a4055-5365-4061-b50d-0b6a126841f3">a digital watch alarm</audio>'
+ '</speak>';
app.ask(textToSpeech);
}
有没有人能成功做到这一点?
感谢您的帮助/指点。
Google 助手的 SSML 解析器非常严格。 URL 中的 &
需要转义,因此结果应该是 &
。该行可能看起来像这样:
+ '<audio src="https://firebasestorage.googleapis.com/v0/b/andrewdittmer-c301f.appspot.com/o/alarm_clock.ogg?alt=media&token=d66a4055-5365-4061-b50d-0b6a126841f3">a digital watch alarm</audio>'
或者,如果您已经在使用 Firebase,并且您的音频资产是静态的,您可能希望将音频存储在 Firebase Hosting。
我需要使用非常具体的音频编码设置,如指定的那样here。
The audio must contain a single channel (mono) of μ-law encoded audio at 8kHz and be hosted on Cloud Storage.
我可以使用以下内容从我的 DialogFlow fulfillment 内联编辑器 webhook 播放声音。
function saySSML (request, response) {
const app = new DialogflowApp({request: request, response: response});
const textToSpeech = '<speak>'
+ 'I can play a sound'
+ '<audio src="https://actions.google.com/sounds/v1/animals/animal_bark_and_growl.ogg">a digital watch alarm</audio>'
+ '</speak>';
app.ask(textToSpeech);
}
但是,我不知道如何在 Firebase 存储中播放音频文件。我已尝试将音频 url 替换为文件的存储位置以及 DownloadUrl1 url,如单击 Firebase 存储中的文件时所示。
我还查看了根据 https://firebase.google.com/docs/storage/web/create-reference 创建存储参考 但是当我添加对存储服务的引用时,出现 'firebase not defined' 错误。
function saySSML (request, response) {
const app = new DialogflowApp({request: request, response: response});
// Get a reference to the storage service, which is used to create references in your storage bucket
var storage = firebase.storage();
// Create a storage reference from our storage service
var storageRef = storage.ref();
const textToSpeech = '<speak>'
+ 'I can play a sound'
+ '<audio src="https://firebasestorage.googleapis.com/v0/b/andrewdittmer-c301f.appspot.com/o/alarm_clock.ogg?alt=media&token=d66a4055-5365-4061-b50d-0b6a126841f3">a digital watch alarm</audio>'
+ '</speak>';
app.ask(textToSpeech);
}
有没有人能成功做到这一点?
感谢您的帮助/指点。
Google 助手的 SSML 解析器非常严格。 URL 中的 &
需要转义,因此结果应该是 &
。该行可能看起来像这样:
+ '<audio src="https://firebasestorage.googleapis.com/v0/b/andrewdittmer-c301f.appspot.com/o/alarm_clock.ogg?alt=media&token=d66a4055-5365-4061-b50d-0b6a126841f3">a digital watch alarm</audio>'
或者,如果您已经在使用 Firebase,并且您的音频资产是静态的,您可能希望将音频存储在 Firebase Hosting。
我需要使用非常具体的音频编码设置,如指定的那样here。
The audio must contain a single channel (mono) of μ-law encoded audio at 8kHz and be hosted on Cloud Storage.