Reputation: 1026
I am able to play a sound from my DialogFlow fulfillment inline editor webhook with the following.
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);
}
However, I can't figure out how to play an audio file in Firebase Storage. I have tried replacing the audio url with the storage location of the file and also the DownloadUrl1 url as shown when clicking on the file in Firebase Storage.
I've also looked at creating a storage reference as per https://firebase.google.com/docs/storage/web/create-reference but when I add the reference to the storage service, I get 'firebase not defined' error.
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);
}
Has anyone been able to successfully do this?
Thanks for any help / pointers.
Upvotes: 3
Views: 974
Reputation: 10744
I needed to use very specific audio encoding settings, as specified here.
The audio must contain a single channel (mono) of μ-law encoded audio at 8kHz and be hosted on Cloud Storage.
Upvotes: 0
Reputation: 50731
The SSML parser for the Google Assistant is very strict. The &
that is in your URL needs to be escaped, so the result should be &
. The Line might look something like this:
+ '<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>'
Alternately, if you're using Firebase already, and your audio assets are static, you may want to store the audio in Firebase Hosting.
Upvotes: 4