Integration

Recognize songs and receive stream results in n8n

Two n8n workflows for AudD: an HTTP Request node that sends the URL of a short audio file and reads the artist and title, and a Webhook node that receives stream results as the AudD callback URL and adds a Google Sheets row for every song. With importable workflow JSON.

view .md auddn8nhttp request nodewebhook node

With n8n, you can send the URL of an audio file to AudD and receive the recognition results from your streams in a workflow. No code is required, only the built-in nodes. In this guide, you’ll build two workflows:

  1. Recognize a file. You send us the URL of a short audio file with the HTTP Request node, and we send you back the song.
  2. Receive stream results. You send us the URLs of radio streams, and we send you the recognition results in real time, to a Webhook node that adds a row to Google Sheets for every song.

Here are the settings of the HTTP Request node:

FieldValue
MethodPOST
URLhttps://api.audd.io/
AuthenticationGeneric Credential Type
Generic Auth TypeQuery Auth
Send Bodyon
Body Content TypeForm-Data
Body fieldName url, Value https://audd.tech/example.mp3

Both workflows are also available as JSON that you can paste into n8n. If you use Zapier or Make, see Recognize songs and receive stream results in Zapier and Make for the same two jobs.

Before you start

To send requests, get a token from the Dashboard. The test token works for the first workflow, but it’s limited to 10 requests a day on the standard endpoint, and the streams methods don’t accept it. For the second workflow, you’ll need a stream: the music recognition costs $45 per audio stream per month with our music DB, and new accounts that get the free trial may also get a 3-day trial of one stream.

To be able to receive callbacks from AudD, your n8n needs to be accessible from the web over HTTPS. That’s the case with n8n Cloud; if you run n8n on your own computer, see Test stream callbacks locally.

Store the token in an n8n credential

All the API requests require the api_token to be specified as either the query parameter or the POST field. So you can keep the token in an n8n credential, and n8n will add it to the query string for you. Here are the settings for the credential:

FieldValue
Authentication (in the HTTP Request node)Generic Credential Type
Generic Auth TypeQuery Auth
Name (in the credential)api_token
Value (in the credential)your API token

With this credential, n8n adds the token to every request. The token isn’t in the workflow itself, so you can download and share the workflow, and the JSON won’t contain your token.

Workflow 1: recognize a file from a URL

Send the request

The workflow starts with a Manual Trigger node, followed by the HTTP Request node with the settings above, so you can run it by selecting Execute workflow. By default, the API responses are in JSON format, and you’ll see ours in the output of the HTTP Request node:

{
  "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"
  }
}

In the nodes after it, {{ $json.result.artist }} is the artist and {{ $json.result.title }} is the title. If there are matches, result always contains artist, title, album, release_date, label, timecode, and song_link fields. And just in case: timecode is the time in the recognized song when the fragment you sent is played; song_link links to a lis.tn song page. See Recognition result fields for the rest.

The standard endpoint accepts uploaded files up to 10 MB and analyzes up to the first 12 seconds of audio. If you need to recognize larger audio files, use the enterprise endpoint instead: see Long recordings below.

If you want to recognize the files from another app, use its trigger instead of the Manual Trigger. Then drag the field with the URL of the file into the url body field.

When result is null

{
  "status": "success",
  "result": null
}

If the server has successfully processed the request, but there are no matches, status is success and result is null, like in the example above. Please note that it isn’t an error: it means that the request went fine and we didn’t find any match. So check for null before reading the fields: add an If node after the HTTP Request node. The If node has the following settings:

FieldValue
Node nameMatch?
ConditionObject > exists
Value{{ $json.result }}

Connect the nodes that use the song to the true output. If there are no matches, the item goes to the false output: the clip might be mostly speech or silence, or the song might not be in our database.

When AudD returns an error

{
  "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."
  }
}

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 errors come with the HTTP status 200 too, and the body has an error object with the error_code and the error_message, like in the example above. So make sure you check the status before you read the result. Put another If node in front of “Match?”; it has the following settings:

FieldValue
Node nameRequest OK?
ConditionString > is equal to
Value 1{{ $json.status }}
Value 2success
True outputthe “Match?” node
False outputa Stop and Error node
Error Message (Stop and Error)AudD error {{ $json.error.error_code }}: {{ $json.error.error_message }}

