Concept

Stream health: URLs that work, notifications 650 and 651, and fixes

Keep AudD stream recognition running: the stream URLs addStream accepts, how getStreams and the notification codes 0, 650 and 651 tell you a stream has a problem, how to fix it with setStreamUrl, and what error 902 means.

view .md auddstreamsstream healthnotifications

You can use the AudD real-time music recognition service for audio streams to identify the songs that are being played on radio stations (or any other streams). This guide is for you if you already have streams and want to keep them running. We’ll cover which URLs you can send, how we let you know about problems with the streams, and how you can fix them.

SignalMeaningWhat to do
Notification 0Everything’s fineClose the alert for that stream
Notification 650AudD can’t connect to the streamCheck the URL, change it with setStreamUrl
Notification 651No music from the stream, only white noiseCheck what the stream is playing
stream_running: false in getStreamsMusic isn’t being recognized from the stream nowLook for a 650 or 651
Error 902 from addStreamThe stream limit is reachedRaise the limit, or delete a stream

Stream URLs that work

As the URL of the audio stream, you can simply send the URL of a stream, like https://npr-ice.streamguys1.com/live.mp3. We support most of the stream formats, including DASH, Icecast, HLS, m3u/m3u8. We also natively support Twitch broadcasts and YouTube live streams, and you can send twitch:[channel name], youtube:[video id], and youtube-ch:[channel id] as the URL. Send the shortcut, not the URL of the page:

  • twitch:monstercat for twitch.tv/monstercat: the name of the channel.
  • youtube:5qap5aO4i9A for youtube.com/watch?v=5qap5aO4i9A: the ID of the video.
  • youtube-ch:UC3zwjSYv4k5HKGXCHMpjVRg for the current live stream on youtube.com/channel/UC3zwjSYv4k5HKGXCHMpjVRg: the ID of the channel.
from audd import AudD

audd = AudD("your-api-token")  # get your own token at dashboard.audd.io

audd.streams.add(url="https://npr-ice.streamguys1.com/live.mp3", radio_id=3249)
audd.streams.add(url="twitch:monstercat", radio_id=5513)
audd.streams.add(url="youtube-ch:UC3zwjSYv4k5HKGXCHMpjVRg", radio_id=5514)

The radio_id is any integer that will identify this stream for you. With youtube:, you send the ID of one video. If the channel starts every broadcast as a new video, use youtube-ch: with the ID of the channel instead.

If the station runs its own Icecast, SHOUTcast or AzuraCast server, send the URL of the mount point, not the URL of the status page. To learn which URL to use for Icecast, SHOUTcast and AzuraCast, see Icecast, SHOUTcast and AzuraCast: the stream URL to give AudD.

Note. The test token doesn’t work with streams. Get your own token at dashboard.audd.io and send it as api_token in every request.

Check your streams with getStreams

Use the getStreams method to get all the streams the music is being recognized from. For each stream, you get the radio_id, the url, stream_running, and the longpoll_category. If stream_running is false, the music isn’t being recognized from the stream right now.

from audd import AudD

audd = AudD("your-api-token")

for s in audd.streams.list():
    state = "running" if s.stream_running else "NOT RUNNING"
    print(f"{s.radio_id:>6}  {state:<11}  {s.url}")

This will print something like:

  3249  running      https://npr-ice.streamguys1.com/live.mp3
  5513  NOT RUNNING  twitch:monstercat

If you use the AudD CLI, audd streams list shows the same list with a status for each stream: running, stopped, can't connect (the last notification was 650), or no music (it was 651). You can also add, remove and update streams in the web interface at audd.io/streams.

Notifications: how AudD tells you about a problem

You’ll receive callbacks with results and with notifications. Notifications are information about problems with the streams. 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).

{
  "status": "-",
  "notification": {
    "radio_id": 3,
    "stream_running": false,
    "notification_code": 650,
    "notification_message": "Recognition failed: can't connect to the audiostream"
  },
  "time": 1587939136
}

A notification has "status": "-" instead of "success", and it doesn’t contain songs. The radio_id tells you which stream it’s about. Notifications also contain the time of sending, in time, as Unix seconds. All the fields are in the stream callback payload reference.

Note. The notifications will be sent to the same URL as the results, so your handler has to read both. A callback contains either a result or a notification, never both.

When the stream goes offline: 650

650 means that we can’t connect to the stream. Try to open the URL in a player, or run the following command on a computer outside your network:

ffprobe -hide_banner -v error -show_entries stream=codec_name -of default=nw=1 \
  https://npr-ice.streamguys1.com/live.mp3

If the URL works, you’ll see the codec of the stream, like codec_name=mp3. Any other output means that the URL isn’t a working stream. If the station has moved its stream to a new URL, update the URL with the setStreamUrl method. If the URL is correct but the server is down, the stream has to be fixed on the station’s side.

When the stream plays only noise: 651

651 means that we don’t receive any music from the stream, only white noise. We can connect to the stream, so the URL is fine. Open the stream in a player and listen to it. Check the software and hardware that send the audio to the server, like the encoder or the mixing desk.

When everything’s fine again: 0

0 means that everything’s fine. When you receive a 0 or a new result for the same radio_id, close the alert you raised for the 650 or the 651.

Change a stream’s URL with setStreamUrl

