question

aki avatar image
aki asked

lalexa-hostedでS3に格納したmp3を再生したい

alexa-hostedでS3にしたmp3を再生したいですが

CloudWatchのログにエラーが出力されず困っています。

以下に内容を記載します。


手順

1.mp3作成(エンコード済み 48K 16000Hz)

2.Alexa-hostedのS3にアップロード(公開はしていません。というか出来ない)

3.スキルから呼び出し


ソース(抜粋)

S3メディアの相対パス指定して署名付き変換
urltext = utils.get_media_url('Media/sound/drum-japanese1_02.mp3')


署名付き変換関数
def get_media_url(key_path):
    # Generate the URL to get 'key_path' from 'bucket-name'
    # URL expires in 604800 seconds (seven days)
    url = s3.generate_presigned_url(
        ClientMethod='get_object',
            Params={
                'Bucket': data.BUCKET,
                'Key': key_path
            },
        ExpiresIn=604800
    )
    
    return url


再生指定
speak_output += "'<audio src=" + urltext + "/>'"


テスト結果

スキルがリクエストに正しく応答できませんでした。

ClowdWatchログにも特にエラーログがでていません。


再生指定の方法が意図しているのでしょうか?

urltextは署名付きで返ってきました。

この使い方はjpeg画像の表示でお願いしますほかの公開スキルで使っています。

今回はS3のmp3で手こずっています。


何が問題なのか分からないため、助けてもらえないでしょうか。

pythonssmlmusic
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Chihiro@Amazon avatar image
Chihiro@Amazon answered

ご投稿ありがとうございます。

Alexa-hostedに付属するS3の場合は、URLの取得にutilsのcreate_presigned_urlをお使いください。また、PythonはURLをエスケープする必要があります。一度以下コードでテストしていただけますでしょうか。

from utils import create_presigned_url
import html
 
urltext = create_presigned_url('Media/sound/drum-japanese1_02.mp3')
speak_output = '<audio src=\"' + html.escape(urltext) + '\"/>'

Alexa-hostedスキルでメディアファイルを使用する - Python

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.