【问题标题】:Google Actions sdk not playing audio using ssmlGoogle Actions sdk 不使用 ssml 播放音频
【发布时间】:2018-11-23 20:44:35
【问题描述】:

我曾尝试使用 SSML 播放小尺寸音频,但以下代码抛出错误 " expected_inputs[0].input_prompt.rich_initial_prompt.items[0].simple_response: 'display_text' must be set or '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);
});

【问题讨论】:

    标签: node.js actions-on-google dialogflow-es ssml


    【解决方案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>');
      }
    

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 2017-10-27
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      相关资源
      最近更新 更多