Skip to main content

Module voice

Module voice 

Source
Expand description

Voice Channels: hear what members say and speak into the call. A bot may be in as many calls at once as it likes, each its own VoiceCall.

Audio is 48 kHz PCM (i16), mono unless a name says stereo. What you hear arrives one 20 ms mono frame per speaker at a time; what you say, mono or stereo, is queued and sent in real time, so a long clip plays at its own pace.

let listener = bot.clone();
tokio::spawn(async move { listener.run(|_, _| async {}).await }); // how the call finds its members
let call = bot.channel(channel_id).join_voice().await?;
call.say(&vector_sdk::voice::tone(440.0, 1000));      // a second of A4
while let Some(speech) = call.listen().await {
    println!("{:?} said {} samples", speech.npub, speech.pcm.len());
}

Structs§

InCall
A member in a voice Channel’s call, as every client lists them.
Speech
One 20 ms frame someone said.
Transcriber
Speech to text with Whisper. Load a ggml model once, then transcribe what Utterances gathers.
Utterance
What one speaker said from when they began until they paused.
Utterances
Turns the frames a call hears into Utterances: each speaker’s words, cut at their pauses. Feed it every Speech from VoiceCall::listen.
VoiceCall
One voice Channel’s call this bot is in. leave when done; dropping it leaves the call running.
VoicePeer
VoiceState

Constants§

DEFAULT_KBPS
The Opus bitrate a call starts at, mono or stereo, in kbit/s. A mesh uploads it once per peer.
FRAME
Samples in one 20 ms frame, per channel: stereo has twice as many, interleaved.
MAX_KBPS
The highest bitrate a call accepts, in kbit/s: about 800 bytes a frame, under [MAX_PACKET] with room for a burst.
MIN_KBPS
The lowest bitrate a call accepts, in kbit/s.
SAMPLE_RATE
Samples per second of everything heard and said.

Functions§

decode_stereo_with_ffmpeg
decode_with_ffmpeg as 48 kHz stereo, interleaved, for VoiceCall::say_stereo. A mono file comes out the same on both sides.
decode_with_ffmpeg
Read any audio file ffmpeg can, as 48 kHz mono PCM. Needs ffmpeg on the PATH. Only local files: a URL would reach the network outside the bot’s transport.
level
How loud pcm is, 0 to 1.
tone
A sine tone, for tests and chimes: hz for ms, at a moderate level.