【问题标题】:Alexa skills: HSL plays, but no soundAlexa技能:HSL播放,但没有声音
【发布时间】:2017-06-30 08:58:26
【问题描述】:

你好,

我正在使用“Alexa Skill Kit”的“AudioPlayer”流式传输 HLS 音频格式 URL。我没有收到来自 AWS Lambda、Silent Echo 和 Developer Portal 的错误。我正在使用 Silent Echo 进行测试。

Alexa 能够很好地播放 MP3 格式的 URL。 Silent Echo 会播放我的 HLS URL,但我什么也听不到。我还测试了下面列出的其他 HLS URL,我也听不到它们的任何消息。但是,当您使用 VLC 软件播放时,它们确实有效。

我的 HLS 网址:https://cpdc101-lh.akamaihd.net/i/ISNCPDCMB1_1@314337/master.m3u8

其他 HLS:

ehttps://c4.prod.playlists.ihrhls.com/3379/playlist.m3u8

ehttp://radioitaliasmi-lh.akamaihd.net/i/radioitaliasmi_1@329643/master.m3u8

http://radiom2o-lh.akamaihd.net/i/RadioM2o_Live_1@42518/master.m3u8

有人也可以测试我的 HLS 吗?不知道是不是只有我一个人,或者 Silent Echo 不会播放。

Lambda 函数代码:

var lastPlayedByUser = {};
var streamURL = "https://cpdc101-lh.akamaihd.net/i/ISNCPDCMB1_1@314337/master.m3u8";


exports.handler = function(event, context) {
    var player = new SidRothPlayer(event, context);
    player.handle();
};

var SidRothPlayer = function (event, context) {
    this.event = event;
    this.context = context;
};

SidRothPlayer.prototype.handle = function () {
    var requestType = this.event.request.type;
    var userId = this.event.context ? this.event.context.System.user.userId : this.event.session.user.userId;

   if (requestType === "LaunchRequest") {
        this.play(streamURL, 0);

    } else  if (requestType === "IntentRequest") {
        var intent = this.event.request.intent;
        if (intent.name === "Play") {
            this.play(streamURL, 0);

        } else if (intent.name === "AMAZON.PauseIntent") {
            this.stop();

        } else if (intent.name === "AMAZON.ResumeIntent") {
            var lastPlayed = this.loadLastPlayed(userId);
            var offsetInMilliseconds = 0;
            if (lastPlayed !== null) {
                offsetInMilliseconds = lastPlayed.request.offsetInMilliseconds;
            }

            this.play(streamURL, offsetInMilliseconds);
        }
    } else if (requestType === "AudioPlayer.PlaybackStopped") {
        this.saveLastPlayed(userId, this.event);
        this.context.succeed(true);
    }
};


 SidRothPlayer.prototype.play = function (audioURL, offsetInMilliseconds) {
    var response = {
        version: "1.0",
        response: {
            shouldEndSession: true,
            directives: [
                {
                    type: "AudioPlayer.Play",
                    playBehavior: "REPLACE_ALL", 
                    audioItem: {
                        stream: {
                            url: audioURL,
                            token: "0", 
                            expectedPreviousToken: null, 
                            offsetInMilliseconds: offsetInMilliseconds
                        }
                    }
                }
            ]
        }
    };

    this.context.succeed(response);
};


SidRothPlayer.prototype.stop = function () {
    var response = {
        version: "1.0",
        response: {
            shouldEndSession: true,
            directives: [
                {
                    type: "AudioPlayer.Stop"
                }
            ]
        }
    };

    this.context.succeed(response);
};

SidRothPlayer.prototype.saveLastPlayed = function (userId, lastPlayed) {
    lastPlayedByUser[userId] = lastPlayed;
};

SidRothPlayer.prototype.loadLastPlayed = function (userId) {
    var lastPlayed = null;
    if (userId in lastPlayedByUser) {
        lastPlayed = lastPlayedByUser[userId];
    }
    return lastPlayed;
};

谢谢,

杰克逊

【问题讨论】:

    标签: amazon-web-services aws-lambda http-live-streaming alexa alexa-skills-kit


    【解决方案1】:

    Silent Echo 和 Echosim 不支持 HLS。必须有一台 Echo Machine 才能测试 HLS 流。

    我刚刚在 Echo Machine 上测试了我的代码,它可以工作。

    【讨论】:

      猜你喜欢
      • 2018-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 2021-12-08
      相关资源
      最近更新 更多