In a GoldSrc game, the
sentences.txt file sets the sound files used by monsters, doors, buttons, the
speaker
entity, and
scripted_sentence
entities.
The file is located in the sound/ folder of a game or mod. Each line of the file sets a sentence name, and a series of sound files to be emitted by the calling entities. The sound files are referenced by their names, without the .wav suffix.
Syntax
Here's a little snippet from the file:
// HUMAN GRUNTS
HG_GREN0 hgrunt/clik(p120) grenade! clik
Where:
- // marks a comment
HG_GREN0
is the unique sentence identifier. More often than not there are a bunch of them with numbered suffixes. These are treated as a group, and can be targeted in entities by omitting the number suffixes.
hgrunt/
changes the folder of the sound files relative to the sound/ folder for the current and subsequent sounds.
clik
and grenade!
are sound files located in the above folder, again referenced by the filename without the file extension.
(p120)
changes the pitch to 120 per cent.
More on this in the following sections.
Identifiers
Each entry starts with the sentence identifier. It must be unique, and there is a max limit in vanilla GoldSrc of 1536 or 2048 sentences since the Half-Life 25th anniversary update.
In general, the identifiers are constructed as follows:
- prefix by monster type (e.g.
BA_
for barneys, SC_
for scientists)
- type of sentence (e.g.
QUESTION
and ANSWER
)
- numbered suffix for a group of sentences, which an entity picks in order or at random, depending on how it's coded.
The max length of the sentence identifiers is 16 characters.
Sounds
The sound files to play in order, separated by spaces.
By default, to make the iconic announcer voice, the sound files are picked from
vox/ and typed into sentences.txt generally like an English sentence. In order to change the folder, specify the folder name followed by a slash and then the file name. The folder name must be relative to "sound/", so "sound/" must not itself be included. You can only specify the folder once, at the beginning of the sentence.
To further support the English sentence paradigm, commas and periods are translated to "_comma" and "_period" files, containing the appropriate amount of silence. Example usage:
SC_HEAL4 scientist/youwounded, letstrythis
The max length of the sentence line is 511 characters, and the max number of words (sound files to play in each sentence) is 32.
Modifiers
Modifiers apply dynamic processing to the sounds, allowing you to do actions such as changing the pitch or truncating a sound from the file without editing the files themselves. Modifiers are in the form of
(a# b# c#)
, where the "abc" are the modifier codes and the "#" are the modifier amounts in percent.
Modifiers take effect in two modes:
- If it directly comes after a sound, without a space, it is applied only to that sound.
- If it is in whitespace, it is applied from that point to the rest of the sentence, or until the next modifier is encountered.
For example, in the following:
C1A0_10 doop (e95 p103) doctor freeman, (e95) to(e70) anomalous materials test lab immediately(e100)
(e95 p103)
takes effect after "doop" but before "doctor freeman".
(e95)
takes effect after that to the end of the sentence. Since it doesn't modify the pitch, "p103" from previous remains in effect.
to(e70)
overrides the above modifier for the word "to", and applies only to it.
immediately(e100)
, likewise, for the word "immediately".
The following lists the modifiers:
Code |
Description |
range |
to reset |
e |
Changes the ending position. Allows you to truncate the end of the file. |
0-100 |
e100 |
p |
Changes the pitch. It also speeds up the sound by the same amount. |
1-255 |
p0 |
s |
Changes the starting position. Allows you to truncate the beginning of the file. |
0-100 |
s0 |
v |
Changes the volume. |
0-100 |
v100 |
t |
Time compression. It can only speed up and starts from 0 (normal speed). Doesn't affect pitch. See below. |
0-100 |
t0 |
Visualization of time compression. Top: Original sample, Bottom: recording of sample spoken with (t25) applied, chopped and aligned to the original sample
Time compression works by chopping the sound file sample, after applying the start and end crops, into 8 chunks, then cropping N% off of the start of the second to eighth chunks. The first chunk is always preserved, probably due to a quirk in the engine code.
Therefore, time compression should be used only on word files e.g. from vox/ and hgrunt/, and not be used on longer sound files e.g. whole sentence files of the scientists and barneys as that'd cause random parts of their sentence to be dropped.
Note that if a single modifier in a modifier group is invalidated, the entire group is discarded.
Usage
Talking monsters each have their groups of sentences in the file. The group names are hard-coded in each game, but you can edit sentences.txt to change/add sentences in the existing groups.
scripted_sentence
and ambient_generic
To use a sentence from the sentences file, add a
!
followed by the sentence name in the "Sentence name" key in
scripted_sentence
.
See
scripted_sentence for more information.
The
ambient_generic
entity also accepts a sentence name in the place of a WAV file. This allows you to play a sentence without an NPC to speak it.
See
ambient_generic for more information.
speaker
Choose from a preset, or specify a "Sentence Group Name" in the
speaker
entity. Unlike in
scripted_sentence
,
!
is not prefixed when specifying a group, but prefixed when specifying a single sentence.
See
speaker for more information.
Doors and buttons have "locked" and "unlocked" sounds, which lets you select from the predefined sentence groups. You cannot specify a sentence name/group directly.
speak
command
In the console, you can test your sentences by typing
speak "sentence"
where "sentence" is the whole sentence. Modifiers are supported. You can also use the
!SENTENCENAME
syntax to speak a specific sentence of that name.
NOTE: The implementation of this command is game-specific and may not work on mods. For example, it works on Half-Life but not on Sven-Coop or XASH. (in fact implementation of sentences.txt modifiers is incomplete in XASH)
Limitations
The following limitations apply in the base engine and/or SDK:
- Max. 1536 or 2048 sentences since the Half-Life 25th anniversary update (this is the engine limit. The default sentences.txt file has a comment saying the limit is 1023, but it's not true)
- Max. 200 sentence groups
- Max. 15 ASCII characters for sentence name
- Max. 32 words in a sentence
- Max. 511 characters in each sentence line
The vanilla sentence system doesn't play well with the SteamPipe folder structures (i.e. the
_addon
and
_downloads
suffixed folders, among others). It means that you should only ever have sentences.txt in the base game/mod folder.
Alternatives in other games
Counter-Strike: Condition Zero Deleted Scenes implements sequence files (.seq), which allow sentences and sequences to be loaded on a per map basis. It has its own associated entities and syntax but increases the portability of custom sentences in custom maps. These additions were not backported to the Half-Life SDK, however.
Sven Co-op has its own way to load a custom sentences.txt-syntaxed file per map/entity.
Resources
Let this be the definitive guide for sentences.txt, especially for the scant information on the modifiers.