mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
Add whisper (targeted voice to channels/clients)
Connector: a new "whisper <channelIds>;<clientIds>" stdin command sets persistent whisper targets; outgoing audio then goes out as AudioData::C2SWhisper instead of the normal C2S broadcast until "unwhisper" clears it. Gateway relays a setWhisperTargets message the same way. Frontend: a toolbar toggle lists channels as checkboxes, and the client context menu gets an "add/remove as whisper target" entry; selecting any target switches all subsequent outgoing voice to whisper mode. Verified against the real test server: setting a channel target and sending a frame produced no connector error, and clearing targets resumed normal voice cleanly.
This commit is contained in:
1 parent
7217bc146a
commit
5858631e6d
5 files changed
+184
-7
No files matched your search
+33
-5
@@ -445,6 +445,11 @@ async fn run(args: Args) -> Result<()> {
|
||||
// `send_with_result()` for text messages gets us a `MessageResult` event we
|
||||
// can surface as a visible error instead of the message just vanishing.
|
||||
let mut pending_messages: HashMap<MessageHandle, String> = HashMap::new();
|
||||
// When non-empty, outgoing voice is whispered to just these channels/clients
|
||||
// instead of being sent to the current channel - set via the "whisper "
|
||||
// stdin command, cleared via "unwhisper".
|
||||
let mut whisper_channels: Vec<u64> = Vec::new();
|
||||
let mut whisper_clients: Vec<u16> = Vec::new();
|
||||
|
||||
enum LoopOutcome {
|
||||
StdinLine(std::io::Result<Option<String>>),
|
||||
@@ -582,6 +587,17 @@ async fn run(args: Args) -> Result<()> {
|
||||
if let Err(e) = part.send(&mut con) {
|
||||
emit(&Event::Error { message: e.to_string() });
|
||||
}
|
||||
} else if let Some(rest) = l.strip_prefix("whisper ") {
|
||||
// Format: "whisper <channelId,channelId,...>;<clientId,clientId,...>"
|
||||
// (either side may be empty, e.g. "whisper 5;" or "whisper ;12,13").
|
||||
let mut parts = rest.splitn(2, ';');
|
||||
let channels_part = parts.next().unwrap_or("");
|
||||
let clients_part = parts.next().unwrap_or("");
|
||||
whisper_channels = channels_part.split(',').filter_map(|s| s.trim().parse().ok()).collect();
|
||||
whisper_clients = clients_part.split(',').filter_map(|s| s.trim().parse().ok()).collect();
|
||||
} else if l == "unwhisper" {
|
||||
whisper_channels.clear();
|
||||
whisper_clients.clear();
|
||||
} else if let Some(b64) = l.strip_prefix("audio ") {
|
||||
match base64::engine::general_purpose::STANDARD.decode(b64.trim()) {
|
||||
Ok(bytes) => {
|
||||
@@ -593,11 +609,23 @@ async fn run(args: Args) -> Result<()> {
|
||||
let mut opus_output = [0u8; 1275];
|
||||
match opus_encoder.encode_float(&samples, &mut opus_output) {
|
||||
Ok(len) => {
|
||||
let packet = OutAudio::new(&AudioData::C2S {
|
||||
id: 0,
|
||||
codec: CodecType::OpusVoice,
|
||||
data: &opus_output[..len],
|
||||
});
|
||||
let has_whisper_targets =
|
||||
!whisper_channels.is_empty() || !whisper_clients.is_empty();
|
||||
let packet = if has_whisper_targets {
|
||||
OutAudio::new(&AudioData::C2SWhisper {
|
||||
id: 0,
|
||||
codec: CodecType::OpusVoice,
|
||||
channels: whisper_channels.clone(),
|
||||
clients: whisper_clients.clone(),
|
||||
data: &opus_output[..len],
|
||||
})
|
||||
} else {
|
||||
OutAudio::new(&AudioData::C2S {
|
||||
id: 0,
|
||||
codec: CodecType::OpusVoice,
|
||||
data: &opus_output[..len],
|
||||
})
|
||||
};
|
||||
if let Err(e) = con.send_audio(packet) {
|
||||
emit(&Event::Error { message: e.to_string() });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user