知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
fix(windows): with OpenRouter's voice, the talk key no longer gets stuck on Speaking to others after the first sentence
wquguruf598b84997a7
diff --git a/site/changelog.json b/site/changelog.jsonindex fa10b05..362c454 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -96,6 +96,14 @@],"title": "引导里听过电脑声音之后,同声传译那一步不再把已装好的 VB-Cable 当成没装,按住说话也不会误报“没有虚拟麦克风”。","text": "以前偶尔会出现:第 4 步显示“安装”、托盘显示“去设置”,其实 VB-Cable 好好的。"+ },+ {+ "kind": "fixed",+ "platforms": [+ "windows"+ ],+ "title": "用 OpenRouter 的声音同传时,说完一句后说话键不再卡在“正在说给对方听…”,之后按下也能接着说。",+ "text": "OpenRouter 送来的声音有时停在半个采样上,知了一直等它播完,还占满一个 CPU 核。"}]},diff --git a/windows/src/Cicada.Core/Ling.cs b/windows/src/Cicada.Core/Ling.csindex bce5f3e..f118872 100644--- a/windows/src/Cicada.Core/Ling.cs+++ b/windows/src/Cicada.Core/Ling.cs@@ -664,16 +664,25 @@ public sealed class LingClient}else{- // Raw PCM: handed on in 0.1 s pieces at 24 kHz, so playback starts early.+ // Raw PCM: handed on in 0.1 s pieces at 24 kHz, so playback starts early. A read can+ // end mid-sample (OpenRouter's does): the odd byte waits for the next read, or every+ // sample after it would be split across two pieces.var buffer = new byte[4800];+ int held = 0;while (true){int n;- try { n = await stream.ReadAsync(buffer, cts.Token); }+ try { n = await stream.ReadAsync(buffer.AsMemory(held), cts.Token); }catch (OperationCanceledException) when (!cancel.IsCancellationRequested) { throw new LingException(LingException.Kind.Timeout); }if (n == 0) break;+ n += held;+ var even = n & ~1;+ held = n - even;+ if (even == 0) continue;if (chunks++ == 0) Log.Debug($"ai {c.Provider.Id}: Speak first audio {(int)(DateTime.UtcNow - started).TotalMilliseconds} ms");- yield return buffer[..n];+ var piece = buffer[..even];+ if (held > 0) buffer[0] = buffer[even];+ yield return piece;}}}diff --git a/windows/src/Cicada/Wasapi.cs b/windows/src/Cicada/Wasapi.csindex b6148f0..66a61eb 100644--- a/windows/src/Cicada/Wasapi.cs+++ b/windows/src/Cicada/Wasapi.cs@@ -314,16 +314,17 @@ sealed class DeviceSpeaker : ISpeechSink{lock (queue) { if (queue.Count > 0) { pending = queue.Dequeue(); offset = 0; } }}+ // Half a sample left over can't be played: without this the loop spun on it forever,+ // End never returned and the talk key stayed on 正在说给对方听….+ if (pending.Length - offset == 1) offset = pending.Length;if (offset < pending.Length && room > 0){int frames = Math.Min(room, (pending.Length - offset) / 2);- if (frames > 0 && render.GetBuffer((uint)frames, out var data) == 0)- {- Marshal.Copy(pending, offset, data, frames * 2);- render.ReleaseBuffer((uint)frames, 0);- offset += frames * 2;- if (!started) { Marshal.ThrowExceptionForHR(client.Start()); started = true; }- }+ if (render.GetBuffer((uint)frames, out var data) != 0) { Thread.Sleep(10); continue; }+ Marshal.Copy(pending, offset, data, frames * 2);+ render.ReleaseBuffer((uint)frames, 0);+ offset += frames * 2;+ if (!started) { Marshal.ThrowExceptionForHR(client.Start()); started = true; }continue;}bool empty; lock (queue) empty = queue.Count == 0;