Voice for other resources
Your resource can use voice (a call, an intercom, a dispatch channel, a bugged room) without knowing which voice system runs. Never call one by name: Whip.voice, in @whip_core/lib/satellite.lua, calls whichever is running.
A line is a set of players who hear each other wherever they are, through a sound you choose: with their talk key (a 'voice' line) or the radio key ('radio'). The people around them still hear them. A line is yours, and closes when your resource stops. Everything here is server side, except asking which voice system runs. Recordings played on a line or from an NPC are in whip_voice/docs/LINES.md.
Lines
Whip.voice calls one of the running voice system's exports (below) and returns what it returns, or false, 'no voice system is running'. Whip.voiceSystem() returns which voice system runs (GetVoiceSystem's result), or false.
false, reasonlocal lineId, why = Whip.voice('OpenLine', { members = { visitor, guard } }) -- an intercom
if not lineId then return false, why end
Opens a line: Whip.voice('OpenLine', spec). Members are players with a character loaded; one not in voice yet is linked once they are.
| Field | Type | Description |
|---|---|---|
| members | number[] | Server ids, at most 32. More later with AddLineMember |
| track | string? | 'voice' (default: the talk key) or 'radio' (the radio key) |
| recipe | table|string? | How it sounds at the far end: a list of sound blocks, or a name from RegisterSound. None: the plain voice |
| speakerRange | number? | 1-30 m (default 8): how far a member's device on speaker carries |
| pickup | boolean? | On speaker, the people near the device are heard on the line too, where the voice system has the pickup feature (whip_voice does) |
| quality | table? | { clear = metres, range = metres }: worse with distance, gone past range |
| sameWorld | boolean? | Only members in the same routing bucket hear each other |
| minMembers | number? | Fewer members than this (default 2) and the line closes by itself |
| onEnd | function? | (lineId, why): the line closed by itself ('empty'). Not called when you close it |
| onLeave | function? | (lineId, src, why): a member went ('left', 'logout', 'removed') |
false, reason-- A call between two players, sounding like a phone. With minMembers 2 it closes
-- by itself when either leaves or logs out.
local lineId, why = Whip.voice('OpenLine', {
members = { caller, callee }, pickup = true, minMembers = 2,
recipe = { { 'band', low = 300, high = 3400 }, { 'compress', threshold = -24, ratio = 4 } },
onEnd = function(id, reason) print(('call %s over: %s'):format(id, reason)) end,
})
All through Whip.voice, and only on your own lines.
| Call | Does |
|---|---|
CloseLine(lineId) | Everyone on it lets go at once. A line already closed returns true |
AddLineMember(lineId, src) · RemoveLineMember(lineId, src) | Puts a player on it, or takes one off |
SetLineSpeaker(lineId, src, on) | That member's device plays the line out loud to the people near it |
SetLineMuted(lineId, src, on) | The line stops hearing that member. The people near them still do |
SetLineRecipe(lineId, recipe) | A new sound for the line |
GetLine(lineId) | { id, track, members = { [src] = { speaker, muted } }, pickup, sameWorld, speakerRange, minMembers } |
RegisterSound(name, recipe) | Keeps a recipe under a name (letters, digits, -, _) for recipe = name. Returns its full name, '<your_resource>:<name>' |
IsVoiceReady(src) | Whether that player is connected to voice |
true (GetLine: the table; RegisterSound: the name), or false, reasonWhip.voice('SetLineSpeaker', lineId, callee, true) -- the callee's phone on speaker
Whip.voice('SetLineMuted', lineId, caller, true) -- the far side stops hearing the caller
Whip.voice('CloseLine', lineId) -- hang up
Sound recipes#
A recipe is a list of blocks, in order, each with its settings: { { 'band', low = 300, high = 3400 }, { 'drive', k = 1.5 } }. It's data, never code, checked before it plays: a setting left out takes its default, a number out of range is brought into it, and an unknown block is refused. At most 24 blocks, 4 of them ones that make sound of their own (noise, breakup, radio, hum, chorus, vibrato, tremolo, ringmod, reverb). whip_voice plays every block.
| Block | Settings (default) | Does |
|---|---|---|
gain | db (0) | Louder or quieter |
lowpass · highpass | hz (3000 · 300), q (0.7) | Cuts the highs above, or the lows below, hz |
bandpass · notch | hz (1200 · 1000), q (0.7) | Only a band around hz, or that band taken out |
band | low (300), high (3400), q | Keeps low to high: a telephone |
peak · lowshelf · highshelf | hz, db (0), q | Boosts or cuts a band, the lows, or the highs |
drive | k (2.5), oversample | Soft clipping: grit, harder the bigger k |
crush | steps (32) | A digital edge |
compress | threshold (-24), ratio (4), knee, attack, release | Loud and quiet squeezed together, like a phone line |
noise | kind (white, pink, brown), level (0.02), hz, q | A hiss under the voice, only while they talk |
hum | hz (50), level (0.02) | A mains hum under the voice, only while they talk |
breakup | static (0.06) | Drops out more the weaker the line (its quality), with static in the gaps |
beeps | up, down, down2 (Hz), level | A beep as they start and stop talking |
pan | to (-1 left to 1 right) | Towards one ear |
echo · reverb | time, feedback, mix · size, mix | Repeats, or a room around the device |
chorus · vibrato · tremolo | rate, depth (mix) | A wavering copy, a wavering pitch, a pulsing loudness |
ringmod | hz (50), mix (1) | A robot |
radio | static (0.06), distortion (1) | whip_voice's walkie-talkie, breaking up with distance |
Voice systems
Which voice system runs, or false when none does. Offer only what its features say it can do. On the client, the local event whip_core:voice:systemChanged ({ resource, label, features }, all nil when none runs) says when it changes.
| Feature | whip_voice | Means |
|---|---|---|
lines | true | The line calls above work |
speaker | true | SetLineSpeaker plays a line out loud near a device |
pickup | true | On speaker, the people near the device are heard on the line |
quality | true | A line's quality breaks up with distance |
sounds | 'full' | 'full': every sound block played. 'basic': a phone or radio filter at most |
{ resource, label, features }, or falselocal v = Whip.voiceSystem()
if v and not v.features.pickup then
-- on speaker, only the people near hear the other side: say so in your UI
end
For a voice resource of your own: makes it the voice system. One at a time: refused, naming the other, while another runs; let go when your resource stops. A voice system handles the line calls above, with the same arguments, registers the radio and megaphone items, turns whip_core:voice:rangeChanged (the Z key) into metres, and lights the HUD with SetVoiceTalking(talking, mode?).
true, or false, reasonWhip.register(function()
local ok, why = exports.whip_core:RegisterVoiceSystem({
label = 'my_voice',
features = { lines = true, speaker = true, pickup = false, quality = false, sounds = 'basic' },
})
if not ok then print('voice stays off: ' .. why) return end
-- ... the rest of your registrations
end)