Skip to main content
The Sound class represents a sound resource containing audio data and metadata.

Properties

SoundType
AudioFileType
Gets the audio file type (AAC, WAV, or MP3).
SampleRate
uint
Gets the samples per second.
Bits
uint
Gets the bit size.
Channels
uint
Gets the number of channels. 1 for mono, 2 for stereo.
AudioFormat
WaveAudioFormat
Gets the bitstream encoding format.
SampleSize
uint
Gets the size of each audio sample in bytes.
SampleCount
uint
Gets the total number of audio samples.
LoopStart
int
Gets the loop start position in samples.
LoopEnd
int
Gets the loop end position in samples.
Duration
float
Gets the duration of the sound in seconds.
Sentence
Sentence?
Gets the sentence data containing phoneme and emphasis information.
Header
byte[]
Gets the WAVE format header data for ADPCM audio.
StreamingDataSize
uint
Gets the size of the streaming audio data in bytes.

Methods

GetSound

Returns a fully playable sound data. In case of WAV files, header is automatically generated as Valve removes it when compiling.
returns
byte[]
Byte array containing sound data.

GetSoundStream

Returns a fully playable sound data as a stream. In case of WAV files, header is automatically generated as Valve removes it when compiling.
returns
MemoryStream
Memory stream containing sound data.

ConstructFromCtrl

Constructs sound data from the control block.
returns
bool
True if successfully constructed from control block.

Enumerations

AudioFileType

Specifies the audio file container type.
  • AAC - AAC container
  • WAV - WAVE container
  • MP3 - MP3 container

AudioFormatV4

Specifies the audio encoding format for version 4 sound files.
  • PCM16 - 16-bit PCM
  • PCM8 - 8-bit PCM
  • MP3 - MP3 encoding
  • ADPCM - ADPCM encoding

WaveAudioFormat

Specifies the WAVE audio encoding format.
  • Unknown - Unknown format
  • PCM - PCM format
  • ADPCM - ADPCM format

Structures

Sentence

Represents a sentence with phoneme and emphasis data for voice playback.
RunTimePhonemes
PhonemeTag[]
Gets the phoneme tags for lip-sync.

PhonemeTag

Represents a phoneme timing tag for lip-sync animation.
StartTime
float
Gets the start time of the phoneme.
EndTime
float
Gets the end time of the phoneme.
PhonemeCode
ushort
Gets the phoneme identifier code.

Usage Example

var resource = new Resource();
var sound = resource.DataBlock as Sound;

if (sound != null)
{
    Console.WriteLine($"Sound Type: {sound.SoundType}");
    Console.WriteLine($"Sample Rate: {sound.SampleRate} Hz");
    Console.WriteLine($"Channels: {sound.Channels}");
    Console.WriteLine($"Duration: {sound.Duration} seconds");
    Console.WriteLine($"Format: {sound.AudioFormat}");
    
    // Get the playable audio data
    var audioData = sound.GetSound();
    Console.WriteLine($"Audio data size: {audioData.Length} bytes");
    
    // Or get as a stream
    using var audioStream = sound.GetSoundStream();
    File.WriteAllBytes("output.wav", audioStream.ToArray());
    
    // Check for phoneme data (for lip-sync)
    if (sound.Sentence != null)
    {
        Console.WriteLine($"Phonemes: {sound.Sentence.RunTimePhonemes.Length}");
        foreach (var phoneme in sound.Sentence.RunTimePhonemes)
        {
            Console.WriteLine($"  {phoneme.StartTime:F2}s - {phoneme.EndTime:F2}s: {phoneme.PhonemeCode}");
        }
    }
    
    // Check loop points
    if (sound.LoopStart >= 0 && sound.LoopEnd > sound.LoopStart)
    {
        Console.WriteLine($"Loop: {sound.LoopStart} to {sound.LoopEnd}");
    }
}

Build docs developers (and LLMs) love