If the request failed, the false output gets the response. Use the Stop and Error node there to display a custom error message with the error code, and to cause the execution to fail.

We have about 40 different error codes, and the API returns the errors with an explanation of what happened. If you want to know more about a code, see the error codes reference, where they’re grouped by category. Note that the HTTP Request node stops with an error on a 4xx or 5xx status: such a response comes from the network in front of the API, not from the API.

Import workflow 1

Copy the workflow shown below and paste it into the canvas of a new workflow. All you have to change is the credential in the Recognize with AudD node.

{
  "name": "AudD: recognize a song from a URL",
  "nodes": [
    {
      "parameters": {},
      "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e01",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [0, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.audd.io/",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formData",
              "name": "url",
              "value": "https://audd.tech/example.mp3"
            }
          ]
        },
        "options": {}
      },
      "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e02",
      "name": "Recognize with AudD",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [220, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e11",
              "leftValue": "={{ $json.status }}",
              "rightValue": "success",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e03",
      "name": "Request OK?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [440, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e12",
              "leftValue": "={{ $json.result }}",
              "rightValue": "",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e04",
      "name": "Match?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [660, -100]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e21",
              "name": "artist",
              "value": "={{ $json.result.artist }}",
              "type": "string"
            },
            {
              "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e22",
              "name": "title",
              "value": "={{ $json.result.title }}",
              "type": "string"
            },
            {
              "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e23",
              "name": "song_link",
              "value": "={{ $json.result.song_link }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e05",
      "name": "Song",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [880, -200]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e31",
              "name": "message",
              "value": "No match",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e06",
      "name": "No match",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [880, 0]
    },
    {
      "parameters": {
        "errorMessage": "=AudD error {{ $json.error.error_code }}: {{ $json.error.error_message }}"
      },
      "id": "5f0b8a52-7c1e-4d2a-9b3e-1a2b3c4d5e07",
      "name": "AudD error",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [660, 200]
    }
  ],
  "connections": {
    "Start": {
      "main": [[{ "node": "Recognize with AudD", "type": "main", "index": 0 }]]
    },
    "Recognize with AudD": {
      "main": [[{ "node": "Request OK?", "type": "main", "index": 0 }]]
    },
    "Request OK?": {
      "main": [
        [{ "node": "Match?", "type": "main", "index": 0 }],
        [{ "node": "AudD error", "type": "main", "index": 0 }]
      ]
    },
    "Match?": {
      "main": [
        [{ "node": "Song", "type": "main", "index": 0 }],
        [{ "node": "No match", "type": "main", "index": 0 }]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}

Workflow 2: receive stream results with a Webhook node

Callbacks are the requests with recognition results our servers will send to your server. In this workflow, your server is n8n: the Production URL of a Webhook node becomes the callback URL of your account, and the workflow adds a row to a Google Sheets spreadsheet for every song.

Set up the Webhook node

Here are the settings of the Webhook node:

FieldValue
HTTP MethodPOST
Paththe random path n8n generated
RespondImmediately

The callbacks will be sent to the specified URL as a JSON structure in the POST payload, so the HTTP Method has to be POST, not the default GET. Keep the random Path: the callbacks aren’t signed, and the path is what keeps other people from sending requests to your workflow. Please ensure that your handler responds with the 200 OK HTTP status when it receives the callbacks: with Respond set to Immediately, n8n does it as soon as a request arrives.

Try it with a sample callback

To test the workflow, select Listen for test event and send a sample callback to the Test URL within 120 seconds. Here’s an example of a callback with a result:

TEST_URL='paste the Test URL here'

curl -X POST "$TEST_URL" \
  -H 'Content-Type: application/json' \
  -d '{"status":"success","result":{"radio_id":7,"timestamp":"2020-04-13 10:31:43","play_length":111,"results":[{"artist":"Alan Walker, A$AP Rocky","title":"Live Fast (PUBGM)","album":"Live Fast (PUBGM)","release_date":"2019-07-25","label":"MER Recordings","score":100,"song_link":"https://lis.tn/LiveFastPUBGM"}]}}'

If you don’t use a terminal, you can send the same JSON from an HTTP Request node in another workflow: set the Method to POST, paste the Test URL, choose JSON as the Body Content Type, and paste the JSON from the command above.

The node’s output shows the whole request. Our JSON is under body, next to headers, params, and query, so the radio ID is {{ $json.body.result.radio_id }} and the songs are in {{ $json.body.result.results }}. The stream callback payload reference has the exact bodies of both kinds of callbacks.

Note. n8n turns our JSON into fields under body only if the Content-Type of the request is application/json, as in the sample, and we don’t document the Content-Type of our callbacks. If a real callback doesn’t show our fields under body, turn on Raw Body in the options of the Webhook node, then add an Extract from File node with the Extract From JSON operation: the fields are then in its output, under data.

Results and notifications

You’ll receive callbacks with results and with notifications. The results contain the recognized songs, and notifications are information about the state of the streams. A callback contains either result or notification, never both, so the workflow checks which one it got. Here are the nodes:

NodeSettings
If (“Result?”)Object > exists, {{ $json.body.result }}
Split Out (on the true output)Fields To Split Out body.result.results, Include No Other Fields
Edit Fields (Set) (“Row”)the six fields in the next table
Google SheetsAppend Row, your Document and Sheet, Mapping Column Mode Map Automatically

There can be several songs in one callback, so read all the objects in the results array, not just the first one: the Split Out node makes one item for each song. The Edit Fields node takes the other fields from the Webhook node, which is called “AudD callback” in the JSON below. Make sure that the first row of your sheet has the same six names: n8n puts each value into the column with the same name.

NameValue
radio_id{{ $('AudD callback').item.json.body.result.radio_id }}
timestamp{{ $('AudD callback').item.json.body.result.timestamp }}
artist{{ $json.artist }}
title{{ $json.title }}
play_length{{ $('AudD callback').item.json.body.result.play_length }}
song_link{{ $json.song_link }}

If something happens to an audio stream, we’ll let you know by sending a notification so you can fix the stream or change its URL. There are 3 codes: 0 (which means that everything’s fine), 650 (which means that we can’t connect to the stream) and 651 (which means that we don’t receive any music from the stream, only white noise). The notifications go to the false output of “Result?”, and a second If node, “Stream problem?” (Number > is not equal to, {{ $json.body.notification.notification_code }} and 0), lets the codes that aren’t 0 through to a Stop and Error node. You can also send yourself an email or a chat message here instead. For more information on fixing the stream, see Stream health.

Publish the workflow and set the callback URL

When your workflow is ready, switch to using the Production URL. Publish the workflow, then copy the Production URL from the top of the Webhook node: n8n will run the workflow automatically when we call it. Don’t send us the Test URL: it only listens for 120 seconds after you select Listen for test event.

Then set the URL for callbacks using the setCallbackUrl API method:

curl https://api.audd.io/setCallbackUrl/ \
  -F api_token=your-api-token \
  -F url='paste the Production URL here'

You can also set it with the AudD CLI, audd streams callback set 'paste the Production URL here', or in the web interface. There is no per-stream callback URL: the callbacks from all the streams will be sent to the specified URL. If you already receive callbacks somewhere else, the new URL replaces the old one, so the sheet will get the songs from every stream on the account. The radio_id in each row tells you which stream it was.

If you haven’t added a stream yet, add one with the addStream API method or with audd streams add https://npr-ice.streamguys1.com/live.mp3 --id 1. You’ll receive the first result seconds or minutes after you add the stream, and then one result for every new song. By default, we will send new results after songs end playing, with the played time in play_length. If you add the stream with callbacks=before, you’ll get them as soon as the songs start, without play_length.

When the workflow is unpublished

While the workflow is unpublished, n8n responds to the Production URL with 404. If your server doesn’t respond to the callbacks with the 200 OK status or we can’t connect to your server, we’ll put the callbacks in a queue. When your server is back online, we’ll gradually send all of the backlog. So if you unpublish the workflow for a while, the songs we recognize meanwhile will be added to the sheet after you publish it again. They can arrive late and out of order, so use the timestamp in each row instead of the time the row was added.

Note that we put a callback in the queue only if your server doesn’t respond with the 200 OK status. n8n responds before the Google Sheets node runs, so if that node fails, we won’t send the callback again; you’ll find its data in the failed execution in the Executions tab.

Keep the URL private

The callbacks aren’t signed, so anyone who knows the Production URL can send a fake result to it. Please don’t share screenshots or exported workflows that show the path. If someone else got the URL, change the path, publish the workflow again, and send us the new Production URL using the setCallbackUrl method. For more information, see Securing your callback endpoint.

Import workflow 2

Paste the workflow shown below into the canvas of a new workflow. n8n will give the Webhook node a new random path, so the URL you send us will be different from anyone else’s. After that, connect your Google account in Append row in sheet and pick your spreadsheet. Make sure that the first row of the sheet has the six names from the table above.

{
  "name": "AudD: stream results to Google Sheets",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "",
        "options": {}
      },
      "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d01",
      "name": "AudD callback",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d11",
              "leftValue": "={{ $json.body.result }}",
              "rightValue": "",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d02",
      "name": "Result?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [220, 0]
    },
    {
      "parameters": {
        "fieldToSplitOut": "body.result.results",
        "include": "noOtherFields",
        "options": {}
      },
      "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d03",
      "name": "One item per song",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [440, -100]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d21",
              "name": "radio_id",
              "value": "={{ $('AudD callback').item.json.body.result.radio_id }}",
              "type": "number"
            },
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d22",
              "name": "timestamp",
              "value": "={{ $('AudD callback').item.json.body.result.timestamp }}",
              "type": "string"
            },
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d23",
              "name": "artist",
              "value": "={{ $json.artist }}",
              "type": "string"
            },
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d24",
              "name": "title",
              "value": "={{ $json.title }}",
              "type": "string"
            },
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d25",
              "name": "play_length",
              "value": "={{ $('AudD callback').item.json.body.result.play_length }}",
              "type": "number"
            },
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d26",
              "name": "song_link",
              "value": "={{ $json.song_link }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d04",
      "name": "Row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [660, -100]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d05",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [880, -100]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d12",
              "leftValue": "={{ $json.body.notification.notification_code }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d06",
      "name": "Stream problem?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [440, 120]
    },
    {
      "parameters": {
        "errorMessage": "=Stream {{ $json.body.notification.radio_id }}: {{ $json.body.notification.notification_code }} {{ $json.body.notification.notification_message }}"
      },
      "id": "7c3d9e14-2a5b-4f6c-8d7e-9f0a1b2c3d07",
      "name": "Stream notification",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [660, 120]
    }
  ],
  "connections": {
    "AudD callback": {
      "main": [[{ "node": "Result?", "type": "main", "index": 0 }]]
    },
    "Result?": {
      "main": [
        [{ "node": "One item per song", "type": "main", "index": 0 }],
        [{ "node": "Stream problem?", "type": "main", "index": 0 }]
      ]
    },
    "One item per song": {
      "main": [[{ "node": "Row", "type": "main", "index": 0 }]]
    },
    "Row": {
      "main": [[{ "node": "Append row in sheet", "type": "main", "index": 0 }]]
    },
    "Stream problem?": {
      "main": [[{ "node": "Stream notification", "type": "main", "index": 0 }]]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}

Long recordings: the enterprise endpoint

The standard endpoint is for a short clip with one song. For whole songs, mixes, podcasts, and other long files, change the URL of the HTTP Request node to https://enterprise.audd.io/, and keep the same credential. We count requests to the enterprise endpoint as 1 request per 12 seconds of audio: when you send a file, our servers consider it to be a group of 12-second-long audio chunks.

If you don’t want every one of these chunks to be recognized and counted as the requests, send the limit body field: the upper bound for the number of chunks the server will recognize. With limit set to 5, a file uses at most 5 requests, however long it is. In a workflow that runs on every new file, always set it. To choose limit, skip, and every, see Controlling enterprise endpoint cost.

On the free trial, you can upload files to the enterprise endpoint, but sending it a URL needs a paid plan. If the file comes from an earlier node, change the Type of the body field to n8n Binary File and name it file. Then enter the binary field of that node in Input Data Field Name. The response is different: result is a list of 12-second fragments with the songs in each, and the list is empty if there are no matches. On a long file, the request can take minutes.


Related

Reading this as an AI agent? The raw Markdown is at integrations/n8n.md, and the full index is /resources/llms.txt.