gpt4 book ai didi

javascript - Amazon Echo 按命令播放音乐

转载 作者:行者123 更新时间:2023-11-27 22:30:21 24 4
gpt4 key购买 nike

大家好,我在尝试实现音频播放时遇到了困难。这是docs

所以我真正想做的事情看起来很简单,但结果却非常令人困惑,一切都应该去。

我希望能够说出命令。 Alexa 将响应一点输出语音,然后继续播放我提供的小音轨 mp3。我不介意在本地上传它(当我压缩文件并将它们导入到 lamda 函数中时)或使用 S3 Buckets SDK 来流式传输 mp3 文件。哪个对你们来说更容易。

这是我到目前为止所得到的。

通过下面的代码,我可以让 Alexa 响应语音并输出语音。

我只是使用 IntentRequest 来为你们减少代码。

  • 我会说“Alexa 打开我的应用程序并播放我的音乐”
  • “播放我的音乐”是我在 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);
}
};


当 Intent 请求通过时将调用我的函数

  • 我的意图名称将是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');
}
}


这是输出消息

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));
}

这是我简单的意图架构

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

示例话语

PlayMyMusic play my music


现在一切正常,亚马逊可以跟我回复并结束 session 。

我怎样才能让亚马逊回复我,然后播放一些音频?这些文档对我来说不太有用。

  • 我应该把播放指令放在哪里? (音频播放器.播放)
  • 最佳答案

    您可以使用 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

    关于javascript - Amazon Echo 按命令播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39648659/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com