简体   繁体   English

Google Actions未使用MediaObject播放音频

[英]Google Actions sdk not playing audio using MediaObject

I have tried to play audio using MediaObject, MediaObject is not playing given mp3 audio files, but i got below error message" MalformedResponse 'final_response' must be set." 我曾尝试使用MediaObject播放音频,MediaObject没有播放给定的mp3音频文件,但我得到以下错误消息“必须设置MalformedResponse'final_response'。”

'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {
  dialogflow,
  BasicCard,
  BrowseCarousel,
  BrowseCarouselItem,
  Button,
  Carousel,
  LinkOutSuggestion,
  List,
  MediaObject,
  Suggestions,
  SimpleResponse,
 } = require('actions-on-google');

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(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  // // Uncomment and edit to make your own intent handler
  // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
  // // below to get this function to be run when a Dialogflow intent is matched
  function yourFunctionHandler(agent) {
    agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
    let conv = agent.conv();
    conv.ask(new Suggestions('Suggestion Chips'));
    conv.close(new MediaObject({
      name: 'Jazz in Paris',
      url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
      description: 'A funky Jazz tune',
      icon: new Image({
        url: 'https://storage.googleapis.com/automotive-media/album_art.jpg',
        alt: 'Media icon',
      }),
    }));
    conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));

  }

  // 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 Fallback Intent', fallback);
   intentMap.set('PlaySongIntents', yourFunctionHandler);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);
});

I am getting below response 我得到了低于回应

  "responseMetadata": {
    "status": {
      "code": 10,
      "message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
      "details": [
        {
          "@type": "type.googleapis.com/google.protobuf.Value",
          "value": "{\"id\":\"ff0ee47a-9df3-46c9-97db-f6db6442179b\",\"timestamp\":\"2018-06-15T09:42:53.424Z\",\"lang\":\"en-us\",\"result\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: Request timeout.\"},\"sessionId\":\"1529055750970\"}"
        }
      ]
    }
  }
}

The error message suggests that you're not including a message that should be said in addition to the audio that you want to play. 错误消息表明除了您要播放的音频之外,您不会包含应该说出的消息。 It is required to include a SimpleResponse along with the audio. 需要包含SimpleResponse和音频。

You're mixing Dialogflow responses and Actions on Google responses, which may be confusing the response parser. 您在Google响应中混合了Dialogflow响应和操作,这可能会使响应解析器感到困惑。 You should add a SimpleResponse to the conv object as part of your response. 作为响应的一部分,您应该将SimpleResponse添加到conv对象。 So that portion of the code might look something like this: 所以代码的那部分可能看起来像这样:

  function yourFunctionHandler(agent) {
    let conv = agent.conv();
    conv.ask(new SimpleResponse("Here is a funky Jazz tune"));
    conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));
    conv.close(new MediaObject({
      name: 'Jazz in Paris',
      url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
      description: 'A funky Jazz tune',
      icon: new Image({
        url: 'https://storage.googleapis.com/automotive-media/album_art.jpg',
        alt: 'Media icon',
      }),
    }));
  }

additionally, you don't import the Image object as part of your require('actions-on-google') , which is what is causing the error when the function runs. 此外,您不会将Image对象作为require('actions-on-google')一部分导入,这是函数运行时导致错误的原因。 Make sure you get all the objects you need as part of the require . 确保获得所需的所有对象作为require一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM