1

みなさん、オーディオ再生を実装しようとして苦労しています。ここにドキュメント

があります私が本当にやりたいことは非常に単純に見えますが、すべてがどこに行くべきか非常に混乱するようになりました.

命令できるようになりたい。Alexa は少し出力音声で応答し、私が提供する小さなオーディオ トラック mp3 の再生に進みます。ローカルにアップロードしたり(ファイルを圧縮してラムダ関数にインポートしたりする場合)、S3 Buckets SDK を使用して mp3 ファイルをストリーミングしてもかまいません。皆さんにとってどちらが簡単ですか。

これが私がこれまでに得たものです。

以下のコードを使用すると、Alexa に音声で応答して音声を出力させることができます。

私は IntentRequest を使用してコードを削減しているだけです。

  • 「アレクサ、アプリを開いて音楽を再生して」と言います。
  • 「音楽を再生して」は、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);
    }
};


インテントリクエストが通過したときに呼び出される私の関数

  • インテント名は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


Amazonが私に話しかけてセッションを終了できるようになった現在、すべてが機能しています。

Amazon に応答してもらい、音声を再生するにはどうすればよいですか? ドキュメントは私にとってはうまくいきません。

  • play ディレクティブはどこに置くのですか? (AudioPlayer.Play)
  • 4

    1 に答える 1

    1

    SSML を使用して任意の https URL に mp3 パスを追加すると、曲を再生できます

    これを見る

    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 
    
    于 2016-12-16T17:20:21.733 に答える