1

I'm building a multi-language-educational app on DialogFlow. and i hit a big problem : Switch recognition language. Any suggestions how could i achieve that or any other approaches?

I have added to DialogFlow web-interface secondary language.

I'm using action-on-google sdk with node.js webhook.

UPDATE :

 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);

The request 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"
  }
 }
Sz-Nika Janos
  • 811
  • 6
  • 19

1 Answers1

3

Dialogflow requires a language with the audio request, if you'd like to change that language you'll need to issue a new request. You can implement some logic in your webhook and frontend to try the request again with a different language.

To do this add some data in the payload field of your webhook response response indicating that you'd like to issues a new request with the a different language specified. In your client, check the data in the response payload and if the data indicates retrying with another language, send another request with a different language specified in the input audio config with the same audio.

mattcarrollcode
  • 3,429
  • 16
  • 16
  • i sent response from webhook with payload containing the audioConfig in the DialogFLow interface i can see (View json) the webhookpayload containing my data, But now i'm stuck sending the second request with the specified audio config in payload,to change the audio recognition to other language – Sz-Nika Janos Feb 02 '18 at 13:03
  • I see your update now. If you're using the actions on google SDK, you Dialogflow fulfillment will only work Actions on Google. For actions on Google the language of the request is determined by Actions on Google. For testing, you can change the language in the Actions on Google simulator: https://developers.google.com/actions/localization/testing – mattcarrollcode Feb 02 '18 at 18:37
  • @matthewayne can you provide more explanation for your comment here on Feb 2? Somehow I'm not able to parse it. – Alex Bravo Jun 26 '18 at 20:47