我尝试使用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);
});
答案 0 :(得分:1)
正如错误消息所提到的,如果您要发送SSML,您需要让SSML的某些部分能够在非音频设备上显示,或者您需要提供单独的文本消息以便显示它
在这种情况下,您可以将playsong()
功能更改为
function playsong(agent) {
agent.add('<speak> <audio src="https://actions.google.com/sounds/v1/alarms/alarm_clock.ogg">Alarm!</audio></speak>');
}