简体   繁体   English

如何在dialogflow中打断音乐

[英]How to interrupt the music in dialogflow

I am building a chatbot using dialogflow.我正在使用 dialogflow 构建一个聊天机器人。 I am using music between the questions.我在问题之间使用音乐。 I want the user to interrupt the music and then provide the answer to the question and then the next question to be asked.我希望用户打断音乐,然后提供问题的答案,然后再提出下一个问题。

This is the code where I am using music:这是我使用音乐的代码:

app.intent('First', (conv) => {
    const ans = conv.parameters.any;
    if(ans == 65){
            senddata[0] = qstion[0] + ans;
            const speech = '<speak><audio src="https://actions.google.com/sounds/v1/science_fiction/alien_beam.ogg"/>Did not get the audio file</speak>';
            conv.add(speech);
            conv.ask(qstion[1]);
        
    }
    else{
            conv.add('Please enter a valid number');
            conv.ask(qstion[0]);
    }
});

This is the next intent:这是下一个意图:

app.intent('Second', (conv) => {
    const ans = conv.parameters.any;
    if(ans == 108){
            senddata[1] = qstion[1] + ans;
            conv.ask(qstion[1]);
        
    }
    else{
            conv.add('Please enter a valid number');
            conv.ask(qstion[0]);
    }
});

Following is the code where I am declaring qstion and senddata:以下是我声明 qstion 和 senddata 的代码:

global.sample = ['Question1, What is 33+32',
'Okay, Question2, What is 76+32',
'Okay, Last Question, Did you like the game']
global.senddata = [];

The issue here I am facing is if during the music if the user speaks "Okay Google" to interrupt the music, the music stops but the flow goes into the else part and says "Please enter a valid number".我在这里面临的问题是,如果在音乐播放过程中,如果用户说“好的 Google”来中断音乐,音乐会停止,但流程会进入 else 部分并说“请输入有效数字”。 After that it asks the first question again but the flow goes to "Second" intent.之后它再次询问第一个问题,但流程转到“第二”意图。

I want the flow to stay in the "First" intent itself when the user interrupts the music.当用户中断音乐时,我希望流程保持在“第一”意图本身。 Is there anyway I can do this?无论如何我可以做到这一点吗?

Not the way you have designed it, but that's partly because the request/response model for Dialogflow (and Actions on Google) don't quite work that way.不是您设计它的方式,但这部分是因为 Dialogflow(和 Google 上的 Actions)的请求/响应模型不太适合那样工作。

For starters, it doesn't quite make sense to say you want to "stay in the Intent".对于初学者来说,说你想“留在意图中”是没有意义的。 Intents aren't something you are "in" - they represent a specific action from the user.意图不是你“在”的东西——它们代表用户的特定操作。 For Actions on Google - this is usually representing the specific action of saying something.对于 Actions on Google - 这通常代表说某事的具体动作。

So when the user "breaks in" to a response, no matter if they break in while a sound file is playing or if the speech is playing, then this is treated as the end of the response and the user generating their next request.因此,当用户“闯入”响应时,无论他们是在播放声音文件时闯入还是正在播放语音,都将被视为响应结束并且用户生成下一个请求。 The request from the user triggers an Intent, the Intent determines how it is handled, and the webhook sends something back.来自用户的请求触发一个 Intent,Intent 决定如何处理它,然后 webhook 发送回一些东西。

This cycle (user input, processing based on Intent, send reply back) can't really be changed.这个循环(用户输入、基于 Intent 的处理、发送回复)不能真正改变。

For playing an audio file, however, there are a couple of tricks you can pull.但是,要播放音频文件,您可以使用一些技巧。 You can, for example, use a Media response .例如,您可以使用媒体响应 With this,有了这个,

  • At some point, you'll send back a spoken message and Media that will play after this spoken message.在某些时候,您将发回一条语音消息和将在此语音消息后播放的媒体。
  • The user can break in at any time, and it will be handled through normal Intent processing用户可以随时闯入,会通过正常的Intent处理
  • If the user does not break in, when the media finishes playing, it will generate a actions_intent_MEDIA_STATUS event in Dialogflow.如果用户没有闯入,当媒体播放完毕时,它会在Dialogflow 中生成一个actions_intent_MEDIA_STATUS事件 You can setup an Intent that will handle this Event and reply accordingly.您可以设置一个 Intent 来处理此事件并相应地回复。

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

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