# Speex

Canonical URL: https://encode.wiki/codecs/audio/speex/
Content version: ca42e61ede0a24f789d7287a0001244ad22f4abf
Status: current
License: CC BY-SA 4.0
Checksum (SHA-256): b6bc199bad22994e1de430a91b40b7e4a8fe128bd80be4c1ef2408d3b3152bb2

Speex is a lossy speech codec from Xiph, designed for VoIP and other low-bitrate voice. Xiph's own site says it has been obsoleted by [Opus](/codecs/audio/opus/), which is better in every respect, and the last release (1.2.1) dates from 2022. Don't use Speex for new work. The only reasons to touch it are playing or converting old `.spx` files and talking to legacy VoIP equipment.

Speex works at three sampling rates: narrowband (8 kHz), wideband (16 kHz) and ultra-wideband (32 kHz). It handles speech, not music, and its quality is poor outside that. SpeexDSP, the companion library with resampling, echo cancellation and noise suppression, is separate and still used.

## Encoding and decoding

With the reference tools:

```sh
speexenc --wideband --quality 8 input.wav output.spx
speexdec output.spx output.wav
```

`--narrowband`, `--wideband` and `--ultra-wideband` say which rate the input is (8, 16 or 32 kHz); resample first, since speexenc warns about other rates. `--quality` goes 0–10.

With FFmpeg (needs `libspeex`):

```sh
ffmpeg -i speech.wav -ar 16000 -c:a libspeex -b:a 24k speech.spx
```

FFmpeg's wrapper also exposes `-vad` and `-dtx` (voice activity detection and discontinuous transmission), `-abr 1` (average bitrate), `-frames_per_packet` (1–8) and `-compression_level` (0–10, default 3). It accepts mono or stereo at 8, 16 or 32 kHz.

## Migrating to Opus

Re-encoding Speex to Opus decodes and recompresses lossy audio, so keep the originals and expect some extra loss. Opus handles speech well at 24–32 kbit/s mono. `.spx` files use the Ogg container. Browsers do not play them natively.
