srctools.sndscript
Enumerations
Several options have a number of predefined names.
- class srctools.sndscript.Pitch
-
The constants permitted for sound pitches.
- PITCH_NORM = 100.0
- PITCH_LOW = 95.0
- PITCH_HIGH = 120.0
- class srctools.sndscript.Channel
Bases:
EnumDifferent categories of sounds.
- DEFAULT = 'CHAN_AUTO'
- GUNFIRE = 'CHAN_WEAPON'
- VOICE = 'CHAN_VOICE'
- TF2_ANNOUNCER = 'CHAN_VOICE2'
- ITEMS = 'CHAN_ITEM'
- BODY = 'CHAN_BODY'
- STREAMING = 'CHAN_STREAM'
- CON_CMD = 'CHAN_REPLACE'
- BACKGROUND = 'CHAN_STATIC'
- PLAYER_VOICE = 'CHAN_VOICE_BASE'
- class srctools.sndscript.Level
Bases:
EnumSoundlevel constants - attenuation.
- SNDLVL_NONE = 0
- SNDLVL_IDLE = 60
- SNDLVL_STATIC = 66
- SNDLVL_NORM = 75
- SNDLVL_TALKING = 80
- SNDLVL_GUNFIRE = 140
- classmethod parse(text: str) int | Level
Parse a soundlevel string, which might be a
SNDLVLname or a number.
- classmethod parse_interval_kv(
- kv: Keyvalues,
Parse an interval of attenuations from the
soundlevelandattenuationkeys of a keyvalues block.Unlike others, this is rounded to an integer. Valve’s code only supports the
SNDLVLnames for a single value, but we allow it for an interval.
- class srctools.sndscript.Volume
Bases:
EnumSpecial value, substitutes default volume (usually 1).
- VOL_NORM = 'VOL_NORM'
- srctools.sndscript.VOL_NORM
This is available globally for convenience.
Sound
- class srctools.sndscript.Sound(
- name: str,
- sounds: list[str],
- volume: tuple[float | Volume, float | Volume] | float | Volume = (srctools.sndscript.VOL_NORM, srctools.sndscript.VOL_NORM),
- channel: int | Channel = Channel.DEFAULT,
- level: tuple[int | Level, int | Level] | int | Level = (Level.SNDLVL_NORM, Level.SNDLVL_NORM),
- pitch: tuple[float | Pitch, float | Pitch] | float | Pitch = (Pitch.PITCH_NORM, Pitch.PITCH_NORM),
- stack_start: Keyvalues | None = None,
- stack_update: Keyvalues | None = None,
- stack_stop: Keyvalues | None = None,
- force_v2: bool = False,
Represents a single soundscript.
Sound Characters
- srctools.sndscript.SND_CHARS
String with some operator characters. Deprecated, use
SoundCharsinstead.
- class srctools.sndscript.SoundChars
Bases:
FlagFlags to represent sound characters which can be added to the start of sound filenames.
Despite comments in the SDK, more than 2 are permitted simultaneously. To re-assemble into a set of characters, call
str.- none = 0x0
A filename with no characters included.
- stream = 0x1
- user_vox = 0x2
Marks player voice chat data, shouldn’t ever be used.
- sentence = 0x4
Dialog from the NPC sentence system.
- dry_mix = 0x8
DSP FX is bypassed for this sound.
- doppler = 0x10
Doppler encoded stereo wav: left wav (incoming) and right wav (outgoing).
- directional = 0x20
Stereo wav has direction cone: mix left wav (front facing) with right wav (rear facing) based on sound facing direction
- dist_variant = 0x40
Distance variant encoded stereo wav (left is close, right is far)
- omni = 0x80
Non-directional - sound appears to play from everywhere, but still has distance volume falloff.
- spatial_stereo = 0x100
Spatialised stereo wav
- dir_stereo = 0x200
Directional stereo wav (like doppler)
- fast_pitch = 0x400
Forces low quality, non-interpolated pitch shift
- subtitled = 0x800
Indicates subtitles were forced on.
- hrtf_force = 0x1000
CSGO+ only. Enables HRTF for all players including the owner.
- hrtf = 0x2000
CSGO+ only. Enables HRTF for non-owners.
- hrtf_blend = 0x4000
CSGO+ only. Enables HRTF for non-owner players, fading to stereo instead if close.
- radio = 0x8000
CSGO+ only. Used for ‘radio’ sounds tha are played without spatialisation.
- music = 0x10000
CSGO+ only. Used for main menu music.
- classmethod from_fname(filename: str) tuple[SoundChars, str]
Parse sound characters out of a filename, then return both.
Utilities
- srctools.sndscript.parse_split_float( ) tuple[float | EnumT, float | EnumT]
Parse pairs of float/enum values from keyvalues.
A single number can be provided, producing the same value for low and high.
- Parameters:
kv – The keyvalues block for the sound, which
keyis then accessed from.key – The name of the keyvalue to look up inside
kv.enum – This is either an Enum with values to match text constants, or a converter function returning enums or raising ValueError, KeyError or IndexError.
default – If either value or the whole string is unparsable, this default is used.
- srctools.sndscript.split_float( ) tuple[float | EnumT, float | EnumT]
Handle values which can be a low, high pair of numbers or enum constants.
A single number can be provided, producing the same value for low and high.
- Parameters:
value – The value to read.
enum – This is either an Enum with values to match text constants, or a converter function returning enums or raising ValueError, KeyError or IndexError.
default – If either value or the whole string is unparsable, this default is used.
- srctools.sndscript.join_float(val: tuple[float | Enum, float | Enum]) str
Reverse split_float(). The two parameters should be stringifiable into floats/constants.
- srctools.sndscript.wav_is_looped(file: FileRSeek[bytes]) bool
Check if the provided wave file contains loop cue points.
This code is partially copied from wave.Wave_read.initfp().
- srctools.sndscript.atten_to_level(attenuation: float) int
Convert an old attenuation value to a soundlevel.
See ATTN_TO_SNDLVL in public/soundflags.h#L105 # TODO: Link that ^^