【问题标题】:DialogFlow change recognition languageDialogFlow 更改识别语言
【发布时间】:2018-02-01 13:54:19
【问题描述】:

我正在 DialogFlow 上构建一个多语言教育应用程序。 我遇到了一个大问题:切换识别语言。 有什么建议我该如何实现这一目标或任何其他方法?

我已添加到 DialogFlow 网络界面辅助语言。

我正在使用带有 node.js webhook 的 action-on-google sdk。

更新:

 let responseToUser = {
    //fulfillmentMessages: richResponsesV2, // Optional, uncomment to enable
    //outputContexts: [{ 'name': `${session}/contexts/weather`, 'lifespanCount': 2, 'parameters': {'city': 'Rome'} }], // Optional, uncomment to enable
    fulfillmentText: 'This is from Dialogflow\'s Cloud Functions for Firebase editor! :-)', // displayed response
    payload: {
       audioConfig : {
        "audioEncoding": 'AUDIO_ENCODING_FLAC',
        "sampleRateHertz": 16000,
        "languageCode": 'de',
        "phraseHints": ["gutten tag"]
       }
    },
      function sendResponse (responseToUser) {
// if the response is a string send it as a response to the user
if (typeof responseToUser === 'string') {
  let responseJson = {fulfillmentText: responseToUser}; // displayed response
  response.json(responseJson); // Send response to Dialogflow
} else {
  // If the response to the user includes rich responses or contexts send them to Dialogflow
  let responseJson = {};
  // Define the text response
  responseJson.fulfillmentText = responseToUser.fulfillmentText;
  responseJson.payload = responseToUser.payload;

     // Send the response to Dialogflow
  console.log('Response to Dialogflow: ' + JSON.stringify(responseJson));
  response.json(responseJson);

请求json:

{
  "responseId": "c4ea35d3-1455-4142-b7d2-22417c5880ae",
  "queryResult": {
"queryText": "hi",
"action": "default",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "This is from Dialogflow's Cloud Functions for Firebase editor! :-)",
"fulfillmentMessages": [
  {
    "text": {
      "text": [
        "This is from Dialogflow's Cloud Functions for Firebase editor! :-)"
      ]
    }
  }
],
"webhookPayload": {
  "sampleRateHertz": 16000,
  "languageCode": "de",
  "phraseHints": [
    "gutten tag"
  ],
  "audioEncoding": "AUDIO_ENCODING_FLAC"
},
"outputContexts": [
  {
    "name": "projects/homehf-master/agent/sessions/824b34b9-45f8-4c65-9377-a31242d3414b/contexts/test_context",
    "lifespanCount": 5
  }
],
"intent": {
  "name": "projects/homehf-master/agent/intents/0259f134-6d4d-4aed-920d-9240adbe38fe",
  "displayName": "starter_intent"
},
"intentDetectionConfidence": 0.75,
"diagnosticInfo": {
  "webhook_latency_ms": 44
},
"languageCode": "en"
 },
    "webhookStatus": {
     "message": "Webhook execution successful"
  }
 }

【问题讨论】:

    标签: node.js webhooks chatbot dialogflow-es


    【解决方案1】:

    Dialogflow 需要使用 audio request 的语言,如果您想更改该语言,则需要发出新请求。您可以在 webhook 和前端中实现一些逻辑,以使用不同的语言再次尝试请求。

    为此,请在您的 webhook response 响应的有效负载字段中添加一些数据,表明您希望使用指定的不同语言发出新请求。在您的客户端中,检查response payload 中的数据,如果数据表明使用另一种语言重试,请使用input audio config 中指定的不同语言和相同的音频发送另一个请求。

    【讨论】:

    • 我从 webhook 发送了响应,其负载包含在 DialogFlow 界面中的 audioConfig 我可以看到(查看 json)包含我的数据的 webhookpayload,但现在我被困在发送带有指定音频配置的第二个请求在有效载荷中,将音频识别更改为其他语言
    • 我现在看到你的更新了。如果您使用 google SDK 上的操作,您的 Dialogflow 实现将仅适用于 Google 上的操作。对于 Google 上的操作,请求的语言由 Google 上的操作确定。为了进行测试,您可以在 Actions on Google 模拟器中更改语言:developers.google.com/actions/localization/testing
    • @matthewayne 您能否在 2 月 2 日为您的评论提供更多解释?不知何故,我无法解析它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 2019-09-21
    • 2011-08-05
    相关资源
    最近更新 更多