Music Identify
Identify songs from audio using AudD, return song info with Spotify link, and optionally queue to the user's active Spotify session.
Runtime Dependencies
Required on $PATH:
- -
curl — HTTP requests to AudD and Spotify APIs - INLINECODE2 — JSON parsing for all API responses
- INLINECODE3 — Spotify OAuth flow only (
scripts/spotify-auth.py)
Credentials
| Credential | Location | Required | Purpose |
|---|
| AudD API key | INLINECODE5 | Yes | Song identification |
| Spotify OAuth tokens |
~/.config/spotify/tokens.json | No (optional) | Queue to Spotify |
| Spotify app credentials |
~/.config/spotify/credentials.json | No (optional) | Token refresh |
Security notes:
- - All credential files should be restricted:
chmod 600. - This skill does not read, store, or access any platform tokens (Telegram, Discord, etc.). Audio file download from messaging platforms is handled by the host agent, not by this skill.
Trigger
- - User sends
/songsearch then follows with a voice message or audio file - User asks to identify a song from audio ("what song is this", "identify this song", "shazam this")
- User asks to recall previously identified songs ("what was that song", "what did I shazam")
Setup
AudD API Key (required)
- 1. Sign up at (free tier: 300 requests, no credit card)
- Save key:
CODEBLOCK0
Spotify Integration (optional)
- 1. Create a Spotify Developer app at
- Set redirect URI to your callback URL
- Save credentials:
mkdir -p ~/.config/spotify
cat > ~/.config/spotify/credentials.json << 'EOF'
{"client_id": "...", "client_secret": "...", "redirect_uri": "https://your-host/callback"}
EOF
chmod 600 ~/.config/spotify/credentials.json
- 4. Run the auth flow: INLINECODE10
- Open the printed URL in a browser, authorize, tokens save automatically
- INLINECODE11
Workflow — Song Identification
When a song identification is triggered:
- 1. Prompt user for a voice clip if not already provided.
- Save the audio file to a temp location (e.g.,
/tmp/music-identify-<timestamp>.ogg). The host agent handles downloading audio from the messaging platform (Telegram, Discord, etc.) — this skill only needs the local file path. - Run identification:
scripts/identify.sh /path/to/audio-file.ogg
- 4. Parse the JSON result and respond.
- If Spotify is configured and active, queue the track.
- Log the identification to
memory/music-log.json.
Supported formats: OGG/Opus, MP3, WAV, FLAC, M4A. No transcoding needed — AudD accepts all common audio formats.
Workflow — Spotify Queue
After a successful identification, if Spotify tokens exist at ~/.config/spotify/tokens.json:
CODEBLOCK3
If no active Spotify session is found, fall back to returning the Spotify link only.
Token refresh is handled automatically by spotify-queue.sh on 401 responses.
Response Format
- - Found:
🎵 {title} by {artist} + Spotify link on next line. If Spotify active, note it was queued. - Found, no Spotify match:
🎵 {title} by {artist} (no link) - Not found: "Couldn't identify that one. Try a longer clip with more of the melody (5+ seconds works best)."
- Error: "Something went wrong with the identification. Try again."
- Missing AudD key: "AudD API key not configured. Get one at https://audd.io and save to ~/.config/audd/api_key"
Memory Logging
Append identified songs to memory/music-log.json (one JSON object per line):
CODEBLOCK4
Create the file if it doesn't exist. For recall queries, read and present this log.
Scripts
| Script | Purpose | Dependencies |
|---|
| INLINECODE19 | POST audio to AudD, return JSON | curl, jq |
| INLINECODE20 |
One-time Spotify OAuth flow | python3 |
|
scripts/spotify-queue.sh queue <uri> | Queue track to active Spotify | curl, jq |
|
scripts/spotify-queue.sh status | Check current Spotify playback | curl, jq |
Exit codes for identify.sh: 0=found, 1=not found, 2=error.
API Reference
See references/audd-api.md for AudD endpoint details, parameters, and response format.
音乐识别
通过AudD识别音频中的歌曲,返回包含Spotify链接的歌曲信息,并可选择将歌曲加入用户当前活跃的Spotify会话队列。
运行时依赖
需要在$PATH中安装:
- - curl — 向AudD和Spotify API发送HTTP请求
- jq — 解析所有API响应的JSON数据
- python3 — 仅用于Spotify OAuth认证流程(scripts/spotify-auth.py)
凭证信息
| 凭证 | 位置 | 是否必需 | 用途 |
|---|
| AudD API密钥 | ~/.config/audd/api_key | 是 | 歌曲识别 |
| Spotify OAuth令牌 |
~/.config/spotify/tokens.json | 否(可选) | 加入Spotify队列 |
| Spotify应用凭证 | ~/.config/spotify/credentials.json | 否(可选) | 令牌刷新 |
安全说明:
- - 所有凭证文件应设置权限:chmod 600。
- 本技能不会读取、存储或访问任何平台令牌(Telegram、Discord等)。来自消息平台的音频文件下载由宿主代理处理,而非本技能。
触发方式
- - 用户发送/songsearch后跟语音消息或音频文件
- 用户要求识别音频中的歌曲(这是什么歌、识别这首歌、类似Shazam)
- 用户要求回忆之前识别过的歌曲(那首歌是什么、我之前Shazam过什么)
设置
AudD API密钥(必需)
- 1. 在注册(免费套餐:300次请求,无需信用卡)
- 保存密钥:
bash
mkdir -p ~/.config/audd
echo YOUR
KEY > ~/.config/audd/apikey
chmod 600 ~/.config/audd/api_key
Spotify集成(可选)
- 1. 在创建Spotify开发者应用
- 将重定向URI设置为你的回调URL
- 保存凭证:
bash
mkdir -p ~/.config/spotify
cat > ~/.config/spotify/credentials.json << EOF
{client
id: ..., clientsecret: ..., redirect_uri: https://your-host/callback}
EOF
chmod 600 ~/.config/spotify/credentials.json
- 4. 运行认证流程:python3 scripts/spotify-auth.py
- 在浏览器中打开打印的URL,授权后令牌将自动保存
- chmod 600 ~/.config/spotify/tokens.json
工作流程 — 歌曲识别
当触发歌曲识别时:
- 1. 如果用户尚未提供语音片段,提示用户提供。
- 将音频文件保存到临时位置(例如/tmp/music-identify-.ogg)。宿主代理负责从消息平台(Telegram、Discord等)下载音频——本技能仅需要本地文件路径。
- 运行识别:
bash
scripts/identify.sh /path/to/audio-file.ogg
- 4. 解析JSON结果并回复。
- 如果已配置Spotify且处于活跃状态,将曲目加入队列。
- 将识别记录写入memory/music-log.json。
支持的格式: OGG/Opus、MP3、WAV、FLAC、M4A。无需转码——AudD接受所有常见音频格式。
工作流程 — Spotify队列
成功识别后,如果~/.config/spotify/tokens.json中存在Spotify令牌:
bash
检查是否有内容正在播放
scripts/spotify-queue.sh status
将识别到的曲目加入队列
scripts/spotify-queue.sh queue spotify:track:
如果未找到活跃的Spotify会话,则仅返回Spotify链接。
令牌刷新由spotify-queue.sh在收到401响应时自动处理。
响应格式
- - 找到匹配:🎵 {歌曲名} by {艺术家} + 下一行的Spotify链接。如果Spotify活跃,注明已加入队列。
- 找到匹配,无Spotify匹配:🎵 {歌曲名} by {艺术家}(无链接)
- 未找到:无法识别该音频。请尝试录制更长的片段,包含更多旋律(5秒以上效果最佳)。
- 错误:识别过程中出现问题,请重试。
- 缺少AudD密钥:未配置AudD API密钥。请前往https://audd.io获取密钥并保存至~/.config/audd/api_key
记忆记录
将识别到的歌曲追加到memory/music-log.json(每行一个JSON对象):
json
{date:2026-03-22,time:14:30,title:Viva La Vida,artist:Coldplay,album:Viva la Vida,spotify:https://open.spotify.com/track/...}
如果文件不存在则创建。对于回忆查询,读取并展示此日志。
脚本
| 脚本 | 用途 | 依赖 |
|---|
| scripts/identify.sh <audio_file> | 将音频POST到AudD,返回JSON | curl, jq |
| scripts/spotify-auth.py [--url] |
一次性Spotify OAuth认证流程 | python3 |
| scripts/spotify-queue.sh queue | 将曲目加入活跃Spotify队列 | curl, jq |
| scripts/spotify-queue.sh status | 检查当前Spotify播放状态 | curl, jq |
identify.sh的退出码:0=找到,1=未找到,2=错误。
API参考
有关AudD端点详情、参数和响应格式,请参阅references/audd-api.md。