Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

feat(windows): a Turn on mic button in the tray panel, Live notes, the subtitle bar and the tray menu replaces Listen to, and people at the table are heard over music and with headphones on

wqugurua5212cc96e54
diff --git a/windows/src/Cicada.Core/Hybrid.cs b/windows/src/Cicada.Core/Hybrid.cs
index 2c01e49..d9c9dc1 100644
--- a/windows/src/Cicada.Core/Hybrid.cs
+++ b/windows/src/Cicada.Core/Hybrid.cs
@@ -3,23 +3,94 @@ namespace Cicada;
// 电脑和会议室: the room side's echo handling, and how its lines are shown (RoomMic.swift,
// EchoMatch.swift, RecordList.swift).
-/// 电脑和会议室 without echo cancellation (Windows has none we can use): while the computer plays
-/// speech, the room mic hears it again from the speakers. The computer's side `Hold`s the gate on
-/// every loud buffer; the room mic hears silence until `Hang` after the last one. Room speech over a
-/// remote speaker is lost this way; EchoMatch catches what still gets through.
+/// 打开麦克风 while the computer plays a meeting: the room mic hears the remote voices again from
+/// the speakers (EchoGate in RoomMic.swift, same rules). The room mic hears silence while the
+/// computer plays speech, until `Hang` after it, but only when that is needed and only for speech:
+///
+/// - Echo is measured: the room mic's loud end while the computer is loud over its floor while the
+/// computer is quiet. Headphones or a meeting mic leave it where it was, and then nothing is
+/// silenced, so people at the table are heard over a remote speaker too. Until there is enough
+/// to tell (and whenever it is unclear) the speakers are taken to echo.
+/// - Music isn't speech: a loud stretch the computer's side has recognized no words in for `Music`
+/// seconds stops closing the gate. Words close it again. Longer than the Mac's 4 s: here words
+/// only come back after a whole segment has gone to the service.
public sealed class EchoGate(Func<double>? clock = null)
{
public const double Hang = 0.4;
+ /// Seconds of loud audio without words before it counts as music.
+ public const double Music = 20;
+ /// A pause this long ends a loud stretch.
+ public const double StretchGap = 1.5;
+ /// Computer audio this recent makes a room block "during"; this long ago, "the computer is quiet".
+ public const double During = 0.15, QuietAfter = 1.0;
+ /// The ratio at or over which there is echo, and under which there is none.
+ public const double EchoRatio = 3, ClearRatio = 2;
+ /// Seconds of each that a decision needs, and how much is kept.
+ public const double Enough = 3, Window = 20;
+
/// Seconds; a monotonic clock shared with EchoMatch's times.
public readonly Func<double> Clock = clock ?? (() => Environment.TickCount64 / 1000.0);
readonly object gate = new();
- double until = double.NegativeInfinity;
+ double until = double.NegativeInfinity, lastLoud = double.NegativeInfinity, stretchStart = double.NegativeInfinity, lastWords = double.NegativeInfinity;
+ readonly List<(double t, double rms, double s)> during = [], quiet = [];
+ bool echo = true;
+ /// Debug (`roomEchoSim`): pretend the measurement says this.
+ public bool? Forced { get; set; }
/// When the computer last played something loud.
- public double LastLoud { get { lock (gate) return until - Hang; } }
-
- public void Hold() { var now = Clock(); lock (gate) until = Math.Max(until, now + Hang); }
+ public double LastLoud { get { lock (gate) return lastLoud; } }
+ /// Whether the speakers reach the room mic, as last measured.
+ public bool Echo { get { lock (gate) return Forced ?? echo; } }
+ public bool PlayingMusic { get { var now = Clock(); lock (gate) return MusicLocked(now); } }
public bool Closed { get { var now = Clock(); lock (gate) return now < until; } }
+
+ bool MusicLocked(double now) => now - lastLoud <= StretchGap && now - stretchStart >= Music && lastWords < now - Music;
+
+ /// A loud buffer of the computer's audio.
+ public void Hold()
+ {
+ var now = Clock();
+ lock (gate)
+ {
+ if (now - lastLoud > StretchGap) stretchStart = now;
+ lastLoud = now;
+ if (MusicLocked(now) || !(Forced ?? echo)) return;
+ until = Math.Max(until, now + Hang);
+ }
+ }
+
+ /// The computer's side recognized words.
+ public void HeardWords() { var now = Clock(); lock (gate) lastWords = now; }
+
+ /// A buffer of what the room mic heard, before any silencing.
+ public void RoomLevel(double rms, double seconds)
+ {
+ var now = Clock();
+ lock (gate)
+ {
+ var since = now - lastLoud;
+ if (since <= During) during.Add((now, rms, seconds)); else if (since >= QuietAfter) quiet.Add((now, rms, seconds)); else return;
+ during.RemoveAll(b => b.t < now - Window);
+ quiet.RemoveAll(b => b.t < now - Window * 3);
+ if (Ratio(during.Select(b => (b.rms, b.s)), quiet.Select(b => (b.rms, b.s))) is not { } r) return;
+ var was = echo;
+ if (r >= EchoRatio) echo = true; else if (r < ClearRatio) echo = false;
+ if (was == echo) return;
+ Log.Debug($"room echo: {(echo ? "speakers reach the mic" : "none")} (x{r:F1})");
+ if (!echo) until = double.NegativeInfinity;
+ }
+ }
+
+ /// The room mic's loud end (a fifth of it louder) while the computer is loud over its floor (the
+ /// quietest fifth) while it is quiet, or null without `Enough` of both. People at the table
+ /// talking over the computer raise it too: that errs on the side of echo.
+ public static double? Ratio(IEnumerable<(double rms, double s)> during, IEnumerable<(double rms, double s)> quiet)
+ {
+ var d = during.ToList(); var q = quiet.ToList();
+ if (d.Sum(b => b.s) < Enough || q.Sum(b => b.s) < Enough) return null;
+ var ds = d.Select(b => b.rms).Order().ToList(); var qs = q.Select(b => b.rms).Order().ToList();
+ return ds[ds.Count * 4 / 5] / Math.Max(qs[qs.Count / 5], 0.0002);
+ }
}
/// 电脑和会议室's last line of defence against hearing a remote sentence twice: once from the
@@ -96,13 +167,6 @@ public sealed class EchoFilter(EchoGate gate)
public bool Quiet(EchoMatch.Heard room) => Gate.LastLoud < room.Start - EchoMatch.Window;
}
-/// 线上也有人?: listening to the room alone while a meeting app is in a call, so people online are
-/// likely speaking through it. Once a meeting.
-public static class RoomPrompt
-{
- public static bool AsksOnline(bool roomOnly, bool answered, bool inCall) => roomOnly && !answered && inCall;
-}
-
/// A meeting that heard both: each of the other side's lines says where (RecordList.swift).
public static class Places
{
diff --git a/windows/src/Cicada.Core/ListenEngine.cs b/windows/src/Cicada.Core/ListenEngine.cs
index 1e4ece6..24404ef 100644
--- a/windows/src/Cicada.Core/ListenEngine.cs
+++ b/windows/src/Cicada.Core/ListenEngine.cs
@@ -312,6 +312,8 @@ public sealed class ListenEngine
foreach (var (seg, heard) in ready)
{
if (heard is null) continue;
+ // Words in the computer's audio: speech, which the room mic is silenced for (EchoGate).
+ if (!RoomSide && Echo is { } words && !string.IsNullOrWhiteSpace(heard.Original)) words.Gate.HeardWords();
if (RoomSide && held is { } h && Echo is { } echo) h.Writer.TryWrite((seg, heard, EmittedAt(seg), echo.Gate.Clock()));
else Record(seg, heard);
}
diff --git a/windows/src/Cicada.Core/Room.cs b/windows/src/Cicada.Core/Room.cs
index fe99126..72e2647 100644
--- a/windows/src/Cicada.Core/Room.cs
+++ b/windows/src/Cicada.Core/Room.cs
@@ -70,6 +70,8 @@ public sealed class GatedSource : IAudioSource
{
readonly IAudioSource inner;
public Func<bool>? Silenced { get; set; }
+ /// Each buffer's level (0–1) and length in seconds, before silencing.
+ public Action<double, double>? Heard { get; set; }
public volatile bool Muted;
public event Action<short[]>? Samples;
public event Action<string?>? Ended;
@@ -79,7 +81,17 @@ public sealed class GatedSource : IAudioSource
public GatedSource(IAudioSource inner)
{
this.inner = inner;
- inner.Samples += buf => Samples?.Invoke(Muted || Silenced?.Invoke() == true ?new short[buf.Length] : buf);
+ inner.Samples += buf =>
+ {
+ // What the mic really hears, for EchoGate's measurement, before any silencing.
+ if (Heard is { } heard && buf.Length > 0)
+ {
+ double sum = 0;
+ foreach (var v in buf) sum += (double)v * v;
+ heard(Math.Sqrt(sum / buf.Length) / 32768, buf.Length / 16000.0);
+ }
+ Samples?.Invoke(Muted || Silenced?.Invoke() == true ? new short[buf.Length] : buf);
+ };
inner.Ended += why => Ended?.Invoke(why);
}
diff --git a/windows/src/Cicada.Core/Settings.cs b/windows/src/Cicada.Core/Settings.cs
index d1d0d9a..7b72326 100644
--- a/windows/src/Cicada.Core/Settings.cs
+++ b/windows/src/Cicada.Core/Settings.cs
@@ -23,8 +23,9 @@ public sealed class AppSettings
[JsonPropertyName("aiCustomVoice")] public string AiCustomVoice { get; set; } = "";
/// A custom service's hear model at its own address (the Mac's key); empty: the same one.
[JsonPropertyName("aiCustomHearBase")] public string AiCustomHearBase { get; set; } = "";
- /// 听哪里 (the Mac's key): "system" (电脑声音), "room" (会议室) or "both" (电脑和会议室).
- [JsonPropertyName("listenSource")] public string ListenSourceValue { get; set; } = ListenSource.System;
+ /// 打开麦克风: "both" while the mic is on, else "system" (the Mac's listenSource values; "room",
+ /// the mic alone, is the Mac's on macOS 14/15). Not saved: every launch starts with the mic off.
+ [JsonIgnore] public string ListenSourceValue { get; set; } = ListenSource.System;
[JsonIgnore] public string Listens => ListenSource.Parse(ListenSourceValue);
[JsonIgnore] public bool ListensToRoom => Listens == ListenSource.Room;
[JsonIgnore] public bool HearsBoth => Listens == ListenSource.Both;
diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.cs
index 1631c18..6ff6621 100644
--- a/windows/src/Cicada/App.cs
+++ b/windows/src/Cicada/App.cs
@@ -322,6 +322,10 @@ sealed class Controller
if (Settings.View == "notes") menu.Items.Add(NotesVisible ? Item(L("隐藏纪要窗"), ToggleNotes) : Item(L("显示纪要"), ShowNotes));
}
else menu.Items.Add(Item(L("开始听"), () => _ = ToggleListening(), Hotkey.Label.Replace('+', ' ')));
+ // 麦克风: one checkable item for what 听哪里's three were.
+ var micItem = Item(L("麦克风"), () => SetMic(!MicOn));
+ micItem.IsCheckable = true; micItem.IsChecked = MicOn;
+ menu.Items.Add(micItem);
menu.Items.Add(Settings.View == "subtitles" ? Item(L("换成纪要"), () => SetView("notes")) : Item(L("换成字幕条"), () => SetView("subtitles")));
menu.Items.Add(new Separator());
if (Updates.Available is { } update) menu.Items.Add(Item(LF("有新版本 %@", update.Version), InstallUpdate, ink: Palette.AccentText));
@@ -365,21 +369,30 @@ sealed class Controller
/// Dev builds: a WAV the room mic hears instead of a microphone.
string? fakeRoom;
public void SetFakeRoom(string? path) { fakeRoom = path; Log.Debug($"room: fake mic {(path is null ? "off" : "on")}"); }
+ /// Dev builds: what the echo measurement says, instead of measuring (the VM has no speakers).
+ bool? fakeEcho;
+ public void SetFakeEcho(bool? on) { fakeEcho = on; if (Listen.Echo is { } e) e.Gate.Forced = on; Log.Debug($"room: echo sim {on?.ToString() ?? "real"}"); }
- /// 听哪里 changed. While listening the same meeting goes on from the new source.
- public void SetListenSource(string value)
+ /// 打开麦克风 / 关闭麦克风 (AppModel.setMic on the Mac): the PC's audio is always heard; the mic
+ /// adds the people in the room to the same meeting. Not kept for the next launch: listening
+ /// never starts with the microphone open. Turning it on while nothing is heard starts listening.
+ public bool MicOn => Settings.HearsBoth;
+
+ public void SetMic(bool on)
{
- value = ListenSource.Parse(value);
- if (value == Settings.Listens) return;
+ var value = on ? ListenSource.Both : ListenSource.System;
+ if (value == Settings.Listens)
+ {
+ if (on && !Listen.Listening) _ = StartChecked(NewSource);
+ return;
+ }
Settings.ListenSourceValue = value;
- Settings.Save();
- Log.Debug($"listen source: {value}");
+ Log.Debug($"mic {(on ? "on" : "off")}");
if (Listen.Listening)
{
- if (!Settings.HearsBoth) _ = StopRoomSide();
- if (Listen.Room != Settings.ListensToRoom) Listen.SwitchSource(Watch(NewSource()), Settings.ListensToRoom);
- if (Settings.HearsBoth) StartRoomSide();
+ if (on) StartRoomSide(); else _ = StopRoomSide();
}
+ else if (on) _ = StartChecked(NewSource);
Changed();
}
@@ -387,15 +400,9 @@ sealed class Controller
/// The room side of 电脑和会议室: its own engine on the room mic, adding to the same meeting.
public readonly ListenEngine RoomListen;
- /// 线上也有人?: the meeting app in a call while only the room is heard; answered once a meeting.
- public string? OnlinePrompt { get; private set; }
- bool onlinePromptAnswered;
/// 电脑和会议室 but Windows won't give Cicada the microphone: the PC's side keeps recording.
public bool HybridMicDenied { get; private set; }
- /// The grey line under 听哪里 while both are heard: without echo cancellation the room pauses
- /// while the PC plays speech (HybridNote on the Mac, whose other cases Windows doesn't have).
- public string? HybridNote => Listen.Listening && RoomListen.Listening ? L("线上有人说话时,先不听会议室") : null;
void StartRoomSide()
{
@@ -405,6 +412,8 @@ sealed class Controller
RoomListen.Echo = echo;
var mic = RoomSource();
mic.Silenced = () => echo.Gate.Closed;
+ mic.Heard = echo.Gate.RoomLevel;
+ echo.Gate.Forced = fakeEcho;
roomSources.Add(mic);
mic.Ended += reason =>
{
@@ -435,24 +444,6 @@ sealed class Controller
Log.Debug("hybrid: room side stopped");
}
- /// 也听电脑 / 不用 on 线上也有人?.
- public void AnswerOnlinePrompt(bool both)
- {
- onlinePromptAnswered = true;
- OnlinePrompt = null;
- Log.Debug($"hybrid: online prompt answered {(both ? "both" : "no")}");
- if (both) SetListenSource(ListenSource.Both); else Changed();
- }
-
- void UpdateOnlinePrompt(Dictionary<string, string> calls)
- {
- var app = RoomPrompt.AsksOnline(Listen.Listening && Settings.ListensToRoom, onlinePromptAnswered, calls.Count > 0) ? calls.Values.First() : null;
- if (app == OnlinePrompt) return;
- OnlinePrompt = app;
- if (app is not null) Log.Debug($"hybrid: online prompt for {app}");
- Changed();
- }
-
/// A source about to be listened to: a room mic is remembered (the talk key mutes it), and one
/// that can't go on says why.
IAudioSource Watch(IAudioSource source)
@@ -577,8 +568,6 @@ sealed class Controller
problemNotified = false;
endWatch = new MeetingEndWatch(EndConfig(), DateTimeOffset.Now);
Listen.Start(source, room: source is GatedSource);
- onlinePromptAnswered = false;
- OnlinePrompt = null;
if (Settings.HearsBoth && source is SystemAudioTap) StartRoomSide();
ShowNotes();
}
@@ -590,7 +579,6 @@ sealed class Controller
Ending = null;
ConfirmingEnd = false;
AutoEnded = auto;
- OnlinePrompt = null;
HybridMicDenied = false;
await StopRoomSide();
roomSources.Clear();
@@ -623,13 +611,10 @@ sealed class Controller
bool live = Listen.Listening && endWatch is not null, after = !Listen.Listening && AutoEnded;
if (readingCalls || !(live || after) || (!live && !Settings.EndWithApp)) return;
readingCalls = true;
- // 线上也有人? needs the calls too, whatever 结束会议 says.
- var asking = live && Settings.ListensToRoom && !onlinePromptAnswered;
- Dictionary<string, string> found = Settings.EndWithApp || asking ? FakeCalls ?? await Task.Run(MicReaders.Calls) : new();
+ Dictionary<string, string> found = Settings.EndWithApp ? FakeCalls ?? await Task.Run(MicReaders.Calls) : new();
readingCalls = false;
var calls = Settings.EndWithApp ? found : new();
var now = DateTimeOffset.Now;
- UpdateOnlinePrompt(asking ? found : new());
if (Listen.Listening && endWatch is { } w)
{
w.Settings = EndConfig();
@@ -1157,6 +1142,9 @@ sealed class Controller
["updateChecked"] = Updates.LastChecked?.ToString("o"),
["inCall"] = endWatch is { } w ? string.Join(",", w.InCall.Values) : null,
["listenSource"] = Settings.Listens,
+ ["mic"] = MicOn,
+ ["roomEcho"] = Listen.Echo?.Gate.Echo,
+ ["roomMusic"] = Listen.Echo?.Gate.PlayingMusic,
["room"] = Listen.Room,
};
}
@@ -1219,7 +1207,9 @@ static class DebugServer
_ => Opened(app),
};
case "start": _ = app.StartChecked(app.NewSource); break;
- case "listensource": app.SetListenSource(arg); break;
+ // mic:<on|off> is the button; listenSource:<system|room|both> the old names for it.
+ case "mic" or "listensource": app.SetMic(arg is "on" or "both" or "room"); break;
+ case "roomechosim": app.SetFakeEcho(arg is "real" or "" ? null : arg != "off"); break;
case "fakeroom": app.SetFakeRoom(arg is "" or "off" ? null : arg); break;
case "stop": _ = app.StopListening(); break;
case "end": app.RequestStop(); break; // the user's 结束: asks first when anything was said
diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.cs
index 40390c9..61f79d5 100644
--- a/windows/src/Cicada/NotesWindow.cs
+++ b/windows/src/Cicada/NotesWindow.cs
@@ -130,10 +130,7 @@ sealed class NotesWindow : Window
if (app.ConfirmingEnd) return ConfirmEnd();
if (app.Ending is not { } p)
{
- if (app.OnlinePrompt is not { } meetingApp) return new Border();
- var strip = TrayFlyout.OnlineStrip(app, meetingApp);
- strip.Margin = new Thickness(12, 0, 12, 8);
- return strip;
+ return new Border();
}
Detach(endingDetail);
var buttons = Ui.Row(8, Ui.Button(L("继续记录"), app.KeepRecording, Ui.Kind.Primary, height: 32),
@@ -176,11 +173,11 @@ sealed class NotesWindow : Window
scroll = new ScrollViewer { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Padding = new Thickness(20, 16, 16, 12) };
Content = Subtitles ? SubtitleFrame() : PanelFrame();
}
- var key = $"{app.Listen.Listening}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";
+ var key = $"{app.Listen.Listening}|{app.MicOn}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";
if (key != headerKey) { headerKey = key; header.Content = Header(); }
Tick();
if (Subtitles) { live.Content = SubtitleLine(); return; }
- var ek = !app.Listen.Listening ? null : app.ConfirmingEnd ? "confirm" : app.Ending is { } p ? p.Reason.ToString() : app.OnlinePrompt is { } o ? "online " + o : null;
+ var ek = !app.Listen.Listening ? null : app.ConfirmingEnd ? "confirm" : app.Ending is { } p ? p.Reason.ToString() : null;
if (ek != endingKey) { endingKey = ek; ending.Content = EndingStrip(); }
var bk = $"{app.Listen.Problem}|{app.Listen.ProblemStatus}|{(app.Listen.Listening && app.Notes.Status is NotesEngine.State.Failed or NotesEngine.State.RateLimited or NotesEngine.State.Unreachable or NotesEngine.State.Updating ? app.Notes.Status : null)}|{app.Ling.Health.Failure?.Why}|{app.Settings.AiProvider}|{app.CanSwitchToLing}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";
if (bk != barsKey) { barsKey = bk; bars.Content = Bars(); }
@@ -228,6 +225,11 @@ sealed class NotesWindow : Window
buttons.Children.Add(Ui.IconButton(Icons.Notes, L("换成纪要"), () => app.SetView("notes"), Palette.NightText, 32, 16, onDark: true));
if (listen.Listening)
{
+ // 打开麦克风 (the Mac's bar has it while editing; this bar takes clicks anyway).
+ var mic = Ui.IconButton(Icons.Mic, app.MicOn ? L("关闭麦克风") : L("打开麦克风"), () => app.SetMic(!app.MicOn),
+ app.MicOn ? NightAccent : Palette.NightText, 32, 15, onDark: true);
+ if (app.MicOn) mic.Background = new SolidColorBrush(Color.FromArgb(0x33, 0xE8, 0x55, 0x2B));
+ buttons.Children.Add(Gap(mic, 6));
var stop = Ui.IconButton("M7,7 H13 V13 H7 Z", L("结束"), app.RequestStop, NightAccent, 32, 14, fill: true, onDark: true);
stop.Background = new SolidColorBrush(Color.FromArgb(0x1F, 0xFF, 0xFF, 0xFF));
buttons.Children.Add(Gap(stop, 6));
@@ -255,6 +257,7 @@ sealed class NotesWindow : Window
? Ui.Button(L("结束"), app.RequestStop, Ui.Kind.Pale, Icons.Stop, 32, iconFill: true)
: Ui.Button(L("开始听"), () => _ = app.ToggleListening(), Ui.Kind.Accent, Icons.Wave, 32);
main.MinWidth = 0; main.Padding = new Thickness(12, 0, 12, 0);
+ if (listen.Listening) right.Children.Add(Gap(TrayFlyout.MicButton(app, panel: false), 8));
right.Children.Add(Gap(main, 8));
right.Children.Add(Gap(Ui.IconButton("M5,10 H15", L("收起(继续听)"), Collapse, Palette.Body, 34, 16), 4));
var row = Ui.Spread(left, right);
diff --git a/windows/src/Cicada/TrayFlyout.cs b/windows/src/Cicada/TrayFlyout.cs
index e90c29b..d8e341b 100644
--- a/windows/src/Cicada/TrayFlyout.cs
+++ b/windows/src/Cicada/TrayFlyout.cs
@@ -154,11 +154,10 @@ sealed class TrayFlyout : Window
var spoken = Languages.Targets.FirstOrDefault(t => t.Code == Languages.FromSystem(System.Globalization.CultureInfo.CurrentUICulture.Name))?.Code;
var target = s.Target == "system" ? spoken ?? "zh-Hans" : s.Target;
stack.Children.Add(Gap(ChoiceRow(L("翻译成"), Ui.TargetName(target), s.Target == "system" ? L("跟随系统") : null, Ui.TargetOptions(), s.Target, app.SetTarget), 12));
- // 听哪里 (the Mac panel's row): changing it mid-meeting carries the same meeting on.
- var sources = new[] { (ListenSource.System, L("电脑声音(线上会议、视频)")), (ListenSource.Room, L("会议室(用麦克风听桌边的人)")), (ListenSource.Both, L("电脑和会议室(线上和桌边的人都听)")) };
- stack.Children.Add(Gap(ChoiceRow(L("听哪里"), SourceName(s.Listens), null, sources, s.Listens, app.SetListenSource), 8));
- if (app.HybridNote is { } note) stack.Children.Add(Gap(Ui.Text(note, 12, Palette.Secondary), 6));
- if (app.OnlinePrompt is { } meetingApp) stack.Children.Add(Gap(OnlineStrip(app, meetingApp, Hide), 10));
+ // 麦克风 (the Mac panel's row): turning it on mid-meeting adds the room to the same meeting.
+ var micText = Ui.Stack(2, Ui.Text(L("麦克风"), 14, Palette.Ink, Palette.Strong, wrap: false),
+ Ui.Text(app.MicOn ? L("桌边的人说话也会记下") : L("关着 · 只听电脑声音"), 12, Palette.Secondary));
+ stack.Children.Add(Gap(Ui.Spread(micText, MicButton(app, panel: true)), 14));
if (app.HybridMicDenied)
{
var text = Ui.Stack(2, Ui.Text(L("听会议室要先允许麦克风"), 13, Palette.AccentText, Palette.Strong), Ui.Text(L("电脑声音照常在记"), 11, Palette.Secondary));
@@ -204,24 +203,18 @@ sealed class TrayFlyout : Window
return stack;
}
- /// 线上也有人? / Zoom 正在通话 / 也听电脑 · 不用 (the Mac panel's strip), here and in the notes window.
- public static FrameworkElement OnlineStrip(Controller app, string meetingApp, Action? after = null)
+ /// 打开麦克风 / 关闭麦克风, the same switch in the panel and the notes window (MicButton on the
+ /// Mac): in the panel the ink button while off, a quiet one while on; in the notes window a pale
+ /// one beside 结束, tinted while on.
+ public static Button MicButton(Controller app, bool panel)
{
- var stack = Ui.Stack(3, Ui.Text(L("线上也有人?"), 14, Palette.Ink, FontWeights.Bold), Ui.Text(LF("%@ 正在通话", meetingApp), 12, Palette.Secondary));
- var buttons = Ui.Row(8, Ui.Button(L("也听电脑"), () => { after?.Invoke(); app.AnswerOnlinePrompt(true); }, Ui.Kind.Primary, height: 32),
- Ui.Button(L("不用"), () => { after?.Invoke(); app.AnswerOnlinePrompt(false); }, height: 32));
- buttons.Margin = new Thickness(0, 10, 0, 0);
- stack.Children.Add(buttons);
- return new Border { Background = Palette.AccentPale, CornerRadius = new CornerRadius(12), Padding = new Thickness(14), Child = stack };
+ var on = app.MicOn;
+ var kind = on ? (panel ? Ui.Kind.Standard : Ui.Kind.Pale) : (panel ? Ui.Kind.Primary : Ui.Kind.Standard);
+ var b = Ui.Button(on ? L("关闭麦克风") : L("打开麦克风"), () => app.SetMic(!on), kind, Icons.Mic, 32);
+ b.MinWidth = 0; b.Padding = new Thickness(12, 0, 12, 0); b.VerticalAlignment = VerticalAlignment.Center;
+ return b;
}
- public static string SourceName(string source) => source switch
- {
- ListenSource.Room => L("会议室"),
- ListenSource.Both => L("电脑和会议室"),
- _ => L("电脑声音"),
- };
-
static FrameworkElement Gap(FrameworkElement e, double top) { e.Margin = new Thickness(e.Margin.Left, top, e.Margin.Right, e.Margin.Bottom); return e; }
static FrameworkElement Rule() => new Border { Height = 1, Background = Palette.Line, Margin = new Thickness(0, 16, 0, 16) };
diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.cs
index 06ae1f7..112fba6 100644
--- a/windows/tests/Cicada.Tests/Program.cs
+++ b/windows/tests/Cicada.Tests/Program.cs
@@ -1101,6 +1101,37 @@ static class Tests
Check(got is [0, 0], "silence while you hold the talk key");
}
+ public static void EchoGateOnlyForSpeechThatReachesTheMic()
+ {
+ double now = 0;
+ var g = new EchoGate(() => now);
+ // Music: loud, and no words for EchoGate.Music seconds.
+ for (; now < EchoGate.Music - 1; now += 0.1) g.Hold();
+ Check(g.Closed && !g.PlayingMusic, "no words yet: still taken for speech");
+ for (; now < EchoGate.Music + 1; now += 0.1) g.Hold();
+ Check(g.PlayingMusic, "no words for long: music");
+ now += EchoGate.Hang + 0.01; g.Hold(); now += 0.01;
+ Check(!g.Closed, "music doesn't close the gate");
+ g.HeardWords(); g.Hold(); now += 0.1;
+ Check(g.Closed, "words close it again");
+
+ // Headphones: the room mic stays at its floor while the computer plays.
+ now = 1000;
+ var h = new EchoGate(() => now);
+ Check(h.Echo, "echo until measured");
+ for (var t = 0; t < 60; t++) { h.Hold(); now += 0.05; h.RoomLevel(0.001, 0.1); now += 0.05; }
+ for (var t = 0; t < 60; t++) { now += 0.1; h.RoomLevel(0.001, 0.1); }
+ Check(!h.Echo, "no echo measured with headphones");
+ h.Hold(); now += 0.1;
+ Check(!h.Closed, "the room stays open with headphones");
+ // Speakers: the mic hears the computer.
+ now += 100;
+ for (var t = 0; t < 60; t++) { h.Hold(); now += 0.05; h.RoomLevel(0.03, 0.1); now += 0.05; }
+ for (var t = 0; t < 60; t++) { now += 0.1; h.RoomLevel(0.001, 0.1); }
+ Check(h.Echo, "echo again once the speakers reach the mic");
+ Check(EchoGate.Ratio([(0.001, 1)], [(0.001, 10)]) is null, "not enough to tell");
+ }
+
sealed class Pump : IAudioSource
{
public event Action<short[]>? Samples;
@@ -1118,7 +1149,6 @@ static class Tests
Check(Places.HeardBoth([L("a", via: "room"), L("b")]), "both");
var starts = Places.Starts([L("a"), L("b"), L("c", via: "room"), L("d", "me"), L("e", via: "room"), L("f")]);
Check(starts.SetEquals(["a", "c", "e", "f"]), "a change of place starts a run: " + string.Join(",", starts));
- Check(RoomPrompt.AsksOnline(true, false, true) && !RoomPrompt.AsksOnline(true, true, true) && !RoomPrompt.AsksOnline(false, false, true) && !RoomPrompt.AsksOnline(true, false, false), "线上也有人? once, in a call, in the room");
}
public static async Task TheRoomSideDropsTheSpeakersAndKeepsTheTable()