2 releases

0.1.1 May 25, 2025
0.1.0 May 5, 2025

#1553 in Audio

Download history

92 downloads per month

EUPL-1.2

14KB
272 lines

steam-audio-codec

Parser for steam's voice packets.

The "steam" audio codec is used by various voice chat application by steam and Source engine games.

The codec is a fairly thin wrapper around opus packets, so most of the heavy lifting is done by libopus

Usage

Voice data can be decoded with the following steps:

  • Create a SteamVoiceDecoder
  • For every voice packet create a SteamVoiceData from the raw binary data, this will validate that the packet is valid and extract the steam id of the account sending the voice from the header.
  • Pass the SteamVoiceData into SteamVoiceDecoder::decode which will write 16-bit PCM samples to the provided output buffer.
  • Play the PCM samples or encode them into a different format.

See the demo_voice example for a full example in the context of extracting voice chat from a TF2 demo.

Building

Note: this section only applies when using the, enabled by default, "opus" feature.

As this crate uses libopus to do the actual audio decoding you'll need either

  • pkg-config and libopus (including development headers)

or

  • cmake, make, and a C compiler to build libopus from scratch.

See the audiopus_sys documentation for more information.

Bring your own opus decoder

If you need more control over how the opus data is handled, you can disable the builtin opus decoder by removing the (on by default) opus cargo feature.

When this feature is disabled, the SteamVoiceDecoder struct is not available. You can instead access the sample rate, raw opus data and silence information in the voice data from SteamVoiceData::packets.

The opus data should be decoded as mono sound with the sample rate encoded in the packets.

Credits

Dependencies

~3MB
~52K SLoC