如何在Dialogflow Fullfilment中使用SSML(荷兰语)

时间:2019-01-15 22:52:50

标签: dialogflow actions-on-google

有一种简单的方法可以使用Google Actions-on函数在Fullfilment部分中使用SSML。我尝试了各种各样的编码,但是效果不好。我使用荷兰语作为默认语言。

在下面的示例中,Google助手会拼写每个'<'等。

// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favoriete kleur', (conv, {color}) => {
  const luckyNumber = color.length;
  const audioSound = 'https://www.example.com/MY_MP3_FILE.mp3'; // AoG currently only supports MP3!
  if (conv.user.storage.userName) {
    conv.ask(`<speak>${conv.user.storage.userName}, je geluksnummer is ${luckyNumber}<audio src="${audioSound}"><desc>Geluid wordt afgespeeld</desc></audio></speak>`); // Audio should have description
    conv.ask(new Suggestions('Paars', 'Geel', 'Oranje'));
  } else {
    conv.ask(`<speak>Je geluksnummer is ${luckyNumber}<audio src="${audioSound}"><desc>Geluid wordt afgespeeld</desc></audio></speak>`);
    conv.ask(new Suggestions('Paars', 'Geel', 'Oranje'));
  }
});

请在下面的环境设置中查找:

Index.js初始化设置:

'use strict';

// Import the Dialogflow module and response creation dependencies
// from the Actions on Google client library.
const {
    dialogflow,
    BasicCard,
    Permission,
    Suggestions,
    Carousel,
    MediaObject, 
    SimpleResponse, 
    Table, 
    Button  
//  Image,
} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

package.json:

{
  "name": "codelab-level-three",
  "description": "Actions on Google Codelab Level 3",
  "author": "Google Inc",
  "private": true,
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "actions-on-google": "^2.0.0",
    "firebase-admin": "~5.8.1",
    "firebase-functions": "^0.8.1",
    "i18n": "^0.8.3"
  },
  "devDependencies": {
    "eslint": "^4.19.0",
    "eslint-config-google": "^0.9.1"
  }
}

产生的有效载荷如下:

"status": 200,
  "headers": {
    "content-type": "application/json;charset=utf-8"
  },
  "body": {
    "payload": {
      "google": {
        "expectUserResponse": true,
        "richResponse": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "<speak>Paul, je geluksnummer is 5<audio src=\"https://www.example.com/MY_MP3_FILE.mp3\"><desc>Geluid wordt afgespeeld</desc></audio></speak>"
              }
            }
          ],
          "suggestions": [
            {
              "title": "Paars"
            },
            {
              "title": "Geel"
            },
            {
              "title": "Oranje"
            }
          ]
        }
      }
    }
  }
}

3 个答案:

答案 0 :(得分:2)

最可能的问题是您没有包含结束</speak>标签。因此,您应该将其写为

    conv.ask(`<speak>Je geluksnummer is ${luckyNumber}.` +
      `<audio src="${audioSound}"></audio></speak>`);

答案 1 :(得分:1)

加上“囚犯”已经说过的话,还有其他一些问题。

app.intent('favoriete kleur', (conv, {color}) => {
  const luckyNumber = color.length;
  const audioSound = 'https://actions.google.com/sounds/v1/cartoon/clang_and_wobble.mp3'; // AoG currently only supports MP3!
  if (conv.user.storage.userName) {
    conv.ask(`<speak>${conv.user.storage.userName}, je geluksnummer is <audio src="${audioSound}"><desc>${luckyNumber}</desc></audio></speak>`); // Audio should have description
    conv.ask(new Suggestions('Paars', 'Geel', 'Oranje'));
  } else {
    conv.ask(`<speak>Je geluksnummer is <audio src="${audioSound}"><desc>${luckyNumber}</desc></audio></speak>`);
    conv.ask(new Suggestions('Paars', 'Geel', 'Oranje'));
  }
});
  • AoG当前仅支持MP3作为音频格式。参见https://developers.google.com/actions/assistant/responses#media_responses 抱歉,我错了。仅适用于媒体响应,不适用于SSML中的嵌入式音频。
  • 我在上面的代码中删除了串联。这适得其反,使事情变得比必要的更难阅读。 (有主见)
  • 音频输出-不仅要输出声音效果,而且还要输出文本-应该包含说明,该说明也将打印在屏幕上。提供的代码中的示例应该可以。
  • 但是,是的,造成您最初问题的原因是您没有关闭音频标签。对于未关闭的标签,Google上的操作是相当宽容的。

希望有帮助。

答案 2 :(得分:1)

我的问题的答案很简单:只需阅读f ... ing手册。 :-)尽管同时支持.OGG和.MP3,但网站应提供HTTPS。不支持不安全的网站(例如HTTP)。您可以在下面找到示例函数进行测试:

app.intent('favoriete muziek', conv => {
    const Optie = conv.parameters.optie;
    //Taalspecifieke meldingen
    const SoundLib =
    {
        '1': {
            description : 'Simple sound using .ogg',
            audiosound  : 'https://actions.google.com/sounds/v1/alarms/alarm_clock.ogg',
            audiotext   : 'You should hear an audio alarm signal',        
        },
        '2': {
            description : 'Music MP3 via HTTP',
            audiosound  : 'http://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
            audiotext   : 'You should hear a Jazz record called "Jazz in Paris" ',        
        },
        '3': {
            description : 'Longer MP3 file via HTTP',
            audiosound  : 'http://www.navyband.navy.mil/anthems/anthems/netherlands.mp3',
            audiotext   : 'You should hear now the Dutch National Anthem',        
        },
        '4': {
            description : 'short MP3 audio via HTTPS',
            audiosound  : 'https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3',
            audiotext   : 'You should hear a short spoken intro text',        
        },
    };
    const Sound = SoundLib[Optie];
    var spraakzin = "<speak>This text is using <say-as interpret-as='verbatim'>SSML</say-as> followed by an audio file in a SimpleResponse box: <audio src='" + Sound.audiosound + "'>The audio file could not be processed</audio></speak>";
    if (!conv.surface.capabilities.has("actions.capability.MEDIA_RESPONSE_AUDIO")) {
        conv.ask("Media response via audio is not supported on this device.");
        return;
    }
    conv.ask(new SimpleResponse({
        speech: spraakzin,
        text: Sound.audiotext,
    }));
});

更多信息可以在这里找到:SSML examples - look at prerequisites of AUDIO