Identify a song from a link with an iPhone Shortcut
Build an iPhone Shortcut that sends a link to an audio file to AudD from the share sheet and shows the artist, title and song link, with the no-match and error cases handled.
You can build a Shortcut that recognizes music from links on your iPhone. When you share a link to an audio file with it, it sends the link to AudD’s Music Recognition API with your token. AudD’s response will contain the title and artist of the song, and a link to the song’s lis.tn page. The Shortcut shows them in an alert.
If the music is playing around you, the Recognize Music button that’s built into iPhone is the better tool. This Shortcut is for a song in a file that you have a link to, and it uses your own AudD account.
What you need
- An API token. You can get a token from our API Dashboard. For a first try, the public
testtoken allows 10 requests a day. - A link to an audio file (a link to a video file sometimes works too). Our standard endpoint is for short clips: it recognizes the first 12 seconds of the audio.
The finished Shortcut
These are the actions you’ll build, from top to bottom:
- The input action: URLs from the share sheet, or Get Clipboard if there’s no input
- URL:
https://api.audd.io/ - Get Contents of URL: POST, with a Form request body:
api_tokenandurl - Get Value for
statusin Contents of URL - If Dictionary Value is not
success: Get Value forerror.error_messagein Contents of URL, Show Alert, Stop Shortcut - End If
- Get Value for
result.song_linkin Contents of URL - If Dictionary Value contains
lis.tn: Get Value forresult.artist, Get Value forresult.title, Show Alert with the song - Otherwise: Show Alert that there’s no match
- End If
Build it
Create the Shortcut and let it take links
- Open the Shortcuts app on your iPhone and tap the Add button to create a new shortcut.
- Give it a name: tap New Shortcut, tap Rename, type the name, then tap the back button.
- To make the shortcut appear in the share sheet, open Details and turn on Show in Share Sheet, then tap Done. A new action appears at the beginning of the shortcut: the input action.
- To accept only links, tap Any in the input action, tap Clear, turn on URLs, and tap Done.
- To use a copied link when you run it from the Shortcuts app, tap Continue in the same action and choose Get Clipboard.
Send the link to AudD
- Add the URL action, and type
https://api.audd.io/in it. To add an action, swipe up on the search field at the bottom of the screen, then choose the action. - Add the Get Contents of URL action after it. It takes the URL from the action before it.
- In Get Contents of URL, tap Show More, and change the method to POST. A new parameter called Request Body appears. Set it to Form.
- Add a text field to the form with the key
api_token, and type your token (your-api-tokenhere) as its value. - Add a second text field with the key
url. Tap its value, then tap Shortcut Input in the Variables bar. You may need to swipe left to see it.
Stop on an error
All the responses contain the status field that equals either success if the request was successfully processed or error if there’s been an error. The Shortcut checks it first.
- Add Get Dictionary Value, and set the key to
status. It reads the output of Get Contents of URL. - Add an If action. Its input is the Dictionary Value from the action before it. Set the condition to is not, and type
success. - Inside the If, add Get Dictionary Value with the key
error.error_message. Set its Dictionary to the output of Get Contents of URL: tap the parameter and choose the Contents of URL variable. - Add Show Alert after it. Type
AudD returned an error:in its text, then tap Select Variable and tap the Dictionary Value under the action before it. - Add Stop Shortcut after Show Alert. Leave the Otherwise part of this If empty.
Show the song, or say there’s no match
If the server has successfully processed the request, but there are no matches, the result field is null. So the Shortcut checks the song_link before it reads the name: every match has a link to the song’s lis.tn page.
- After End If, add Get Dictionary Value with the key
result.song_link, and set its Dictionary to Contents of URL. - Add an If action with the condition contains, and type
lis.tn. - Inside the If, add two Get Dictionary Value actions with the keys
result.artistandresult.title. Set the Dictionary of both to Contents of URL. - Add Show Alert. In its text, use Select Variable to insert the artist, the title, and the song link: tap the blue token under each Get Dictionary Value action.
- After Otherwise, add Show Alert with a message such as
No match. AudD recognizes the first 12 seconds of the file. - Tap Done.
Try it
- In the
api_tokenfield, typetestinstead of your token for now. - Copy this link:
https://audd.tech/example.mp3. - Open the shortcut in the shortcut editor and tap the Run button. If a Privacy dialog appears, choose Allow Once or Always Allow.
- You should see an alert with Tears For Fears, Everybody Wants To Rule The World, and
https://lis.tn/NbkVb. - Replace
testwith your own token.
To identify a song from a link in Safari or another app, tap the Share button, scroll down, and pick the Shortcut. A notification shows the progress of each action while the Shortcut runs.
What AudD sends back
A match
The response is JSON. The Shortcut reads status, then artist, title and song_link inside result:
{
"status": "success",
"result": {
"artist": "Tears For Fears",
"title": "Everybody Wants To Rule The World",
"album": "Songs From The Big Chair",
"release_date": "2014-11-10",
"label": "UMC (Universal Music Catalogue)",
"timecode": "00:56",
"song_link": "https://lis.tn/NbkVb"
}
}
When result is null
If there are no matches, the response looks like this:
{
"status": "success",
"result": null
}
The clip might be mostly speech or silence, or the song might not be in our database. The standard endpoint only recognizes the first 12 seconds, so if the song starts later in the file, it won’t be found.
When status is error
If there’s been an error, status is error, and the API returns an explanation of what happened:
{
"status": "error",
"error": {
"error_code": 900,
"error_message": "Recognition failed: authorization failed: the provided api_token is incorrect, invalid, or inactive. Please check the status of your account on dashboard.audd.io: it needs to have either a trial or an active subscription."
}
}
The common errors are about the token (it’s wrong, the account has no trial or plan, or the test token has used its 10 requests for the day) and about the link (AudD can’t download it, or it isn’t a file AudD can read). The Error codes reference lists them.
Keep your token private
The Shortcut includes your API token, in the api_token field of the Get Contents of URL action. You can share other shortcuts with your friends, but please don’t share this one, and don’t post screenshots of that action. Anyone who has your token can send requests with it. If you’ve already shared it with an iCloud link, stop sharing it.
For a leaked token, rotate the token in the dashboard, copy the new one, and paste it into the api_token field of the Shortcut. The old token stops working immediately.
A token on your own iPhone is fine for your own use, but an app you give to other people shouldn’t contain one; see Keeping your API token on the server.
What it costs
Each run sends 1 request. New accounts get a free trial of 300 requests where available. You can find the usage stats for your API token on dashboard.audd.io, and all the plans on our pricing page.
Related
Reading this as an AI agent? The raw Markdown is at integrations/ios-shortcuts.md, and the full index is /resources/llms.txt.
