知了 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): installing VB-Cable no longer leaves the computer silent
wqugurua3aa981a4a7c
diff --git a/site/changelog.json b/site/changelog.jsonindex 95431e2..15566a1 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -21,6 +21,14 @@],"title": "会议记录校准时,一个人说的词不再挪到下一个人那句里。","text": "两个人中间几乎没有停顿时,校准偶尔把前一句末尾的“Great”或后一句开头的“Okay”挪到另一个人的那一行。现在一句话说完的地方就是这一行的结尾。"+ },+ {+ "kind": "fixed",+ "platforms": [+ "windows"+ ],+ "title": "装好 VB-Cable 后电脑不会再没声了。",+ "text": "Windows 有时会把新装的 CABLE Input 设成默认播放设备,视频和会议就都听不到了。现在知了装完会自动改回原来的扬声器;之前装过的,启动时会提醒一次,点一下就能恢复,“设置 › 同声传译”里也有“恢复声音”。"}]},diff --git a/windows/src/Cicada.Core/Settings.cs b/windows/src/Cicada.Core/Settings.csindex 735a229..db8e5bb 100644--- a/windows/src/Cicada.Core/Settings.cs+++ b/windows/src/Cicada.Core/Settings.cs@@ -77,6 +77,9 @@ public sealed class AppSettings[JsonPropertyName("updateLastChecked")] public DateTimeOffset? UpdateLastChecked { get; set; }/// The version the update notification was last shown for: one per version.[JsonPropertyName("updateNotified")] public string? UpdateNotified { get; set; }+ /// The startup notification that VB-Cable holds the speaker was shown (CableDefaults.ShouldNotify);+ /// cleared when a real speaker is back.+ [JsonPropertyName("cableSpeakerNotified")] public bool CableSpeakerNotified { get; set; }[JsonIgnore] public string TargetCode => Target == "system" ? Languages.FromSystem(CultureInfo.CurrentUICulture.Name) : Target;/// The AI service in use, its address and models (what LingClient calls with).diff --git a/windows/src/Cicada.Core/Speak.cs b/windows/src/Cicada.Core/Speak.csindex d90e6a8..6ac23e2 100644--- a/windows/src/Cicada.Core/Speak.cs+++ b/windows/src/Cicada.Core/Speak.cs@@ -272,6 +272,26 @@ public static class VirtualCablepublic static bool Verify(byte[] package) => Convert.ToHexString(SHA256.HashData(package)).Equals(PackageSha256, StringComparison.OrdinalIgnoreCase);}+/// Windows can make a freshly installed VB-Cable the default speaker (and mic): then everything the+/// computer plays goes into the cable and the user hears nothing. A user took that for Cicada+/// breaking their sound and nearly uninstalled it. Keys are "<flow>/<role>" (render 0, capture 1;+/// console 0, multimedia 1, communications 2), values the endpoint ids.+public static class CableDefaults+{+ /// The defaults to set back after the install: each one the cable took from a real device.+ public static List<(string Key, string Id)> Restore(IReadOnlyDictionary<string, string> before, IReadOnlyDictionary<string, string> after, Func<string, bool> isCable) =>+ after.Where(a => isCable(a.Value) && before.TryGetValue(a.Key, out var b) && !isCable(b))+ .Select(a => (a.Key, before[a.Key])).OrderBy(r => r.Key, StringComparer.Ordinal).ToList();++ /// A speaker to go back to when nothing was remembered (installed before this, or outside+ /// Cicada): the first that isn't the cable.+ public static string? Speaker(IEnumerable<(string Id, bool Cable)> speakers) => speakers.FirstOrDefault(s => !s.Cable).Id;++ /// The startup notification, once while the cable holds the speaker: someone who routes sound+ /// into it on purpose hears about it once; it comes back only after the speaker was real again.+ public static bool ShouldNotify(bool speakerIsCable, bool notified) => speakerIsCable && !notified;+}+/// Whether anyone spoke during a press of the talk key (PressSpeech in SpeakEngine.swift, same/// numbers): 0.3 s of 30 ms frames over three times the press's own quiet (its quietest tenth),/// between -44 and -36 dBFS. A silent press came back from Ming as "嗯。" and went out as "Hmm.";diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex fa6dfce..8284fb8 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -192,11 +192,31 @@ sealed class Controllerelse{if (Ling.HasKey) _ = Ling.Check();+ NotifyCableSpeaker();if (Arrived == "--updated") Toast(LF("知了已更新到 %@", Version), L("会议记录、设置和 Ling key 都在。"));else if (Arrived is not null) FromInstaller();}}+ /// VB-Cable holds the speaker (installed before Cicada gave it back, or outside Cicada): the user+ /// hears nothing and may blame Cicada. Said once (CableDefaults.ShouldNotify); a click gives a+ /// real speaker back.+ public void NotifyCableSpeaker()+ {+ var onCable = Endpoints.SpeakerIsCable();+ if (CableDefaults.ShouldNotify(onCable, Settings.CableSpeakerNotified))+ {+ Toast(L("听不到电脑声音了?"), L("Windows 把输出改成了 CABLE Input,点此恢复"), () =>+ {+ if (!Endpoints.RestoreSpeaker()) Toast(L("自动恢复失败"), L("请去 Windows 声音设置,把输出设备改回你的耳机或扬声器"), () => Open("ms-settings:sound"));+ });+ Log.Debug("cable: speaker notified");+ }+ if (Settings.CableSpeakerNotified == onCable) return;+ Settings.CableSpeakerNotified = onCable;+ Settings.Save();+ }+/// The installer ran again with this version (or an older one) already here: bring the main window.public void FromInstaller(){@@ -245,7 +265,8 @@ sealed class Controllerif (e.Button == Forms.MouseButtons.Left) Dispatch.BeginInvoke(() => { if (Listen.Listening && Settings.View == "notes") ToggleNotes(); else ShowFlyout(); });else if (e.Button == Forms.MouseButtons.Right) Dispatch.BeginInvoke(ShowMenu);};- tray.BalloonTipClicked += (_, _) => Dispatch.BeginInvoke(() => { balloonClicked?.Invoke(); balloonClicked = null; });+ // Cleared before the run: a click may show the next notification, with its own action.+ tray.BalloonTipClicked += (_, _) => Dispatch.BeginInvoke(() => { var c = balloonClicked; balloonClicked = null; c?.Invoke(); });UpdateTray();}@@ -1379,6 +1400,21 @@ static class DebugServerbreak;}case "speakers": app.Settings.SpeakerVoices = arg == "on"; app.Settings.Save(); app.SettingsChanged(); break;+ // speaker: the defaults and whether the cable holds the speaker; "cable" hands it the speaker+ // (what Windows may do on install), "install" does that and then the installer's give-back,+ // "restore" is 恢复声音, "notify" the startup notification again.+ case "speaker":+ if (arg is "cable" or "install")+ {+ var before = Endpoints.Defaults();+ var to = Endpoints.Cable()!.Id;+ for (var role = 0; role < 3; role++) Endpoints.SetDefault(to, role);+ if (arg == "install") _ = CableInstaller.GiveBackDefaults(before); // about 4 s; ask "speaker" after+ }+ else if (arg == "restore") Endpoints.RestoreSpeaker();+ else if (arg == "notify") { app.Settings.CableSpeakerNotified = false; app.NotifyCableSpeaker(); }+ return new JsonObject { ["onCable"] = Endpoints.SpeakerIsCable(), ["speaker"] = Endpoints.Default(Endpoints.Flow.Render)?.Name, ["notified"] = app.Settings.CableSpeakerNotified,+ ["defaults"] = string.Join(" ", Endpoints.Defaults().OrderBy(d => d.Key).Select(d => $"{d.Key}={(Endpoints.CableIds().Contains(d.Value) ? "cable" : "real")}")) };case "fakemic": app.SetFakeMic(arg == "off" ? null : arg); break;case "record": _ = app.RecordCable(arg); break;// 回放: "open <id> [transcript]", "play <seconds>|toggle|speed", "recordaudio on|off".diff --git a/windows/src/Cicada/Onboarding.cs b/windows/src/Cicada/Onboarding.csindex e96836f..57269df 100644--- a/windows/src/Cicada/Onboarding.cs+++ b/windows/src/Cicada/Onboarding.cs@@ -594,7 +594,7 @@ sealed class Onboarding : Window{Children ={- Numbered(Disc(1, cable), L("装一个虚拟麦克风"), L("VB-Cable,免费,Windows 会问一次是否允许"), cableControl),+ Numbered(Disc(1, cable), L("装一个虚拟麦克风"), L("VB-Cable,免费,Windows 会问一次是否允许"), cableControl, cable ? SpeakerNote() : null),Divider(),Numbered(Disc(2), L("会议软件里,麦克风选 CABLE Output"), L("Teams、Zoom、腾讯会议都在“音频设置”里")),Divider(),@@ -604,6 +604,11 @@ sealed class Onboarding : Windowreturn Page(L("线上开会时要说外语吗?"), LF("按住%@说话,线上的人听到翻译后的声音。不需要可以跳过。", PushToTalk.Label), card);}+ /// After the install: where the computer's sound plays, so nobody thinks Cicada took it.+ FrameworkElement? SpeakerNote() =>+ Endpoints.SpeakerIsCable() ? CableInstaller.SpeakerStrip(this, Render)+ : Endpoints.Default(Endpoints.Flow.Render) is { } d ? Ui.Text(LF("电脑声音照常从 %@ 播放", d.Name), 13, Palette.Secondary) : null;+void SpeakChanged() => Dispatcher.BeginInvoke(() => { if (step == 3 && IsLoaded) page.Content = SpeakStep(); });async Task InstallCable()diff --git a/windows/src/Cicada/SettingsWindow.cs b/windows/src/Cicada/SettingsWindow.csindex d74037c..25ec946 100644--- a/windows/src/Cicada/SettingsWindow.cs+++ b/windows/src/Cicada/SettingsWindow.cs@@ -286,8 +286,14 @@ sealed partial class SettingsWindow : Windownote is null ? Card(null, LF("线上的人听到的声音(%@)", Ui.TargetName(target)), null, voice): Ui.Stack(0, Card(null, LF("线上的人听到的声音(%@)", Ui.TargetName(target)), null, voice), PreviewNoteBox(note.Value)));yield return Label(L("麦克风"));- yield return Group(- Card(null, L("译文送进会议"), cable ? L("在会议软件里把麦克风选成 CABLE Output") : L("需要装免费的 VB-Cable;装的时候 Windows 会请你确认"), cableControl));+ var mic = Card(null, L("译文送进会议"), cable ? L("在会议软件里把麦克风选成 CABLE Output") : L("需要装免费的 VB-Cable;装的时候 Windows 会请你确认"), cableControl);+ if (cable && Endpoints.SpeakerIsCable())+ {+ var strip = CableInstaller.SpeakerStrip(this, Render);+ strip.Margin = new Thickness(0, 4, 0, 12);+ yield return Group(mic, strip);+ }+ else yield return Group(mic);}// 按住说话's 更改: waiting for a key, and why the last one pressed can't be it.diff --git a/windows/src/Cicada/Speaking.cs b/windows/src/Cicada/Speaking.csindex 25874e5..d4dd4cd 100644--- a/windows/src/Cicada/Speaking.cs+++ b/windows/src/Cicada/Speaking.cs@@ -2,6 +2,8 @@ using System.Diagnostics;using System.IO.Compression;using System.Net.Http;using System.Runtime.InteropServices;+using System.Windows;+using System.Windows.Controls;namespace Cicada.App;@@ -139,6 +141,19 @@ sealed class PushToTalk : IDisposable/// pinned SHA-256 before anything runs, then its installer with Windows' admin prompt.static class CableInstaller{+ /// 电脑没声了? in onboarding and settings: shown while the cable holds the speaker, one button+ /// gives a real speaker back.+ public static FrameworkElement SpeakerStrip(Window owner, Action changed)+ {+ var text = new StackPanel { Children = { Ui.Text(Strings.L("电脑没声了?"), 14, Palette.Ink), Ui.Text(Strings.L("Windows 把播放设备改成了 CABLE Input"), 13, Palette.WarnIcon) } };+ var strip = Ui.Spread(text, Ui.Button(Strings.L("恢复声音"), () =>+ {+ if (!Endpoints.RestoreSpeaker()) Dialogs.Tell(owner, Strings.L("自动恢复失败"), Strings.L("请去 Windows 声音设置,把输出设备改回你的耳机或扬声器"));+ changed();+ }, Ui.Kind.Primary, height: 32));+ return new Border { Background = Palette.WarnBg, CornerRadius = new CornerRadius(10), Padding = new Thickness(12, 8, 8, 8), Child = strip };+ }+public enum Result { Installed, DownloadFailed, BadPackage, Declined, Failed }public static async Task<Result> Install(Action<string> progress)@@ -160,6 +175,8 @@ static class CableInstaller}catch (Exception e) { Log.Debug($"cable: extract failed {e.GetType().Name}"); return Result.Failed; }progress(Strings.L("正在安装…"));+ // Windows may hand the new cable the default speaker and mic (CableDefaults): remember them.+ var before = Endpoints.Defaults();// The x64 installer also puts the ARM64 driver on Windows on ARM.var setup = Path.Combine(dir, Environment.Is64BitOperatingSystem ? "VBCABLE_Setup_x64.exe" : "VBCABLE_Setup.exe");try@@ -173,9 +190,22 @@ static class CableInstallercatch (Exception e) { Log.Debug($"cable: setup failed {e.GetType().Name}"); return Result.Failed; }for (int i = 0; i < 40; i++){- if (Endpoints.Cable() is not null) { Log.Debug("cable: endpoint ready"); return Result.Installed; }+ if (Endpoints.Cable() is not null) { Log.Debug("cable: endpoint ready"); await GiveBackDefaults(before); return Result.Installed; }await Task.Delay(500);}return Result.Failed;}++ /// Windows switches the default a moment after the endpoint appears, not always at once: look+ /// for a few seconds.+ internal static async Task GiveBackDefaults(Dictionary<string, string> before)+ {+ for (int i = 0; i < 8; i++)+ {+ var cables = Endpoints.CableIds();+ foreach (var (key, id) in CableDefaults.Restore(before, Endpoints.Defaults(), cables.Contains))+ Log.Debug($"cable: default {key} given back {Endpoints.SetDefault(id, int.Parse(key[2..]))}");+ await Task.Delay(500);+ }+ }}diff --git a/windows/src/Cicada/Strings/en.lproj/Windows.strings b/windows/src/Cicada/Strings/en.lproj/Windows.stringsindex f8ab674..bbc30d1 100644--- a/windows/src/Cicada/Strings/en.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/en.lproj/Windows.strings@@ -350,3 +350,12 @@"开会时也会这样换过去,不会不出声。" = "Meetings fall back the same way, so you're never silent.";"没放出声音。" = "Nothing played.";"再试一次,还不行就换一个声音。" = "Try again, or pick another voice.";+/* VB-Cable took the speaker (CableDefaults). Copy polished and translated with gemini-4-argon, reviewed. */+"电脑声音照常从 %@ 播放" = "PC audio will keep playing through %@";+"电脑没声了?" = "No sound from your PC?";+"Windows 把播放设备改成了 CABLE Input" = "Windows changed the playback device to CABLE Input";+"恢复声音" = "Restore sound";+"听不到电脑声音了?" = "Can't hear your PC?";+"Windows 把输出改成了 CABLE Input,点此恢复" = "Windows switched audio output to CABLE Input. Click to restore.";+"自动恢复失败" = "Couldn't restore audio";+"请去 Windows 声音设置,把输出设备改回你的耳机或扬声器" = "Go to Windows Sound settings and switch the output device back to your headphones or speakers.";diff --git a/windows/src/Cicada/Strings/ja.lproj/Windows.strings b/windows/src/Cicada/Strings/ja.lproj/Windows.stringsindex bf2eea9..78919c1 100644--- a/windows/src/Cicada/Strings/ja.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ja.lproj/Windows.strings@@ -350,3 +350,12 @@"开会时也会这样换过去,不会不出声。" = "会議中も同じように切り替わるので、無音にはなりません。";"没放出声音。" = "再生されませんでした。";"再试一次,还不行就换一个声音。" = "もう一度試すか、別の音声を選んでください。";+/* VB-Cable took the speaker (CableDefaults). Copy polished and translated with gemini-4-argon, reviewed. */+"电脑声音照常从 %@ 播放" = "PCの音声は通常通り %@ から再生されます";+"电脑没声了?" = "PCから音が出ませんか?";+"Windows 把播放设备改成了 CABLE Input" = "Windows により再生デバイスが CABLE Input に変更されました";+"恢复声音" = "音声を戻す";+"听不到电脑声音了?" = "PCの音が聞こえませんか?";+"Windows 把输出改成了 CABLE Input,点此恢复" = "Windows が音声出力を CABLE Input に変更しました。クリックして元に戻します。";+"自动恢复失败" = "自動復元に失敗しました";+"请去 Windows 声音设置,把输出设备改回你的耳机或扬声器" = "Windows の「サウンド設定」を開き、出力デバイスをお使いのヘッドホンやスピーカーに戻してください。";diff --git a/windows/src/Cicada/Strings/ko.lproj/Windows.strings b/windows/src/Cicada/Strings/ko.lproj/Windows.stringsindex 312e9d4..97d0398 100644--- a/windows/src/Cicada/Strings/ko.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ko.lproj/Windows.strings@@ -350,3 +350,12 @@"开会时也会这样换过去,不会不出声。" = "회의 중에도 같은 방식으로 바뀌어 소리가 끊기지 않습니다.";"没放出声音。" = "재생되지 않았습니다.";"再试一次,还不行就换一个声音。" = "다시 시도하거나 다른 음성을 고르세요.";+/* VB-Cable took the speaker (CableDefaults). Copy polished and translated with gemini-4-argon, reviewed. */+"电脑声音照常从 %@ 播放" = "PC 소리는 평소처럼 %@에서 재생됩니다";+"电脑没声了?" = "PC에서 소리가 안 나나요?";+"Windows 把播放设备改成了 CABLE Input" = "Windows에서 재생 장치가 CABLE Input으로 변경됨";+"恢复声音" = "소리 복구";+"听不到电脑声音了?" = "PC 소리가 안 들리나요?";+"Windows 把输出改成了 CABLE Input,点此恢复" = "Windows에서 출력이 CABLE Input으로 변경되었습니다. 클릭하여 복구하세요.";+"自动恢复失败" = "자동 복구 실패";+"请去 Windows 声音设置,把输出设备改回你的耳机或扬声器" = "Windows 소리 설정에서 출력 장치를 사용 중인 헤드폰이나 스피커로 다시 변경해 주세요.";diff --git a/windows/src/Cicada/Wasapi.cs b/windows/src/Cicada/Wasapi.csindex ed482d0..efce81a 100644--- a/windows/src/Cicada/Wasapi.cs+++ b/windows/src/Cicada/Wasapi.cs@@ -46,6 +46,58 @@ static class Endpointspublic static Device? Cable() => All(Flow.Render).FirstOrDefault(d => d.Description == VirtualCable.InputName || d.Name.StartsWith(VirtualCable.InputName));public static Device? CableOutput() => All(Flow.Capture).FirstOrDefault(d => d.Description == VirtualCable.OutputName || d.Name.StartsWith(VirtualCable.OutputName));+ /// Any end of VB-Cable, "CABLE In 16ch" too (the pack installs it beside CABLE Input, and+ /// Windows can make it the default speaker as well).+ public static bool IsCable(Device d) =>+ d.Description is VirtualCable.InputName or VirtualCable.OutputName || d.Name.StartsWith(VirtualCable.InputName) || d.Name.StartsWith(VirtualCable.OutputName)+ || d.Name.Contains("VB-Audio Virtual Cable", StringComparison.OrdinalIgnoreCase);++ /// Every default (CableDefaults' "<flow>/<role>" keys): the playback and recording device for+ /// games and system sounds, for media and for calls.+ public static Dictionary<string, string> Defaults()+ {+ var map = new Dictionary<string, string>();+ try+ {+ var e = (IMMDeviceEnumerator)new MMDeviceEnumerator();+ foreach (var flow in new[] { Flow.Render, Flow.Capture })+ for (var role = 0; role < 3; role++)+ if (e.GetDefaultAudioEndpoint((int)flow, role, out var d) == 0 && d.GetId(out var id) == 0) map[$"{(int)flow}/{role}"] = id;+ }+ catch (Exception ex) { Log.Debug($"endpoints: defaults failed {ex.GetType().Name}"); }+ return map;+ }++ /// Ids of the cable's two ends, for CableDefaults.+ public static HashSet<string> CableIds() => [.. All(Flow.Render).Concat(All(Flow.Capture)).Where(IsCable).Select(d => d.Id)];++ /// What the user hears through is the cable: they hear nothing.+ public static bool SpeakerIsCable() => Default(Flow.Render) is { } d && IsCable(d);++ /// Makes `id` the default for one role, as the Sound control panel does. IPolicyConfig isn't+ /// documented, but it is what Windows' own panel calls and has stayed put since Windows 7.+ public static bool SetDefault(string id, int role)+ {+ try+ {+ var policy = (IPolicyConfig)new PolicyConfigClient();+ var hr = policy.SetDefaultEndpoint(id, role);+ Marshal.ReleaseComObject(policy);+ return hr == 0;+ }+ catch (Exception ex) { Log.Debug($"endpoints: set default failed {ex.GetType().Name}"); return false; }+ }++ /// Back to a real speaker for every role (CableDefaults.Speaker): when nothing from before the+ /// install was remembered.+ public static bool RestoreSpeaker()+ {+ if (CableDefaults.Speaker(All(Flow.Render).Select(d => (d.Id, IsCable(d)))) is not { } id) { Log.Debug("cable: no other speaker"); return false; }+ var ok = Enumerable.Range(0, 3).All(role => SetDefault(id, role));+ Log.Debug($"cable: speaker restored {ok}");+ return ok && !SpeakerIsCable();+ }+/// A microphone, never the cable's own output (that would be the room hearing itself).public static Device? Microphone(){@@ -148,6 +200,26 @@ static class Endpoints[PreserveSig] int GetValue(ref PropertyKey key, out PropVariant value);}+ [ComImport, Guid("870AF99C-171D-4F9E-AF0D-E63DF40C2BC9")] class PolicyConfigClient { }++ /// Only SetDefaultEndpoint is called; the slots before it keep the vtable in order.+ [ComImport, Guid("F8679F50-850A-41CF-9C72-430F290290C8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]+ interface IPolicyConfig+ {+ [PreserveSig] int GetMixFormat(IntPtr a, IntPtr b);+ [PreserveSig] int GetDeviceFormat(IntPtr a, int b, IntPtr c);+ [PreserveSig] int ResetDeviceFormat(IntPtr a);+ [PreserveSig] int SetDeviceFormat(IntPtr a, IntPtr b, IntPtr c);+ [PreserveSig] int GetProcessingPeriod(IntPtr a, int b, IntPtr c, IntPtr d);+ [PreserveSig] int SetProcessingPeriod(IntPtr a, IntPtr b);+ [PreserveSig] int GetShareMode(IntPtr a, IntPtr b);+ [PreserveSig] int SetShareMode(IntPtr a, IntPtr b);+ [PreserveSig] int GetPropertyValue(IntPtr a, IntPtr b, IntPtr c);+ [PreserveSig] int SetPropertyValue(IntPtr a, IntPtr b, IntPtr c);+ [PreserveSig] int SetDefaultEndpoint([MarshalAs(UnmanagedType.LPWStr)] string id, int role);+ [PreserveSig] int SetEndpointVisibility([MarshalAs(UnmanagedType.LPWStr)] string id, int visible);+ }+[StructLayout(LayoutKind.Sequential)] struct PropertyKey { public Guid fmtid; public int pid; }[StructLayout(LayoutKind.Explicit, Size = 24)] struct PropVariant { [FieldOffset(0)] public ushort vt; [FieldOffset(8)] public IntPtr pointer; }[DllImport("ole32.dll")] static extern int PropVariantClear(ref PropVariant value);diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex 11de532..c173fe2 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -1587,6 +1587,22 @@ static class TestsEqual(64, VirtualCable.PackageSha256.Length, "a full SHA-256 is pinned");}+ public static void GivesTheSpeakerBackAfterTheCableInstall()+ {+ static bool cable(string id) => id.StartsWith("cable");+ var before = new Dictionary<string, string> { ["0/0"] = "realtek", ["0/1"] = "realtek", ["0/2"] = "headset", ["1/0"] = "mic", ["1/2"] = "cable-out" };+ var after = new Dictionary<string, string> { ["0/0"] = "cable-in", ["0/1"] = "cable-in", ["0/2"] = "headset", ["1/0"] = "cable-out", ["1/1"] = "cable-out", ["1/2"] = "cable-out" };+ var back = CableDefaults.Restore(before, after, cable);+ Equal("0/0=realtek 0/1=realtek 1/0=mic", string.Join(" ", back.Select(r => $"{r.Key}={r.Id}")),+ "only the defaults the cable took from a real device; one already on the cable, or unknown before, stays");+ Equal(0, CableDefaults.Restore(before, before, cable).Count, "nothing changed, nothing to do");+ Equal("realtek", CableDefaults.Speaker([("cable-in", true), ("realtek", false)]), "the first real speaker");+ Equal(null, CableDefaults.Speaker([("cable-in", true)]), "no real speaker");+ Check(CableDefaults.ShouldNotify(true, false), "told once");+ Check(!CableDefaults.ShouldNotify(true, true), "not again while it stays on the cable");+ Check(!CableDefaults.ShouldNotify(false, false), "a real speaker: nothing to say");+ }+static SpeakEngine Speaker(LingClient ling, NoVoice voice, AppSettings? settings = null) =>new(ling, new Translator(ling, new Fake(_ => new HttpResponseMessage(HttpStatusCode.ServiceUnavailable))), new SessionStore(), settings ?? new AppSettings(), () => "en", () => null, voice);