技巧精选

@levelsio 公开 Alexa 音乐点播技能的完整提示词

精选理由

levelsio 贴出了完整提示词,能让 Alexa 播你自己 S3 里的 MP3 和 NTS 等电台,不用受限于 Amazon Music。

@levelsio 分享了一段可直接使用的提示词,让 AI 代你构建一个私有 Alexa 技能。该技能通过 S3 或 Cloudflare R2 桶播放自己的 MP3,并内置 NTS、Rinse FM、Bassdrive 等网络电台和 BBC World Service 新闻流。提示词要求 Alexa 用预签名 HTTPS URL(有效期至少 12 小时)播放文件,把播放队列存在 AudioPlayer token 里从而免建数据库。语音匹配部分包含数字转写、流派别名(dnb、lo fi 等)和文件夹乱序播放的处理细节。

原文 · Pieter Levels

Here is the prompt to build your own music MP3 player and internet radio for Amazon Alexa:

[ 🎶 Jukebox for Alexa ] by @levelsio

Build me a private Alexa skill that plays my own music from a cloud bucket, plus internet radio

I want my Amazon Echo to play my own MP3s instead of being forced to use Amazon Music or Spotify. Build a private Alexa skill for this. Do as much as possible yourself: use CLIs and APIs, deploy and test it yourself, and only ask me for things only a person can do (logging in, clicking Allow, testing on the Echo).

Setup - My music is in an S3-compatible bucket (AWS S3 or Cloudflare R2) under a music/ prefix. Each folder under it is a genre/playlist (music/Coffee Jazz/) or an artist/album (music/Artist/Album/). - I'll create an access key for the bucket and give it to you. Keep it in a config file and never print it. The skill only needs read access; the upload tools need write access. - My Echo and my Amazon developer account use the same Amazon login.

Build 1. An Alexa-hosted (Node.js) custom skill with invocation name "jukebox" (use two words if Amazon rejects one) and the AudioPlayer interface enabled. 2. Voice model: a PlayIntent with an AMAZON.SearchQuery slot ("play {query}", "put on {query}", "tune in to {query}", "shuffle {query}"), a ShuffleAllIntent, a WhatsPlayingIntent, a ListStationsIntent, and all the built-in AudioPlayer intents (pause, resume, next, previous, loop on/off, shuffle on/off, start over). 3. Library: list everything under music/ with ListObjectsV2 (follow the continuation token), build folders from the key prefixes, keep only .mp3/.m4a/.aac files, and cache the result for 5 minutes. Match spoken phrases to folder and file names loosely: ignore track numbers and spacing ("ama piano" = amapiano), turn number words into digits ("thirteen beaches" = 13 Beaches), and handle genre aliases (dnb, drum n bass, hiphop, lo fi). 4. Playback: give Alexa a presigned HTTPS GET URL for each file. Make it valid for at least 12 hours so long mixes and pause/resume don't expire mid-play. Keep the bucket private. Store the play queue in the AudioPlayer token (folder, shuffle seed, position) so there's no database, and enqueue the next track on PlaybackNearlyFinished. Folders shuffle and loop. A folder whose files all start with track numbers is an album and plays in order. A single song carries on with the rest of its folder. 5. Radio: a stations list of HTTPS MP3/AAC/HLS streams, with good underground electronic stations (Rinse FM, NTS, Bassdrive, Intergalactic FM, Kiosk Radio, Refuge Worldwide, and so on) plus news (BBC World Service, NPR). Test every URL with curl first and drop the plain-HTTP ones, because Alexa refuses them. Support "play rinse fm", "drum and bass radio", "techno radio" and "the news", and make next/previous switch stations. Live streams drop and Alexa treats a drop as the end, so re-enqueue the same stream with a new token on PlaybackNearlyFinished, and retry once on PlaybackFailed. 6. Log one line per request (type, intent, token, offset, error) so playback problems show up in CloudWatch.

Deploy without the web console - Install the ASK CLI (npm i -g ask-cli). If ask configure won't work in your shell, run ask util generate-lwa-tokens --no-browser, have me paste the one-time code, and write ~/.ask/cli_config yourself. Get the vendor ID from GET https://t.co/8eS787CaBt. - The hosted skill's code is a git repo (find it with ask smapi get-alexa-hosted-skill-metadata). Push to master to deploy, with ask util git-credentials-helper as the git credential helper. The helper needs ask-resources.json and .ask/ask-states.json next to the repo. If pushes start failing with 403, clear the cached macOS keychain credential. - The hosted runtime may run an old Node version, so pin an S3 SDK version that supports it, or sign URLs with a small SigV4 library. - Upload the voice model with ask smapi set-interaction-model, check the skill manifest lists AUDIO_PLAYER, and test with ask smapi simulate-skill. The web console's simulator can't play audio, so a "problem with the requested skill's response" error there is expected.

When it works, tell me how to add Alexa app routines (When: voice "coffee jazz" → Action: Customized "ask jukebox to play coffee jazz") so I can just say "Alexa, coffee jazz". And how to play internet radio stations I like.