使用 AudD API 识别音频片段中的歌曲,可选加入 Spotify 队列。触发方式:/songsearch 命令或语音消息进行歌曲识别。
Identify songs from audio using AudD, return song info with Spotify link, and optionally queue to the user's active Spotify session.
Required on $PATH:
curl — HTTP requests to AudD and Spotify APIsjq — JSON parsing for all API responsespython3 — Spotify OAuth flow only ( scripts/spotify-auth.py)CredentialLocationRequiredPurposeAudD API key~/.config/audd/api_keyYesSong identificationSpotify OAuth tokens~/.config/spotify/tokens.jsonNo (optional)Queue to SpotifySpotify app credentials~/.config/spotify/credentials.jsonNo (optional)Token refresh
Security notes:
chmod 600./songsearch then follows with a voice message or audio fileSign up at https://audd.io (free tier: 300 requests, no credit card)
Save key: bash
mkdir -p ~/.config/audd
echo "YOUR_KEY" > ~/.config/audd/api_key
chmod 600 ~/.config/audd/api_key
Create a Spotify Developer app at https://developer.spotify.com/dashboard
Set redirect URI to your callback URL
Save credentials: bash
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
Run the auth flow: python3 scripts/spotify-auth.py
Open the printed URL in a browser, authorize, tokens save automatically
chmod 600 ~/.config/spotify/tokens.json
When a song identification is triggered:
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: bash
scripts/identify.sh /path/to/audio-file.ogg
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.
After a successful identification, if Spotify tokens exist at ~/.config/spotify/tokens.json:
bash
# Check if anything is playing
scripts/spotify-queue.sh status
# Queue the identified track
scripts/spotify-queue.sh queue "spotify:track:<track_id>"
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.
🎵 {title} by {artist} + Spotify link on next line. If Spotify active, note it was queued.🎵 {title} by {artist} (no link)Append identified songs to memory/music-log.json (one JSON object per line):
json
{"date":"2026-03-22","time":"14:30","title":"Viva La Vida","artist":"Coldplay","album":"Viva la Vida","spotify":"https://open.spotify.com/track/..."}
Create the file if it doesn't exist. For recall queries, read and present this log.
ScriptPurposeDependenciesscripts/identify.sh <audio_file>POST audio to AudD, return JSONcurl, jqscripts/spotify-auth.py [--url]One-time Spotify OAuth flowpython3scripts/spotify-queue.sh queue <uri>Queue track to active Spotifycurl, jqscripts/spotify-queue.sh statusCheck current Spotify playbackcurl, jq
Exit codes for identify.sh: 0=found, 1=not found, 2=error.
See references/audd-api.md for AudD endpoint details, parameters, and response format.