AudioRtp

source extra: audio-rtp

Receive an RTP audio stream with PyAV, resample it, and transmit it in fixed-length chunks of block_size seconds.

Node type:

AudioRtp

Input:

–

Output:

AudioPayload

Extra:

audio-rtp

$ pip install "juturna-nodes[audio-rtp]"

How it works

On warmup the node writes an SDP file, _session_in.sdp, in its pipeline folder, describing a stream on host:port with payload_type and encoding_clock_chan. On start, a worker opens that SDP with PyAV and listens for RTP packets on the port. Start the pipeline first, then the sender: packets sent before the node listens are lost, without any error.

The decoded audio is resampled to out_rate, out_channels and resampler_format, and cut into chunks of block_size seconds.

The input is opened and read with a timeout of JUTURNA_THREAD_JOIN_TIMEOUT seconds, 2 s by default (the times below assume the default). When no packet arrives for 2 s (the sender stopped, or never started), the node closes the input and opens it again: without traffic this happens about every 4 s, and only shows up in the log at DEBUG level (demux terminate while reading False). When the input is closed, the samples still pending are transmitted as a last chunk, padded with zeros to block_size when flush_partial_on_error is true, and dropped otherwise. If the input cannot be opened at all, for example because another process uses the port, the node logs source unavailable (...), retrying... at ERROR level and tries again every 2 s, until it succeeds or the node stops.

The UDP receive buffer is 64 KB, so short bursts of packets are not dropped. stop() returns within a few seconds.

Arguments

Argument

Type

Default

Description

host

str

"127.0.0.1"

Address the stream is received on

port

int

8888

UDP port of the stream; 0 picks a free port when the node is configured

payload_type

int

97

RTP payload type of the stream

encoding_clock_chan

str

"opus/48000/2"

Encoding name, clock rate and channels, as in an SDP rtpmap line

out_rate

int

16000

Sampling rate of the transmitted audio, in Hz

out_channels

int

1

Channels of the transmitted audio

resampler_format

str

"dblp"

Sample format of the transmitted audio, as named by PyAV: one of flt, fltp (float32), dbl, dblp (float64), s16, s16p, s32, s32p, u8, u8p

block_size

int

3

Length of each chunk, in seconds

flush_partial_on_error

bool

true

Transmit the pending samples, padded with zeros, when the input is closed

For telephony audio, G.711 µ-law at 8 kHz mono (from a PBX such as Asterisk, a Janus RTP forwarder, or ffmpeg ... -ac 1 -ar 8000 -c:a pcm_mulaw -f rtp rtp://127.0.0.1:5004), use encoding_clock_chan: "PCMU/8000" ("PCMU/8000/1" works the same) and set payload_type to the type the sender uses: 0 is the static type of PCMU, but a sender may be configured with a dynamic one. The string is written as is in the SDP rtpmap line, and the audio is resampled from 8 kHz to out_rate. The example at the end of this page receives such a stream.

License

  • Code: this node is part of juturna-nodes, MIT (its LICENSE file).

  • PyAV: BSD-3-Clause (the License-Expression of av on PyPI).

  • FFmpeg: effectively GPL. The PyAV wheels on PyPI bundle their own FFmpeg: av 19.0.2 ships FFmpeg 9.0.2 from the pyav-ffmpeg 9.0.2-4 build, which links x264 and x265 (GPL-2.0-or-later). The FFmpeg legal page says that when its GPL parts are used, “the GPL applies to all of FFmpeg”. The libraries still report “LGPL version 3 or later” only because a pyav-ffmpeg patch to FFmpeg’s configure moves x264 and x265 out of the libraries that need --enable-gpl. A PyAV built from source against an LGPL build of FFmpeg (without x264, x265 or other GPL parts) avoids the GPL. (Checked on 2026-11-18 on av 19.0.2.)

  • NumPy: BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0 (the License-Expression of numpy on PyPI).

Configuration

Default node arguments, as defined in the node config.toml file. Any of them can be overridden in the node configuration of a pipeline.

[arguments]
host = "127.0.0.1"
port = 8888
payload_type = 97
encoding_clock_chan = "opus/48000/2"
out_rate = 16000
out_channels = 1
resampler_format = "dblp"
block_size = 3
flush_partial_on_error = true

[meta]

Argument

Type

Description

host

str

Address the stream is received on

port

int

UDP port of the stream; 0 picks a free port when the node is configured

payload_type

int

RTP payload type of the stream

encoding_clock_chan

str

Encoding name, clock rate and channels, as in an SDP rtpmap line

out_rate

int

Sampling rate of the transmitted audio, in Hz

out_channels

int

Channels of the transmitted audio

resampler_format

str

Sample format of the transmitted audio, as named by PyAV: one of flt, fltp (float32), dbl, dblp (float64), s16, s16p, s32, s32p, u8, u8p

block_size

int

Length of each chunk, in seconds

flush_partial_on_error

bool

Transmit the pending samples, padded with zeros, when the input is closed

For G.711 µ-law at 8 kHz, as sent by ffmpeg ... -ac 1 -ar 8000 -c:a pcm_mulaw -f rtp rtp://127.0.0.1:5004, use payload_type: 0 and encoding_clock_chan: "PCMU/8000".

Input message

The node has no input: it reads the RTP stream.

Output message

Field

Content

payload.audio

out_rate * block_size samples, with the dtype of resampler_format; with out_channels: 2 the samples are interleaved

payload.sampling_rate

out_rate

payload.channels

out_channels

payload.audio_format

resampler_format

payload.start, payload.end

Seconds from the time the input was opened. They start again from 0.0 every time the input is opened again, so after every pause of more than 2 s

version

Number of chunks transmitted by the node, from 0

meta is empty, and the message has no timers.

Limits

  • The end of a stream is not propagated downstream: the node only stops transmitting. A downstream node waiting for silence, such as a transcriber, keeps its sentence open until more audio comes or the pipeline stops.

Pipeline usage

{
  "name": "question",
  "type": "AudioRtp",
  "configuration": {
    "port": 5004,
    "payload_type": 0,
    "encoding_clock_chan": "PCMU/8000",
    "resampler_format": "flt",
    "block_size": 1
  }
}

Reference

class AudioRtp(
host: str,
port: int,
payload_type: int,
encoding_clock_chan: str,
out_rate: int,
out_channels: int,
resampler_format: str,
block_size: int,
flush_partial_on_error: bool,
**kwargs,
)

Node implementation class