[英]Google Actions sdk not playing audio using ssml
I have tried to play small size audio using SSML, but the below code throws the error " expected_inputs[0].input_prompt.rich_initial_prompt.items[0].simple_response: 'display_text' must be set or 'ssml' must have a valid display rendering. " 我尝试使用SSML播放小尺寸的音频,但是以下代码引发错误“ Expected_inputs [0] .input_prompt.rich_initial_prompt.items [0] .simple_response:必须设置'display_text'或'ssml'必须具有有效的显示呈现。”
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {
MediaObject
} = require('actions-on-google');
const LOGO_IMG = 'https://s3.ap-south-1.amazonaws.com/XXXXXXXXXXXXXX/skill/Logo1200.jpg'
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(new Card({
title: `TITLE`,
imageUrl: LOGO_IMG,
text: `This is the body text of a card. You can even use line\n breaks and emoji! 💁`
})
);
const welcomeText = 'Welcome message';
agent.add(welcomeText);
}
function playsong(agent) {
agent.add('<speak> <audio src="https://actions.google.com/sounds/v1/alarms/alarm_clock.ogg"></audio></speak>');
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('PlaySongIntents', playsong);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
As the error message mentions, if you're sending SSML, you either need to have some part of the SSML be able to be displayed on non-audio devices, or you need to provide a separate text message for it to display. 如错误消息所述,如果要发送SSML,则需要使SSML的某些部分能够在非音频设备上显示,或者需要提供单独的文本消息来显示。
In this case, you can change your playsong()
function to something like 在这种情况下,您可以将playsong()
函数更改为类似
function playsong(agent) {
agent.add('<speak> <audio src="https://actions.google.com/sounds/v1/alarms/alarm_clock.ogg">Alarm!</audio></speak>');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.