Speex is a CELP speech codec from the Xiph.Org Foundation, usually found in
.spx files. It has been replaced by Opus, but old files remain. In Ogg, a stream
has an 80-byte header packet, a comment packet, any extra headers, and then audio packets.
Header packet
The first packet is 80 bytes. Numbers are little-endian 32-bit integers.
| Offset | Size | Name | Description |
|---|---|---|---|
| 0 | 8 | speex_string | the ASCII characters Speex (three spaces) |
| 8 | 20 | speex_version | the encoder version, as text |
| 28 | 4 | speex_version_id | a version number |
| 32 | 4 | header_size | the size of this header, 80 |
| 36 | 4 | rate | the sample rate in Hz |
| 40 | 4 | mode | 0 narrowband, 1 wideband, 2 ultra-wideband |
| 44 | 4 | mode_bitstream_version | the bit stream version of that mode |
| 48 | 4 | nb_channels | the number of channels |
| 52 | 4 | bitrate | bit rate; −1 when not known |
| 56 | 4 | frame_size | samples in each frame |
| 60 | 4 | vbr | 1 when variable bit rate |
| 64 | 4 | frames_per_packet | the number of frames in each Ogg packet |
| 68 | 4 | extra_headers | further header packets after the comments |
| 72 | 8 | reserved | two more 32-bit values |
Comment packet
The second packet holds the Vorbis comments, with no framing bit.
Audio packets
Each packet holds the header’s frames_per_packet frames, packed bit after bit,
and padded at the end. A frame holds a wideband layer first, when present, then the
narrowband frame. The packet’s frames are 20 ms each at the codec’s frame rate.
Every narrowband frame begins with its mode number in 4 bits, after a 1-bit flag: 0 for narrowband. A wideband-mode frame is a 1 bit and a 3-bit submode for the high band, then the narrowband frame of the low band.
Narrowband modes
| Mode | Bits in a 20 ms frame | Bit rate | Type |
|---|---|---|---|
| 0 | 5 | 250 bit/s | comfort noise (no speech) |
| 1 | 43 | 2.15 kbit/s | vocoder mode |
| 2 | 119 | 5.95 kbit/s | CELP |
| 3 | 160 | 8 kbit/s | CELP |
| 4 | 220 | 11 kbit/s | CELP |
| 5 | 300 | 15 kbit/s | CELP |
| 6 | 364 | 18.2 kbit/s | CELP |
| 7 | 492 | 24.6 kbit/s | CELP |
| 8 | 79 | 3.95 kbit/s | CELP |
| 9–12 | reserved | ||
| 13 | application-defined in-band data | ||
| 14 | Speex in-band requests | ||
| 15 | end of stream |
Wideband adds a high band in submodes 1 to 4 at 1.8, 5.6, 9.6 and 17.6 kbit/s. Submode 0 adds no high band.
In-band signalling
Mode 14 carries a 4-bit request code and a payload whose length depends on the code:
| Code | Payload |
|---|---|
| 0, 1 | 1 bit |
| 2–7 | 4 bits |
| 8, 9 | 8 bits (9 is intensity stereo) |
| 10, 11 | 16 bits |
| 12, 13 | 32 bits |
| 14, 15 | 64 bits |
Mode 13 carries application data with a 4-bit byte count and that many bytes.
Links
- Speex project – the codec’s home page and manual
- RFC 5574 – the RTP payload format for Speex, with the mode table