Amazon AlexaAWS

ASK Sound LibraryでAlexa Skillに効果音をいれる

ゲームスキルなどを作っていると、何かしらの効果音を入れたくなることがあります。そんな時に便利な効果音ライブラリがAlexa teamから提供されていますので、使ってみましょう。 ASK Sound Libraryとは A […]

広告ここから
広告ここまで

ゲームスキルなどを作っていると、何かしらの効果音を入れたくなることがあります。そんな時に便利な効果音ライブラリがAlexa teamから提供されていますので、使ってみましょう。

ASK Sound Libraryとは

Alexa Skills Kit (ASK)向けのサウンドライブラリです。2018年の3月に提供が始まり、SSMLのaudioタグを使うことでSkillに様々な効果音をいれることが可能になります。

Announcing the New Alexa Skills Kit Sound Library to Create More Engaging Skills

効果音の種類

現時点で提供されている効果音は以下の通りです。

使い方

まずは上記のリストから、使いたい効果音のURLを探します。各ページに再生ボタンがついていますので、実際に聞きながら試すとよいでしょう。

https://developer.amazon.com/ja/docs/custom-skills/foley-sounds.html

使いたいものがでてきたら、横にあるaudioタグをコピーします。

そしてalexa-sdkを使用している場合は、以下のようにspeakの値に渡してやりましょう。

const Alexa = require('alexa-sdk')

const handlers = {
    'LaunchRequest': function () {
        const speechOutput = `<p>拍手・歓声の効果音を再生します。</p>
<audio src='https://s3.amazonaws.com/ask-soundlibrary/human/amzn_sfx_large_crowd_cheer_03.mp3'/>
<p>おめでとうございます。効果音が再生できました。</p>
`;
        this.response.speak(speechOutput);
        this.emit(':responseReady');
    }
}

exports.handler = function (event, context, callback) {
    const alexa = Alexa.handler(event, context, callback);
    alexa.registerHandlers(handlers);
    alexa.execute();
};

this.response.speak()を使う場合、<speak>タグは不要です。(関数側でラップしてくれます)

これでスキルのテストをすると、効果音がちゃんと再生されていることが確認できます。

プログレッシブレスポンスに利用する

[Alexa日本語] プログレッシブレスポンスを使用して応答待ちの間に音楽やメッセージを流してユーザーを幸せにするという記事が先日公開されていました。これを使うことで、内部処理がレスポンスを返す間に話す内容を定義することができます。

ブログのサンプルでは自分で作成した音楽が使用されていますが、ASK Sound Libraryの音源を使用すればより簡単に実装を行うことができます。

元記事のサンプルコードっぽくしたサンプル

'ProgressiveResponseIntent': function() {
        let that = this;
        let query = 'sample';
     
        const requestId = this.event.request.requestId;
        const token = this.event.context.System.apiAccessToken;
        const endpoint = this.event.context.System.apiEndpoint;
        const ds = new Alexa.services.DirectiveService();
        const ssml = `<speak><p>拍手・歓声の効果音を再生します。</p>
<audio src='https://s3.amazonaws.com/ask-soundlibrary/human/amzn_sfx_large_crowd_cheer_03.mp3'/>
</speak>`
     
        const directive = new Alexa.directives.VoicePlayerSpeakDirective(requestId, ssml);
        const progressiveResponse = ds.enqueue(directive, endpoint, token)
        .catch((err) => {
            console.log(err);
        });
        const serviceCall = new Promise((resolve) => {
            setTimeout( () => {
                resolve(query);
            },7000);
        })
        Promise.all([progressiveResponse, serviceCall])
        .then( query => {
            that.emit(':tell', 'おめでとうございます。効果音が再生できました。');
        }).catch(err => console.log(err));  
    }

SSML書き換えたくらいなので、ちゃんと動くかはまだ確認していません。ただ、ゲームのカウントダウンなどにも使えそうな気がするので、いろいろ試してまた記事にしていこうと思います。

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts