音频播放后的消防意图或功能结束Alexa技能node.js

时间:2018-03-10 22:15:25

标签: node.js alexa alexa-skills-kit alexa-skill

我需要在我的alexa技能中执行以下一系列事件,我目前无法确定如何执行此操作。

  1. 播放一些音频剪辑(超过90秒)。
  2. 询问用户是否准备好接收下一个音频片段。
  3. 根据要求播放另一个音频片段。
  4. 根据需要重复。
  5. 我对#1有以下意图:

    "PlayWarmUp": function(){
            console.log("play warm up intent fired");
    
            if (this.event.context.System.device.supportedInterfaces.Display) {
                //play warm up video
                const builder = new Alexa.templateBuilders.BodyTemplate6Builder();
                const template = builder.setTextContent(makeRichText('<font size="7">Are you ready?</font><br/><br/><br/><br/>')).build();
                let meta = {
                    title: "Warmup",
                    subtitle: null
                };
                this.response.playVideo(videoURL, meta).renderTemplate(template).hint("'Yes', or 'No', or 'Ready'");
                //switch state to workout since we want to handle their responses to the are you ready screen, which is in the WORKOUT state
                this.handler.state = states.WORKOUT;
                this.emit(":responseReady");
            } else {
                // Audio only
                //
                console.log("Audio only for play warm up");
                this.response.shouldEndSession(false);
                this.response.audioPlayerPlay('ENQUEUE', warmupAudioURL, 'warmup-audio-token', 'previous-token', '0');
    
                this.handler.state = states.WORKOUT;
                audioState = states.WARMUP;
                this.emit(":responseReady");
            }
        }
    

    亚马逊为这样的音频事件提供内置意图:

    const audioHandlers = {
        'PlaybackStarted' : function() {
            console.log('Alexa begins playing the audio stream');
            this.emit(':responseReady');
        },
        'PlaybackFinished' : function() {
            console.log('The stream comes to an end');
            console.log("audioState: ", audioState);
            console.log("this ", this);
            console.log("context: ", this.context);
    
            if (audioState === states.WARMUP) {
                console.log("audio state is warm up...");
    
                // This doesn't work. It does nothing.
                //
                this.handler.state = states.WORKOUT;
                this.emitWithState("WORKOUT");
            }
        },
        'PlaybackStopped' : function() {
            console.log('Alexa stops playing the audio stream');
            this.emit(':responseReady');
        },
        'PlaybackNearlyFinished' : function() {
            console.log('The currently playing stream is nearly complate and the device is ready to receive a new stream');
            this.emit(':responseReady');
        },
        'PlaybackFailed' : function() {
            console.log('Alexa encounters an error when attempting to play a stream');
            this.emit(':responseReady');
        }
    };
    

    上述代码不起作用。我无法打电话给&#34;锻炼&#34;音频结束时的意图。

    documentation州:

    enter image description here

    我还看过使用SSML,但emitWithState()在讲话结束前发光,只允许90秒的音频。

    您无法播放和录制音频,然后向用户询问某些内容,这没有任何意义。这应该是一个基本的对话功能。有人解决了这个问题吗?

0 个答案:

没有答案