Use the setStreamUrl method to update the URL of a stream. The radio_id stays the same, so the results from the new URL will come with the same radio_id. The longpoll category is calculated from your API token and the radio_id, so a widget that shows the stream keeps working too.

from audd import AudD

audd = AudD("your-api-token")
audd.streams.set_url(radio_id=3249, url="https://new-stream.example/live.mp3")

The same call in curl:

curl https://api.audd.io/setStreamUrl/ \
  -F api_token=your-api-token \
  -F radio_id=3249 \
  -F url=https://new-stream.example/live.mp3

In the CLI, it’s audd streams set-url 3249 https://new-stream.example/live.mp3. You don’t need to delete the stream and add it again to change its URL. Use the deleteStream method only to remove a stream: we’ll stop recognizing music from it and forget about its existence.

When addStream returns error 902

You set the maximum limit of concurrent audio streams on the API Dashboard, and you pay for this number every month, not for the hours. If you add more streams than the limit allows, you’ll get error 902 (the response is shortened here):

{
  "status": "error",
  "error": {
    "error_code": 902,
    "error_message": "Adding a stream stream failed: authorization failed: the limit was reached. (Please check if you have an active subscription for music recognition for audio streams on https://dashboard.audd.io/ or contact us to try it for free: [email protected])"
  },
  "request_api_method": "addStream"
}

Retrying the request won’t help. In this case, you can raise the limit on the dashboard or delete a stream that you no longer need. To see which streams use the limit, call getStreams. In the Python SDK, the error is raised as AudDQuotaError, and its error_code is 902. The other error codes are grouped by category in the error reference.

A small stream monitor

If something happens to one of your streams, the monitor below will let you know by sending an alert so you can fix the stream or change its URL. It also adds the streams from STATIONS that aren’t on the account yet, and lets you know if addStream returns error 902. When the stream is fine again (a 0, or a new result from the same stream), you’ll get one more alert.

pip install audd flask
# monitor.py
import os
import sys
from datetime import datetime, timezone

from flask import Flask, request
from audd import AudD
from audd.errors import AudDAPIError, AudDSerializationError

audd = AudD(os.environ["AUDD_API_TOKEN"])  # get your own token at dashboard.audd.io
app = Flask(__name__)

# radio_id -> stream URL: the streams this monitor looks after
STATIONS = {
    3249: "https://npr-ice.streamguys1.com/live.mp3",
    5513: "twitch:monstercat",
}
PROBLEMS = {
    650: "AudD can't connect to the stream",
    651: "no music from the stream, only white noise",
}
open_problems = {}  # radio_id -> notification code of the open problem


def alert(text):
    # Send this to your pager, chat or email instead of printing it.
    now = datetime.now(timezone.utc)
    print(f"{now:%Y-%m-%d %H:%M:%S} UTC  {text}", file=sys.stderr, flush=True)


def add_missing_streams():
    existing = {s.radio_id for s in audd.streams.list()}
    for radio_id, url in STATIONS.items():
        if radio_id in existing:
            continue
        try:
            audd.streams.add(url=url, radio_id=radio_id)
        except AudDAPIError as e:
            if e.error_code in (902, 610):
                alert(f"stream {radio_id} not added: the stream limit is reached; "
                      "raise it at dashboard.audd.io or delete a stream you don't need")
            else:
                alert(f"stream {radio_id} not added: #{e.error_code} {e.message}")


@app.post("/audd-callback")
def audd_callback():
    try:
        match, notification = audd.streams.handle_callback(request)
    except AudDSerializationError as e:
        print(f"not an AudD callback: {e}", file=sys.stderr)
        return "", 200  # answer 200 so a bad body isn't queued and re-sent
    if notification:
        radio_id = notification.radio_id
        code = notification.notification_code
        if code in PROBLEMS and open_problems.get(radio_id) != code:
            open_problems[radio_id] = code
            sent = datetime.fromtimestamp(notification.time or 0, timezone.utc)
            alert(f"stream {radio_id}: {code}, {PROBLEMS[code]} "
                  f"(sent {sent:%H:%M:%S} UTC)")
        elif code == 0 and radio_id in open_problems:
            del open_problems[radio_id]
            alert(f"stream {radio_id}: everything's fine again")
    elif match and match.radio_id in open_problems:
        del open_problems[match.radio_id]
        alert(f"stream {match.radio_id}: songs are being recognized again")
    return "", 200


if __name__ == "__main__":
    add_missing_streams()
    app.run(host="0.0.0.0", port=8080)
AUDD_API_TOKEN=your-api-token python monitor.py

To be able to receive callbacks from AudD, your server needs to be accessible from the web. The monitor listens on port 8080, so put it behind a reverse proxy with a public address. Then set the URL for callbacks using the setCallbackUrl API method:

from audd import AudD

audd = AudD("your-api-token")
audd.streams.set_callback_url("https://monitor.example.com/audd-callback")

There is no per-stream callback URL: the callbacks from all the streams will be sent to the specified URL. If another service already receives your results, add this code to that service instead. The handler responds with 200 OK to every callback. 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.

The open problems are only kept in memory and are lost when the monitor restarts. If you want them to survive a restart, save them in a database.

The callbacks aren’t signed, so anyone can send a request to this URL. For more information, see Securing your callback endpoint. If you want to test the handler locally, see Test callbacks locally.


Related

Reading this as an AI agent? The raw Markdown is at concepts/stream-health.md, and the full index is /resources/llms.txt.