简体   繁体   English

Amazon Echo 按命令播放音乐

[英]Amazon Echo Playing Music on Command

Hey everyone so I'm having a difficult time trying to implement an audio playback.大家好,我在尝试实现音频播放时遇到了困难。 Here's the docs这是文档

So what I really want to do seems quite simple but came out to be very confusing where everything is suppose to go.所以我真正想做的事情看起来很简单,但结果却让一切都变得非常混乱。

I want to be able to say a command.我希望能够说一个命令。 Alexa will respond will a little outputSpeech and then proceed to play a small audio track mp3 that I would provide. Alexa 会响应一点 outputSpeech,然后继续播放我提供的小音轨 mp3。 I don't mind uploading it locally(When I zip the files and import them into a lamda function) or using S3 Buckets SDK to stream the mp3 file.我不介意在本地上传它(当我压缩文件并将它们导入到 lamda 函数中时)或使用 S3 Buckets SDK 来流式传输 mp3 文件。 Which ever is easier for you guys.哪一个对你们来说更容易。

Here's what I got so far.这是我到目前为止所得到的。

With the codes below I'm able to get Alexa to respond to be voice and output a speech.使用下面的代码,我可以让 Alexa 响应语音并输出语音。

I'm only using the IntentRequest to reduce codes for you guys.我只是使用 IntentRequest 来减少你们的代码。

  • I'm going to say "Alexa open myApp and play my music"我要说“Alexa 打开 myApp 并播放我的音乐”
  • "play my music" is the command i'm going to list as my utterance when I set up my skill in the alexa developer console “播放我的音乐”是我在 alexa 开发者控制台中设置我的技能时将列出的命令
exports.handler = (event, context, callback) => {
    try {
        if (event.request.type === 'IntentRequest') {
            onIntent(event.request,
                event.session,
                (sessionAttributes, speechletResponse) => {
                    callback(null, buildResponse(sessionAttributes, speechletResponse));
                });
        }
    } catch (err) {
        callback(err);
    }
};


My function that will be called when the Intent request goes through当 Intent 请求通过时将调用我的函数

  • My intent name will be PlayMyMusic我的意图名称将是PlayMyMusic


function onIntent(intentRequest, session, callback) {
    console.log(`onIntent requestId=${intentRequest.requestId}, sessionId=${session.sessionId}`);

    const intent = intentRequest.intent;
    const intentName = intentRequest.intent.name;

    if (intentName === 'PlayMyMusic') {
        PlayMyMusic(intent, session, callback);
    } else if (intentName === 'AMAZON.StopIntent' || intentName === 'AMAZON.CancelIntent') {
        handleSessionEndRequest(callback);
    } else {
        throw new Error('Invalid intent');
    }
}


This is the output Message这是输出消息

function PlayMyMusic(intent, session, callback) {

    const repromptText = null;
    const sessionAttributes = {};
    let shouldEndSession = true;
    let speechOutput = '';

        speechOutput = `I'm Alexa and I will output speech in this area. After I'm done talking I will play an audio track`;

    callback(sessionAttributes,
        buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
}

This is my simple Intent Schema这是我的简单意图架构

{
  "intents": [
    {
      "intent": "PlayMyMusic"
    },
    {
      "intent": "AMAZON.HelpIntent"
   }
  ]
}

Sample Utterances示例话语

PlayMyMusic play my music


Everything works as of right now where Amazon can talk to me back and end the session.现在一切正常,亚马逊可以与我交谈并结束会话。

How would I be able to have Amazon responds to me and then play some audio?我怎样才能让亚马逊回复我然后播放一些音频? The docs are kind of not working for me.这些文档对我不起作用。

  • Where do I put the play directive?我在哪里放置播放指令? (AudioPlayer.Play) (音频播放器。播放)
  • you can use SSML and add mp3 path at any https url and it will play song您可以使用 SSML 并在任何 https url 添加 mp3 路径,它会播放歌曲

    see this 看到这个

    Include the audio tag within your text-to-speech response within the speak tag. Alexa plays the MP3 at the specified point within the text to speech. For example:
    <speak>
        Welcome to Car-Fu. 
        <audio src="soundbank://soundlibrary/transportation/amzn_sfx_car_accelerate_01" /> 
        You can order a ride, or request a fare estimate. 
        Which will it be?
    </speak> 
    When Alexa renders this response, it would sound like this:
    Alexa: Welcome to Car-Fu.
    (the specified amzn_sfx_car_accelerate_01.mp3 audio file plays)
    Alexa: You can order a ride, or request a fare estimate. Which will 
    

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

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