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: a Turn on mic button in the menu bar panel, Live notes and the subtitle bar replaces Listen to, and people at the table are heard over music and with headphones on

wqugurufc7e3954c33b
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings
index d1aa2f4..74e1c14 100644
--- a/Resources/en.lproj/Localizable.strings
+++ b/Resources/en.lproj/Localizable.strings
@@ -226,8 +226,8 @@
/* AppModel */
"准备就绪" = "Ready";
-"会议室 · %@" = "Room · %@";
-"电脑和会议室 · %@" = "Mac + Room · %@";
+"麦克风 · %@" = "Mic · %@";
+"电脑和麦克风 · %@" = "Mac + Mic · %@";
"%@ 转好了" = "%@ is transcribed";
"%@ · %lld 句" = "%@ · %lld lines";
",正在整理纪要" = ", writing notes";
@@ -502,10 +502,8 @@
"改用 Ling" = "Use Ling";
"这轮纪要没写好 · 下轮自动补上" = "This round of notes didn't work · the next one catches up";
"电脑声音照常在记" = "The Mac's audio is still being recorded";
-"在会议室里开会?" = "Meeting in the room?";
-"电脑里 1 分钟没放出声音" = "Nothing has played on this Mac for a minute";
-"线上也有人?" = "Anyone online too?";
-"%@ 正在通话" = "%@ is in a call";
+"麦克风没声音" = "The mic is silent";
+"重开了一次也没好" = "Reopening it didn't help";
"会议纪要" = "Meeting notes";
"结束这场会议" = "End this meeting";
"收窄" = "Narrow";
@@ -550,10 +548,7 @@
"在会议记录中查看" = "View in Meetings";
"开始新会议" = "New Meeting";
"去设置" = "Open Settings";
-"改听会议室" = "Listen to the room";
-"不是" = "No";
-"也听电脑" = "Hear the Mac too";
-"不用" = "No thanks";
+"换麦克风" = "Change mic";
"连不上翻译,新字幕暂时只有原文" = "Can't reach translation; subtitles show the original only";
"填 Ling key 后不用代理也能翻译,还会整理出纪要。" = "With a Ling key, translation works without a proxy, and you get notes too.";
"填好 %@ 的 key 后用它翻译,还会整理出纪要。" = "Enter a %@ key to translate with it, and you get notes too.";
@@ -699,6 +694,8 @@
"你在说… " = "You're speaking… ";
"翻译中… " = "Translating… ";
"你:" = "You: ";
+"关闭麦克风" = "Turn off mic";
+"打开麦克风" = "Turn on mic";
/* Recognition */
"请在系统设置 › 键盘里打开“听写”" = "Turn on Dictation in System Settings › Keyboard";
@@ -731,8 +728,6 @@
"标题" = "Title";
/* RoomMic */
-"线上有人说话时,先不听会议室" = "The room pauses while someone online speaks";
-"用 Mac 麦克风听会议室" = "Hearing the room with the Mac's mic";
"已改用 Mac 自带的麦克风" = "Now using the Mac's microphone";
"已改用 %@" = "Now using %@";
"只听电脑了" = "Hearing the Mac only";
@@ -1021,13 +1016,6 @@
"自动识别(%@)" = "Auto-detect (%@)";
"要先加进系统的听写语言" = "Add it to the system's Dictation languages first";
"选中后自动下载语音模型" = "Downloads its speech model when chosen";
-"听哪里" = "Listen to";
-"会议室" = "Room";
-"电脑和会议室" = "Mac + Room";
-"电脑声音" = "This Mac";
-"电脑声音(线上会议、视频)" = "This Mac (online meetings, videos)";
-"会议室(用麦克风听桌边的人)" = "Room (the mic hears people at the table)";
-"电脑和会议室(线上和桌边的人都听)" = "Mac + Room (people online and at the table)";
"系统" = "System";
"系统麦克风还是 %@" = "System mic is still %@";
"别的软件现在听不到你说话" = "Other apps can't hear you now";
@@ -1043,6 +1031,8 @@
"屏幕上不出字幕,文字记录照常保存" = "Nothing on screen; the transcript is still saved";
"什么时候出现" = "Appears";
"填入 API key 后可生成纪要;文字记录照常保存" = "Add an API key for notes; the transcript is saved either way";
+"桌边的人说话也会记下" = "People at the table are recorded too";
+"关着 · 只听电脑声音" = "Off · Mac audio only";
"译文从扬声器念出来" = "Translations are read out from the speakers";
"系统麦克风换成 %@" = "System mic switches to %@";
"译文送进 %@" = "Translations go into %@";
@@ -1068,6 +1058,8 @@
"收起更早的会议" = "Hide earlier meetings";
"更早的会议" = "Earlier meetings";
"只有录音" = "Recording only";
+"电脑和会议室" = "Mac + Room";
+"会议室" = "Room";
"未命名会议" = "Untitled meeting";
"转写中 %lld%%" = "%lld%%";
"翻译中" = "Translating";
@@ -1213,6 +1205,7 @@
"导入录音或视频" = "Import a Recording or Video";
/* LiveViews */
+"会议室 · %@" = "Room · %@";
"正在听 · %@" = "Listening · %@";
"对方说和翻译成" = "They speak, and translate into";
"%lld 人在说" = "%lld people talking";
diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.strings
index 82bc194..6551d4a 100644
--- a/Resources/ja.lproj/Localizable.strings
+++ b/Resources/ja.lproj/Localizable.strings
@@ -226,8 +226,8 @@
/* AppModel */
"准备就绪" = "準備完了";
-"会议室 · %@" = "会議室 · %@";
-"电脑和会议室 · %@" = "Mac と会議室 · %@";
+"麦克风 · %@" = "マイク · %@";
+"电脑和麦克风 · %@" = "Mac とマイク · %@";
"%@ 转好了" = "%@ の文字起こしが完了";
"%@ · %lld 句" = "%@ · %lld文";
",正在整理纪要" = "、メモを作成中";
@@ -502,10 +502,8 @@
"改用 Ling" = "Ling に切り替え";
"这轮纪要没写好 · 下轮自动补上" = "今回のメモはまとまらず · 次の回で自動で補います";
"电脑声音照常在记" = "Mac の音声はそのまま記録中";
-"在会议室里开会?" = "会議室で会議中?";
-"电脑里 1 分钟没放出声音" = "1 分間 Mac から音が出ていません";
-"线上也有人?" = "オンラインの参加者も?";
-"%@ 正在通话" = "%@ で通話中";
+"麦克风没声音" = "マイクの音が入りません";
+"重开了一次也没好" = "開き直しても直りません";
"会议纪要" = "会議の議事メモ";
"结束这场会议" = "この会議を終了";
"收窄" = "幅を狭める";
@@ -550,10 +548,7 @@
"在会议记录中查看" = "会議の記録で見る";
"开始新会议" = "新しい会議を開始";
"去设置" = "設定を開く";
-"改听会议室" = "会議室を聞く";
-"不是" = "いいえ";
-"也听电脑" = "Mac も聞く";
-"不用" = "いいえ";
+"换麦克风" = "マイクを変更";
"连不上翻译,新字幕暂时只有原文" = "翻訳につながりません。字幕は原文のみです";
"填 Ling key 后不用代理也能翻译,还会整理出纪要。" = "Ling の key を入れると、プロキシなしで翻訳でき、議事メモも作られます。";
"填好 %@ 的 key 后用它翻译,还会整理出纪要。" = "%@ の key を入れるとそれで翻訳し、議事メモも作られます。";
@@ -699,6 +694,8 @@
"你在说… " = "話しています… ";
"翻译中… " = "翻訳中… ";
"你:" = "あなた: ";
+"关闭麦克风" = "マイクをオフ";
+"打开麦克风" = "マイクをオン";
/* Recognition */
"请在系统设置 › 键盘里打开“听写”" = "システム設定 › キーボードで「音声入力」をオンにしてください";
@@ -731,8 +728,6 @@
"标题" = "タイトル";
/* RoomMic */
-"线上有人说话时,先不听会议室" = "オンラインの人が話す間は会議室を聞きません";
-"用 Mac 麦克风听会议室" = "会議室は Mac のマイクで聞きます";
"已改用 Mac 自带的麦克风" = "Mac 内蔵のマイクに切り替えました";
"已改用 %@" = "%@ に切り替えました";
"只听电脑了" = "パソコンの音だけを聞いています";
@@ -1021,13 +1016,6 @@
"自动识别(%@)" = "自動検出(%@)";
"要先加进系统的听写语言" = "先にシステムの音声入力の言語に追加してください";
"选中后自动下载语音模型" = "選ぶと音声モデルを自動ダウンロード";
-"听哪里" = "聞く場所";
-"会议室" = "会議室";
-"电脑和会议室" = "Mac と会議室";
-"电脑声音" = "この Mac";
-"电脑声音(线上会议、视频)" = "この Mac(オンライン会議・動画)";
-"会议室(用麦克风听桌边的人)" = "会議室(マイクでテーブルの声を聞く)";
-"电脑和会议室(线上和桌边的人都听)" = "Mac と会議室(オンラインとテーブルの両方)";
"系统" = "システム";
"系统麦克风还是 %@" = "システムのマイクがまだ %@ です";
"别的软件现在听不到你说话" = "ほかのアプリにあなたの声が届きません";
@@ -1043,6 +1031,8 @@
"屏幕上不出字幕,文字记录照常保存" = "画面には何も出しません。文字起こしは保存されます";
"什么时候出现" = "表示するタイミング";
"填入 API key 后可生成纪要;文字记录照常保存" = "API key を入力すると議事メモを作成できます。文字起こしは常に保存されます";
+"桌边的人说话也会记下" = "テーブルの人の発言も記録します";
+"关着 · 只听电脑声音" = "オフ · Mac の音だけ";
"译文从扬声器念出来" = "訳文はスピーカーから読み上げます";
"系统麦克风换成 %@" = "システムのマイクを %@ に切り替え";
"译文送进 %@" = "訳文を %@ に送ります";
@@ -1068,6 +1058,8 @@
"收起更早的会议" = "以前の会議を隠す";
"更早的会议" = "以前の会議";
"只有录音" = "録音のみ";
+"电脑和会议室" = "Mac と会議室";
+"会议室" = "会議室";
"未命名会议" = "無題の会議";
"转写中 %lld%%" = "文字起こし中 %lld%%";
"翻译中" = "翻訳中";
@@ -1213,6 +1205,7 @@
"导入录音或视频" = "録音や動画を読み込む";
/* LiveViews */
+"会议室 · %@" = "会議室 · %@";
"正在听 · %@" = "聞いています · %@";
"对方说和翻译成" = "相手の言語と翻訳先";
"%lld 人在说" = "%lld 人が話しています";
diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.strings
index 94aa04b..e6b077d 100644
--- a/Resources/ko.lproj/Localizable.strings
+++ b/Resources/ko.lproj/Localizable.strings
@@ -226,8 +226,8 @@
/* AppModel */
"准备就绪" = "준비 완료";
-"会议室 · %@" = "회의실 · %@";
-"电脑和会议室 · %@" = "Mac과 회의실 · %@";
+"麦克风 · %@" = "마이크 · %@";
+"电脑和麦克风 · %@" = "Mac과 마이크 · %@";
"%@ 转好了" = "%@ 받아쓰기 완료";
"%@ · %lld 句" = "%@ · %lld문장";
",正在整理纪要" = ", 노트 작성 중";
@@ -502,10 +502,8 @@
"改用 Ling" = "Ling으로 전환";
"这轮纪要没写好 · 下轮自动补上" = "이번 노트는 정리되지 않음 · 다음 회차에 자동으로 보완";
"电脑声音照常在记" = "Mac 소리는 계속 기록 중";
-"在会议室里开会?" = "회의실에서 회의 중인가요?";
-"电脑里 1 分钟没放出声音" = "1분 동안 Mac에서 소리가 나지 않았어요";
-"线上也有人?" = "온라인 참석자도 있나요?";
-"%@ 正在通话" = "%@ 통화 중";
+"麦克风没声音" = "마이크에서 소리가 안 들어와요";
+"重开了一次也没好" = "다시 켜도 그대로예요";
"会议纪要" = "회의록";
"结束这场会议" = "이 회의 종료";
"收窄" = "좁게";
@@ -550,10 +548,7 @@
"在会议记录中查看" = "회의 기록에서 보기";
"开始新会议" = "새 회의 시작";
"去设置" = "설정 열기";
-"改听会议室" = "회의실 듣기";
-"不是" = "아니요";
-"也听电脑" = "Mac도 듣기";
-"不用" = "괜찮아요";
+"换麦克风" = "마이크 바꾸기";
"连不上翻译,新字幕暂时只有原文" = "번역에 연결할 수 없어 자막은 원문만 표시됩니다";
"填 Ling key 后不用代理也能翻译,还会整理出纪要。" = "Ling key를 입력하면 프록시 없이도 번역되고 회의록도 정리됩니다.";
"填好 %@ 的 key 后用它翻译,还会整理出纪要。" = "%@ key를 입력하면 그것으로 번역하고 회의록도 정리됩니다.";
@@ -699,6 +694,8 @@
"你在说… " = "말하는 중… ";
"翻译中… " = "번역 중… ";
"你:" = "나: ";
+"关闭麦克风" = "마이크 끄기";
+"打开麦克风" = "마이크 켜기";
/* Recognition */
"请在系统设置 › 键盘里打开“听写”" = "시스템 설정 › 키보드에서 ‘받아쓰기’를 켜 주세요";
@@ -731,8 +728,6 @@
"标题" = "제목";
/* RoomMic */
-"线上有人说话时,先不听会议室" = "온라인에서 말하는 동안 회의실은 잠시 듣지 않아요";
-"用 Mac 麦克风听会议室" = "회의실은 Mac 마이크로 들어요";
"已改用 Mac 自带的麦克风" = "Mac 내장 마이크로 바꿨어요";
"已改用 %@" = "%@(으)로 바꿨어요";
"只听电脑了" = "컴퓨터 소리만 듣고 있어요";
@@ -1021,13 +1016,6 @@
"自动识别(%@)" = "자동 감지(%@)";
"要先加进系统的听写语言" = "먼저 시스템 받아쓰기 언어에 추가해 주세요";
"选中后自动下载语音模型" = "선택하면 음성 모델을 자동 다운로드";
-"听哪里" = "듣는 곳";
-"会议室" = "회의실";
-"电脑和会议室" = "Mac과 회의실";
-"电脑声音" = "이 Mac";
-"电脑声音(线上会议、视频)" = "이 Mac (온라인 회의, 동영상)";
-"会议室(用麦克风听桌边的人)" = "회의실 (마이크로 테이블의 목소리를 들어요)";
-"电脑和会议室(线上和桌边的人都听)" = "Mac과 회의실 (온라인과 테이블 모두)";
"系统" = "시스템";
"系统麦克风还是 %@" = "시스템 마이크가 아직 %@예요";
"别的软件现在听不到你说话" = "다른 앱에 내 목소리가 들리지 않아요";
@@ -1043,6 +1031,8 @@
"屏幕上不出字幕,文字记录照常保存" = "화면에는 표시하지 않고, 대화 기록은 그대로 저장됩니다";
"什么时候出现" = "표시 시점";
"填入 API key 后可生成纪要;文字记录照常保存" = "API key를 입력하면 회의록을 작성할 수 있으며, 대화 기록은 그대로 저장됩니다";
+"桌边的人说话也会记下" = "테이블에 있는 사람의 말도 기록해요";
+"关着 · 只听电脑声音" = "꺼짐 · Mac 소리만";
"译文从扬声器念出来" = "번역은 스피커로 읽어 줘요";
"系统麦克风换成 %@" = "시스템 마이크를 %@(으)로 전환";
"译文送进 %@" = "번역을 %@(으)로 보냅니다";
@@ -1068,6 +1058,8 @@
"收起更早的会议" = "이전 회의 숨기기";
"更早的会议" = "이전 회의";
"只有录音" = "녹음만 있음";
+"电脑和会议室" = "Mac과 회의실";
+"会议室" = "회의실";
"未命名会议" = "제목 없는 회의";
"转写中 %lld%%" = "받아쓰는 중 %lld%%";
"翻译中" = "번역 중";
@@ -1213,6 +1205,7 @@
"导入录音或视频" = "녹음 또는 동영상 가져오기";
/* LiveViews */
+"会议室 · %@" = "회의실 · %@";
"正在听 · %@" = "듣는 중 · %@";
"对方说和翻译成" = "상대 언어와 번역할 언어";
"%lld 人在说" = "%lld명이 말하는 중";
diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.strings
index ad05127..a16fd57 100644
--- a/Resources/zh-Hans.lproj/Localizable.strings
+++ b/Resources/zh-Hans.lproj/Localizable.strings
@@ -226,8 +226,8 @@
/* AppModel */
"准备就绪" = "准备就绪";
-"会议室 · %@" = "会议室 · %@";
-"电脑和会议室 · %@" = "电脑和会议室 · %@";
+"麦克风 · %@" = "麦克风 · %@";
+"电脑和麦克风 · %@" = "电脑和麦克风 · %@";
"%@ 转好了" = "%@ 转好了";
"%@ · %lld 句" = "%@ · %lld 句";
",正在整理纪要" = ",正在整理纪要";
@@ -502,10 +502,8 @@
"改用 Ling" = "改用 Ling";
"这轮纪要没写好 · 下轮自动补上" = "这轮纪要没写好 · 下轮自动补上";
"电脑声音照常在记" = "电脑声音照常在记";
-"在会议室里开会?" = "在会议室里开会?";
-"电脑里 1 分钟没放出声音" = "电脑里 1 分钟没放出声音";
-"线上也有人?" = "线上也有人?";
-"%@ 正在通话" = "%@ 正在通话";
+"麦克风没声音" = "麦克风没声音";
+"重开了一次也没好" = "重开了一次也没好";
"会议纪要" = "会议纪要";
"结束这场会议" = "结束这场会议";
"收窄" = "收窄";
@@ -550,10 +548,7 @@
"在会议记录中查看" = "在会议记录中查看";
"开始新会议" = "开始新会议";
"去设置" = "去设置";
-"改听会议室" = "改听会议室";
-"不是" = "不是";
-"也听电脑" = "也听电脑";
-"不用" = "不用";
+"换麦克风" = "换麦克风";
"连不上翻译,新字幕暂时只有原文" = "连不上翻译,新字幕暂时只有原文";
"填 Ling key 后不用代理也能翻译,还会整理出纪要。" = "填 Ling key 后不用代理也能翻译,还会整理出纪要。";
"填好 %@ 的 key 后用它翻译,还会整理出纪要。" = "填好 %@ 的 key 后用它翻译,还会整理出纪要。";
@@ -699,6 +694,8 @@
"你在说… " = "你在说… ";
"翻译中… " = "翻译中… ";
"你:" = "你:";
+"关闭麦克风" = "关闭麦克风";
+"打开麦克风" = "打开麦克风";
/* Recognition */
"请在系统设置 › 键盘里打开“听写”" = "请在系统设置 › 键盘里打开“听写”";
@@ -731,8 +728,6 @@
"标题" = "标题";
/* RoomMic */
-"线上有人说话时,先不听会议室" = "线上有人说话时,先不听会议室";
-"用 Mac 麦克风听会议室" = "用 Mac 麦克风听会议室";
"已改用 Mac 自带的麦克风" = "已改用 Mac 自带的麦克风";
"已改用 %@" = "已改用 %@";
"只听电脑了" = "只听电脑了";
@@ -1021,13 +1016,6 @@
"自动识别(%@)" = "自动识别(%@)";
"要先加进系统的听写语言" = "要先加进系统的听写语言";
"选中后自动下载语音模型" = "选中后自动下载语音模型";
-"听哪里" = "听哪里";
-"会议室" = "会议室";
-"电脑和会议室" = "电脑和会议室";
-"电脑声音" = "电脑声音";
-"电脑声音(线上会议、视频)" = "电脑声音(线上会议、视频)";
-"会议室(用麦克风听桌边的人)" = "会议室(用麦克风听桌边的人)";
-"电脑和会议室(线上和桌边的人都听)" = "电脑和会议室(线上和桌边的人都听)";
"系统" = "系统";
"系统麦克风还是 %@" = "系统麦克风还是 %@";
"别的软件现在听不到你说话" = "别的软件现在听不到你说话";
@@ -1043,6 +1031,8 @@
"屏幕上不出字幕,文字记录照常保存" = "屏幕上不出字幕,文字记录照常保存";
"什么时候出现" = "什么时候出现";
"填入 API key 后可生成纪要;文字记录照常保存" = "填入 API key 后可生成纪要;文字记录照常保存";
+"桌边的人说话也会记下" = "桌边的人说话也会记下";
+"关着 · 只听电脑声音" = "关着 · 只听电脑声音";
"译文从扬声器念出来" = "译文从扬声器念出来";
"系统麦克风换成 %@" = "系统麦克风换成 %@";
"译文送进 %@" = "译文送进 %@";
@@ -1068,6 +1058,8 @@
"收起更早的会议" = "收起更早的会议";
"更早的会议" = "更早的会议";
"只有录音" = "只有录音";
+"电脑和会议室" = "电脑和会议室";
+"会议室" = "会议室";
"未命名会议" = "未命名会议";
"转写中 %lld%%" = "转写中 %lld%%";
"翻译中" = "翻译中";
@@ -1213,6 +1205,7 @@
"导入录音或视频" = "导入录音或视频";
/* LiveViews */
+"会议室 · %@" = "会议室 · %@";
"正在听 · %@" = "正在听 · %@";
"对方说和翻译成" = "对方说和翻译成";
"%lld 人在说" = "%lld 人在说";
diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swift
index c1aa283..20f8bf1 100644
--- a/Sources/Cicada/AppModel.swift
+++ b/Sources/Cicada/AppModel.swift
@@ -23,9 +23,10 @@ final class AppModel: ObservableObject {
/// 电脑和会议室: the microphone side, its own engine (language, pauses, model), as Feishu keeps the
/// online and the room streams apart instead of mixing them into one track.
lazy var roomListen = ListenEngine(settings: settings, role: .room)
- /// Debug (`roomEcho:off`, `roomGate:off`): the room without echo cancellation, or without the
- /// gate, to try each defence alone. Next meeting.
- var roomEchoCancel = true
+ /// Debug (`roomEcho:on`, `roomGate:off`): the room through the echo-cancelling unit, or without
+ /// the gate, to try each defence alone. Next meeting. The unit is off by default: it let no echo
+ /// through, but lost most of what people at the table said (`EchoGate`).
+ var roomEchoCancel = false
var roomEchoGate = true
/// The Mac's lines of late (wall clock), and room lines waiting to be told apart from their echo.
private var recentOnline: [EchoMatch.Heard] = []
@@ -79,12 +80,6 @@ final class AppModel: ObservableObject {
/// 继续等 was chosen: the offer stays away until the next meeting.
private var cloudDeclined = false
@Published var identifyingLanguage = false
- /// 在会议室里开会? in the panel: the Mac has played nothing for a minute of listening.
- @Published var roomPrompt = false
- /// 线上也有人? in the panel: the meeting app on this Mac in a call while listening to the room
- /// alone; its name for the grey line.
- @Published var onlinePrompt: String?
- private var callCheck: (at: Date, name: String?) = (.distantPast, nil)
/// 电脑和会议室 with the microphone not allowed: the Mac's side goes on, the room's can't start.
@Published var hybridMicDenied = false
/// Debug (`micDeniedSim`): 电脑和会议室 acts as if the microphone were refused.
@@ -95,18 +90,12 @@ final class AppModel: ObservableObject {
@Published private(set) var problem: String?
private var micDeniedSince: Date?
private var micDeniedNotified = false
- /// HybridNote under 听哪里.
- @Published var hybridNote: String?
- private var headsetCheck: (at: Date, on: Bool) = (.distantPast, false)
+ /// 麦克风没声音: the room mic stayed digital silence after being opened again.
+ @Published var roomMicSilent = false
/// 外接麦克风断开了: what happened instead (RoomMicLoss), for a few seconds.
@Published var roomMicLost: String?
/// The debug command's pretend unplug: these inputs count as gone.
private var fakeGoneMics: Set<String> = []
- /// Answered (or 听哪里 changed) in this meeting: not asked again until the next one.
- var roomPromptDismissed = false
- /// 线上也有人? answered this meeting. Its own flag: picking 会议室 by hand answers the question
- /// above, but a call starting afterwards is still worth asking about.
- var onlinePromptDismissed = false
/// Why the model 听不出 needed couldn't be had, when that is so.
@Published var modelProblem: ModelProblem?
/// That model was the one to start with and there is none to fall back on: nothing is listening.
@@ -189,6 +178,9 @@ final class AppModel: ObservableObject {
init() {
// A meeting or speaking holds the update notification until it ends (see stop()).
updates.busy = { [weak self] in guard let self else { return false }; return self.running || self.speak.phase != .idle }
+ // Words in the Mac's audio: speech, which the room mic is silenced for (music isn't, `EchoGate`).
+ listen.onWords = { [gate = roomListen.echoGate] in gate.heardWords() }
+ roomListen.onStateChange = { [weak self] in self?.refresh() }
listen.onSubtitle = { [weak self] src, dst in
guard let self else { return }
// Someone is speaking either way; only the wrong model's words aren't shown.
@@ -340,6 +332,7 @@ final class AppModel: ObservableObject {
talkRight.onCancel = { [weak self] in
DispatchQueue.main.async { MainActor.assumeIsolated { self?.speak.pressCancelled() } }
}
+ overlay.onMic = { [weak self] in MainActor.assumeIsolated { guard let self else { return }; self.setMic(!self.micOn) } }
overlay.onCollapsed = { [weak self] in
self?.listen.clearDisplay()
self?.overlay.setSubtitle(source: "", translation: "")
@@ -355,7 +348,6 @@ final class AppModel: ObservableObject {
let watch = Timer(timeInterval: 2, repeats: true) { [weak self] _ in
MainActor.assumeIsolated {
self?.watchEnd()
- self?.updateOnlinePrompt()
self?.watchRoomMic()
}
}
@@ -363,23 +355,6 @@ final class AppModel: ObservableObject {
RunLoop.main.add(watch, forMode: .common)
}
- /// 线上也有人?: from refresh, and from the 2-second watch, since a quiet room may change nothing
- /// in the engine for a while after a call starts.
- private func updateOnlinePrompt() {
- let roomOnly = listen.isRunning && settings.listensToRoom
- var call: String?
- if roomOnly, !onlinePromptDismissed, !Recognition.legacy {
- // refresh runs on every engine change; asking Core Audio who reads the mic is not free.
- if Date().timeIntervalSince(callCheck.at) >= 2 {
- callCheck = (Date(), (fakeCalls ?? MicUsers.currentCalls()).sorted { $0.key < $1.key }.first?.value)
- }
- call = callCheck.name
- }
- let ask = RoomPrompt.asksOnline(roomOnly: roomOnly, bothAvailable: !Recognition.legacy,
- answered: onlinePromptDismissed, inCall: call != nil) ? call : nil
- if ask != onlinePrompt { onlinePrompt = ask }
- }
-
/// The room's microphone unplugged: Core Audio moves the engine to the system default without a
/// word, which may be a headset or the virtual mic. Pick again the way the meeting started, and say so.
private func watchRoomMic() {
@@ -435,8 +410,8 @@ final class AppModel: ObservableObject {
running = listen.isRunning
// Once the tap has run, the permission is there: pausing doesn't take it away.
systemAudioOK = systemAudioOK || (listen.isRunning && !settings.listensToRoom)
- summary = settings.listensToRoom ? L("会议室 · \(listen.languageSummary())")
- : settings.hearsBoth ? L("电脑和会议室 · \(listen.languageSummary())") : listen.languageSummary()
+ summary = settings.listensToRoom ? L("麦克风 · \(listen.languageSummary())")
+ : settings.hearsBoth ? L("电脑和麦克风 · \(listen.languageSummary())") : listen.languageSummary()
candidates = listen.candidates
installed = listen.installedLocales
let ask = listen.asksLanguage ? listen.askChoices : []
@@ -448,20 +423,10 @@ final class AppModel: ObservableObject {
listening: listen.cloudListening, back: listen.cloudBack?.name)
if cloudNow != cloud { cloud = cloudNow }
if listen.identifyingLanguage != identifyingLanguage { identifyingLanguage = listen.identifyingLanguage }
- let roomAsk = listen.isRunning && RoomPrompt.shows(silent: listen.macSilent, answered: roomPromptDismissed,
- inCall: listen.macSilent && !(fakeCalls ?? MicUsers.currentCalls()).isEmpty)
- if roomAsk != roomPrompt { roomPrompt = roomAsk }
- updateOnlinePrompt()
- let both = listen.isRunning && settings.hearsBoth && !Recognition.legacy
checkProblem()
- if both, Date().timeIntervalSince(headsetCheck.at) >= 2 {
- let def = AudioDevices.defaultInput
- let t = def.map { AudioDevices.transport($0.id) }
- headsetCheck = (Date(), t == kAudioDeviceTransportTypeBluetooth || t == kAudioDeviceTransportTypeBluetoothLE)
- }
- let note = both ? HybridNote.line(roomRunning: roomListen.isRunning, echoCancelled: roomListen.hearsEchoCancelled,
- headsetDefault: headsetCheck.on) : nil
- if note != hybridNote { hybridNote = note }
+ let silent = micOn && (settings.hearsBoth ? roomListen : listen).roomMicSilent
+ if silent != roomMicSilent { roomMicSilent = silent }
+ overlay.setMic(micOn)
if listen.modelProblem != modelProblem { modelProblem = listen.modelProblem }
if listen.blockedByModel != modelBlocked { modelBlocked = listen.blockedByModel }
let notInstalled = !ask.isEmpty && listen.mismatch && ask.allSatisfy { !listen.candidates.contains($0) }
@@ -569,6 +534,12 @@ final class AppModel: ObservableObject {
}
func openMicrophoneSettings() { openSettingsPane("Privacy_Microphone") }
+ /// 换麦克风: the room is heard by the system's input (`RoomMicPlan`), picked in Sound.
+ func openSoundInputSettings() {
+ if let url = URL(string: "x-apple.systempreferences:com.apple.Sound-Settings.extension?input") {
+ NSWorkspace.shared.open(url)
+ }
+ }
/// On each change and every second: the menu bar's dot, the subtitle bar's notice and the
/// notification. Never a dialog: it would take the focus from the meeting app, and show in a
@@ -681,8 +652,6 @@ final class AppModel: ObservableObject {
liveSource = ""
liveTranslation = ""
speechHeard = false
- roomPromptDismissed = false
- onlinePromptDismissed = false
fakeGoneMics = []
micDeniedNotified = false
meetingSubtitles = nil
@@ -889,39 +858,35 @@ final class AppModel: ObservableObject {
// MARK: Settings actions
- /// 听哪里 in the panel: "system", "room" or "both".
- var listenSourceSelection: String {
- get { settings.listenSource }
- set {
- guard newValue != settings.listenSource else { return }
- let wasRoomOnly = settings.listensToRoom
- settings.listenSource = ["room", "both"].contains(newValue) ? newValue : "system"
- roomPromptDismissed = true
- if listen.isRunning && settings.hearsRoom { store.markLiveInRoom() }
- // The main engine changes only between the Mac and the room alone; "both" adds the room side.
- if wasRoomOnly != settings.listensToRoom { listen.listenSourceChanged() }
- if listen.isRunning {
- if settings.hearsBoth { startRoomSide() } else { stopRoomSide() }
- }
- applySystemMic()
- refreshMicUsers()
- refresh()
- objectWillChange.send()
+ /// 打开麦克风 / 关闭麦克风, in the panel, the notes window and the subtitle bar. The Mac's audio is
+ /// always heard; the microphone adds the people in the room to the same meeting (macOS 14/15,
+ /// where two recognizers interrupt each other: the microphone in place of the Mac's audio).
+ /// Not kept for the next launch: listening starts by itself, never with the microphone open.
+ var micOn: Bool { settings.hearsRoom }
+
+ func setMic(_ on: Bool) {
+ let value = !on ? "system" : Recognition.legacy ? "room" : "both"
+ // Asking for the room is asking to listen, even with the switch already on.
+ if value == settings.listenSource {
+ if on, !listen.isRunning { start(byUser: true) }
+ return
}
- }
-
- /// 改听会议室 / 不是 on the 在会议室里开会? strip.
- func answerRoomPrompt(_ room: Bool) {
- debugLog("room prompt answered: \(room ? "room" : "no")")
- roomPromptDismissed = true
- if room { listenSourceSelection = "room" } else { refresh() }
- }
-
- /// 也听电脑 / 不用 on the 线上也有人? strip.
- func answerOnlinePrompt(_ both: Bool) {
- debugLog("online prompt answered: \(both ? "both" : "no")")
- onlinePromptDismissed = true
- if both { listenSourceSelection = "both" } else { refresh() }
+ debugLog("mic \(on ? "on" : "off") (\(value))")
+ let wasRoomOnly = settings.listensToRoom
+ settings.listenSource = value
+ if listen.isRunning && settings.hearsRoom { store.markLiveInRoom() }
+ // The main engine changes only between the Mac and the room alone; "both" adds the room side.
+ if wasRoomOnly != settings.listensToRoom { listen.listenSourceChanged() }
+ if listen.isRunning {
+ if settings.hearsBoth { startRoomSide() } else { stopRoomSide() }
+ } else if on {
+ // Asking for the room is asking to listen.
+ start(byUser: true)
+ }
+ applySystemMic()
+ refreshMicUsers()
+ refresh()
+ objectWillChange.send()
}
/// The room mic hears silence from the talk key going down until the translation has been
@@ -1672,15 +1637,20 @@ final class AppModel: ObservableObject {
if let lang = sourceLanguages.first(where: { $0.locale == arg }) { listen.pickLanguage(lang) }
case "stop": stop()
case "source": sourceSelection = arg
- case "listenSource": listenSourceSelection = arg
- case "roomPrompt": answerRoomPrompt(arg == "room")
+ case "listenSource", "mic":
+ // mic:<on|off> is the button; listenSource:<system|room|both> the old names for it.
+ setMic(arg == "on" || arg == "room" || arg == "both")
+ case "roomEchoSim":
+ // roomEchoSim:<on|off|real>: pretend the speakers do (or don't) reach the room mic.
+ roomListen.echoGate.forced = arg == "real" ? nil : arg != "off"
+ case "roomMicSilent":
+ // roomMicSilent:<on|off>: the room mic delivers nothing but zeros (from its next start).
+ RoomMic.simulateSilence = arg != "off"
case "roomMicGone":
// roomMicGone[:none]: pretend the room's microphone (or every one) was unplugged.
let uid = (settings.hearsBoth ? roomListen : listen).roomMicUID
fakeGoneMics = arg == "none" ? Set(AudioDevices.inputs().map(\.uid)) : Set([uid].compactMap { $0 })
watchRoomMic()
- case "onlinePrompt":
- if arg == "state" { debugLog("online prompt: \(onlinePrompt ?? "hidden")") } else { answerOnlinePrompt(arg == "both") }
case "open": openMainWindow?()
case "panel": showPanel?()
case "onboarding":
@@ -1978,6 +1948,7 @@ final class AppModel: ObservableObject {
debugLog("hybrid state source=\(settings.listenSource) main=\(listen.isRunning) room=\(roomListen.isRunning) "
+ "echoCancelled=\(roomListen.hearsEchoCancelled) roomLang=\(roomListen.activeLang?.locale ?? "-") "
+ "mainLang=\(listen.activeLang?.locale ?? "-") held=\(heldRoom.count) voiceMic=\(voiceMic.inUse) "
+ + "echo=\(roomListen.echoGate.echo) [\(roomListen.echoGate.summary)] music=\(roomListen.echoGate.playingMusic()) micSilent=\(roomMicSilent) "
+ String(format: "roomVoiced=%.1fs mainVoiced=%.1fs", roomListen.router.stats().voicedTotal, listen.router.stats().voicedTotal))
case "speakTest":
// speakTest:<sample|voice>: open settings › 同声传译 with the 试一句 sheet and run it.
diff --git a/Sources/Cicada/ListenEngine.swift b/Sources/Cicada/ListenEngine.swift
index c9685e0..ceffe69 100644
--- a/Sources/Cicada/ListenEngine.swift
+++ b/Sources/Cicada/ListenEngine.swift
@@ -36,6 +36,10 @@ final class ListenEngine {
var onTranslated: ((_ segmentID: Int, _ translation: String) -> Void)?
/// Diagnostics: how long a sentence took from its last new words to its translation on screen.
var onTiming: ((SentenceTiming) -> Void)?
+ /// The recognizer heard words (a draft or a line), whether or not they are shown.
+ var onWords: (() -> Void)?
+ /// The room mic stayed digital silence even after it was opened again (`RoomMic.onSilent`).
+ private(set) var roomMicSilent = false
let settings: AppSettings
let router = AudioRouter()
@@ -124,8 +128,6 @@ final class ListenEngine {
/// The Mac reading a translation aloud, or the talk key held: the room mic hears silence then.
private var roomMuted = false
private var startedAt = Date()
- /// Listening to the Mac, and it has played nothing since the start: maybe the meeting is in the room.
- private(set) var macSilent = false
private var recognizer: RecognitionStream?
private var resultsTask: Task<Void, Never>?
/// The room engine's clocks and segment ids start far above the main one's, so lines from the two
@@ -346,7 +348,6 @@ final class ListenEngine {
cloudBack = nil
serverFellBack = false
startedAt = Date()
- macSilent = false
updateHold()
debugLog("listen start mode=\(settings.sourceMode) target=\(resolvedTarget)")
@@ -488,6 +489,14 @@ final class ListenEngine {
let mic = RoomMic(device: roomDevice?())
mic.muted = roomMuted
if role == .room { mic.echoGate = echoGate }
+ roomMicSilent = false
+ mic.onSilent = { [weak self, weak mic] in
+ MainActor.assumeIsolated {
+ guard let self, let mic, self.audioTap === mic else { return }
+ self.roomMicSilent = true
+ self.onStateChange?()
+ }
+ }
let router = self.router
mic.onAudio = { pcm in router.push(pcm) }
do {
@@ -732,6 +741,8 @@ final class ListenEngine {
guard gen == generation, isRunning else { return }
failureStreak = 0
var text = result.text.trimmingCharacters(in: .whitespacesAndNewlines)
+ // Before any holding for the language: words at all is what tells speech from music.
+ if !text.isEmpty { onWords?() }
if result.isFinal {
text = HeardText.clean(text)
let fuller = HeardText.fuller(final: text, draft: volatileText)
@@ -1259,14 +1270,6 @@ final class ListenEngine {
guard self.ticks % 4 == 0 else { return }
self.translateVolatile()
self.maybeDetectLanguage()
- let silent = self.role == .main && RoomPrompt.asks(room: self.settings.hearsRoom,
- listened: Date().timeIntervalSince(self.startedAt),
- voiced: self.router.stats().voicedTotal)
- if silent != self.macSilent {
- self.macSilent = silent
- debugLog("mac silent \(silent)")
- self.onStateChange?()
- }
if self.ticks % 20 == 0 { self.checkDictation() }
// The fetch's progress, and 听不出 coming or going, redraw the windows.
if let back = self.cloudBack, Date().timeIntervalSince(back.at) > 6 { self.cloudBack = nil }
diff --git a/Sources/Cicada/NotesWindow.swift b/Sources/Cicada/NotesWindow.swift
index 8961f9b..a7378db 100644
--- a/Sources/Cicada/NotesWindow.swift
+++ b/Sources/Cicada/NotesWindow.swift
@@ -354,6 +354,7 @@ struct NotesWindowView: View {
.lineLimit(1).minimumScaleFactor(0.75)
Spacer(minLength: 8)
if live {
+ MicButton(model: model, settings: settings, inHeader: true).padding(.trailing, 2)
Button(action: askToEnd) {
Text("结束").font(.system(size: 12, weight: .semibold)).foregroundStyle(Palette.ink)
.padding(.horizontal, 12).frame(height: 28)
@@ -713,16 +714,9 @@ struct NotesWindowView: View {
SoftButton(L("去设置"), dark: true) { model.openMicrophoneSettings() }
}
}
- if model.roomPrompt {
- ask(L("在会议室里开会?"), L("电脑里 1 分钟没放出声音")) {
- SoftButton(L("改听会议室"), dark: true) { model.answerRoomPrompt(true) }
- SoftButton(L("不是")) { model.answerRoomPrompt(false) }
- }
- }
- if let app = model.onlinePrompt {
- ask(L("线上也有人?"), L("\(app) 正在通话")) {
- SoftButton(L("也听电脑"), dark: true) { model.answerOnlinePrompt(true) }
- SoftButton(L("不用")) { model.answerOnlinePrompt(false) }
+ if model.roomMicSilent {
+ ask(L("麦克风没声音"), L("重开了一次也没好")) {
+ SoftButton(L("换麦克风"), dark: true) { model.openSoundInputSettings() }
}
}
}
diff --git a/Sources/Cicada/Overlay.swift b/Sources/Cicada/Overlay.swift
index 31e042f..6618d4f 100644
--- a/Sources/Cicada/Overlay.swift
+++ b/Sources/Cicada/Overlay.swift
@@ -8,6 +8,8 @@ import AppKit
/// - Rest the pointer on it for 0.6 s to edit: outline + corner grip.
/// - Drag anywhere to move (snaps to the screen's centre line).
/// - Drag the bottom-right grip to scale; the font scales with the width.
+/// - The bottom-left button turns the microphone on or off (打开麦克风, the panel's switch): the
+/// bar has no notes window beside it. Only while editing, so the bar stays click-through.
/// - Double-click to return to the default spot.
/// - Position, width and size are remembered per display.
@MainActor
@@ -27,6 +29,13 @@ final class OverlayController {
var mode: () -> (auto: Bool, hideAfter: Double) = { (true, 4) }
/// Called when the bar tucks away after a quiet spell.
var onCollapsed: (() -> Void)?
+ /// The microphone button while editing.
+ var onMic: (() -> Void)?
+ func setMic(_ on: Bool) {
+ guard view.micOn != on else { return }
+ view.micOn = on
+ view.needsDisplay = true
+ }
private(set) var expanded = true
private(set) var manualHidden = false
private(set) var dimmed = false
@@ -467,6 +476,7 @@ final class OverlayView: NSView {
/// Translation lines the bar is sized for (1 or 2), so a short line leaves no gap.
var transLines = 1
var dragMode: Bool?
+ var micOn = false
private let orange = NSColor(srgbRed: 1.0, green: 0.71, blue: 0.62, alpha: 1)
private let accent = NSColor(srgbRed: 0.91, green: 0.33, blue: 0.17, alpha: 1)
@@ -500,6 +510,12 @@ final class OverlayView: NSView {
return NSRect(x: barRect.maxX - s + 6, y: barRect.minY - 6, width: s, height: s)
}
+ /// 打开麦克风 while editing: the grip's twin in the bottom-left corner.
+ private var micRect: NSRect {
+ let s: CGFloat = 26
+ return NSRect(x: barRect.minX - 6, y: barRect.minY - 6, width: s + 8, height: s)
+ }
+
// MARK: Drawing
override func draw(_ dirtyRect: NSRect) {
@@ -603,6 +619,17 @@ final class OverlayView: NSView {
p.move(to: NSPoint(x: g.midX + 1, y: g.minY + 7)); p.line(to: NSPoint(x: g.maxX - 7, y: g.midY - 1))
NSColor(calibratedWhite: 0.08, alpha: 1).setStroke()
p.stroke()
+
+ let m = micRect
+ (micOn ? NSColor(srgbRed: 0.99, green: 0.93, blue: 0.906, alpha: 1) : NSColor(calibratedWhite: 0.94, alpha: 1)).setFill()
+ NSBezierPath(roundedRect: m, xRadius: 8, yRadius: 8).fill()
+ let config = NSImage.SymbolConfiguration(pointSize: 13, weight: .semibold)
+ .applying(.init(paletteColors: [micOn ? accent : NSColor(calibratedWhite: 0.08, alpha: 1)]))
+ if let icon = NSImage(systemSymbolName: micOn ? "mic.fill" : "mic", accessibilityDescription: micOn ? L("关闭麦克风") : L("打开麦克风"))?
+ .withSymbolConfiguration(config) {
+ icon.draw(in: NSRect(x: m.midX - icon.size.width / 2, y: m.midY - icon.size.height / 2,
+ width: icon.size.width, height: icon.size.height))
+ }
}
}
@@ -639,6 +666,10 @@ final class OverlayView: NSView {
return
}
let p = convert(event.locationInWindow, from: nil)
+ if hover, micRect.insetBy(dx: -4, dy: -4).contains(p) {
+ controller?.onMic?()
+ return
+ }
dragMode = gripRect.insetBy(dx: -6, dy: -6).contains(p)
controller?.beginDrag()
(dragMode == true ? NSCursor.crosshair : NSCursor.closedHand).push()
@@ -660,6 +691,7 @@ final class OverlayView: NSView {
if hover {
addCursorRect(barRect, cursor: .openHand)
addCursorRect(gripRect, cursor: .crosshair)
+ addCursorRect(micRect, cursor: .pointingHand)
}
}
}
diff --git a/Sources/Cicada/RoomMic.swift b/Sources/Cicada/RoomMic.swift
index 298214e..f249183 100644
--- a/Sources/Cicada/RoomMic.swift
+++ b/Sources/Cicada/RoomMic.swift
@@ -72,42 +72,6 @@ struct VoiceGate {
}
}
-/// 在会议室里开会?: asked when listening to the Mac and it has played nothing for a minute. It
-/// only reads the system audio already being listened to, so the microphone stays closed.
-enum RoomPrompt {
- static let after = 60.0
-
- static func asks(room: Bool, listened: Double, voiced: Double) -> Bool {
- !room && listened >= after && voiced < 1
- }
-
- /// Shown in the panel: asked, not answered this meeting, and no meeting app in a call (early
- /// in a call nobody may have spoken yet; that silence is not a meeting in the room).
- static func shows(silent: Bool, answered: Bool, inCall: Bool) -> Bool {
- silent && !answered && !inCall
- }
-
- /// 线上也有人?: listening to the room alone while a meeting app on this Mac is in a call, so
- /// people online are likely speaking through it. Only where the Mac and the room can be heard
- /// together (not macOS 14/15), and once a meeting, like the question above. The call is the
- /// sign, not the Mac's audio: in 会议室 the Mac's audio isn't listened to at all.
- static func asksOnline(roomOnly: Bool, bothAvailable: Bool, answered: Bool, inCall: Bool) -> Bool {
- roomOnly && bothAvailable && !answered && inCall
- }
-}
-
-/// The grey line under 听哪里 while listening to the Mac and the room: how the room is being heard
-/// when that isn't the plain case. Echo cancellation off comes first: it changes what gets recorded.
-enum HybridNote {
- static func line(roomRunning: Bool, echoCancelled: Bool, headsetDefault: Bool) -> String? {
- guard roomRunning else { return nil }
- if !echoCancelled { return L("线上有人说话时,先不听会议室") }
- // A Bluetooth headset is the default input: the room is heard by the Mac's own mic (RoomMicPlan).
- if headsetDefault { return L("用 Mac 麦克风听会议室") }
- return nil
- }
-}
-
/// 外接麦克风断开了: the microphone hearing the room went away mid-meeting. Another takes over
/// (`RoomMicPlan` among what's left); with none left, 电脑和会议室 goes on with the Mac alone and
/// 会议室 pauses.
@@ -146,22 +110,124 @@ extension AudioDevices {
}
}
-/// 电脑和会议室 without echo cancellation: while the Mac plays speech, the room mic hears that speech
-/// again from the speakers. The main engine's audio queue `hold`s the gate on every loud block of the
-/// Mac's audio; the room mic hears silence until `hang` after the last one (the speakers' tail and the
-/// room's echo). Room speech over a remote speaker is lost this way: what `VoiceMic` is for.
+/// 打开麦克风 while the Mac plays a meeting: the room mic hears the remote voices again from the
+/// speakers. The room mic hears silence while the Mac plays speech, until `hang` after it (the
+/// speakers' tail and the room's echo), but only when that is needed and only for speech:
+///
+/// - Echo is measured, not assumed away: the room mic's level while the Mac is loud against its own
+/// floor while the Mac is quiet. Headphones, a meeting mic or a quiet speaker leave the mic 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 Mac's recognizer has found no words in for `music`
+/// seconds stops closing the gate, so people at the table are heard over hold music or a video.
+/// Words heard again close it again (a voice over music echoes too).
+///
+/// Measured with the MacBook's speakers and a speaker at the table (ESP32, 10 cm from the mic):
+/// echo cancellation (`VoiceMic`) let 0 echoes through but lost most table lines even with nobody
+/// online speaking, so this gate, with `EchoMatch` behind it, is the default.
final class EchoGate: @unchecked Sendable {
static let hang = 0.4
+ /// Seconds of loud Mac audio without a word before it counts as music.
+ static let music = 4.0
+ /// A pause this long ends a loud stretch.
+ static let stretchGap = 1.5
+ /// Mac audio this recent makes a room block "during the Mac"; this long ago, "the Mac is quiet".
+ static let during = 0.15
+ static let quietAfter = 1.0
+ /// Room level during the Mac over the room's floor: at or over `echoRatio` there is echo, under
+ /// `clearRatio` there is none (the gap between them keeps it from flapping).
+ static let echoRatio: Float = 3
+ static let clearRatio: Float = 2
+ /// Seconds of each that a decision needs, and how much is kept.
+ static let enough = 3.0
+ static let window = 20.0
+
private let lock = NSLock()
private var until: Double = 0
+ private var lastLoud: Double = -.infinity
+ private var stretchStart: Double = -.infinity
+ private var lastWords: Double = -.infinity
+ /// Room mic blocks (time, rms, seconds) while the Mac is loud, and while it is quiet.
+ private var during: [(t: Double, rms: Float, s: Double)] = []
+ private var quiet: [(t: Double, rms: Float, s: Double)] = []
+ private var _echo = true
+ /// Debug (`roomEchoSim:<on|off>`): pretend the measurement says this.
+ var forced: Bool?
+ /// A loud block of the Mac's audio, on the main engine's audio queue.
func hold(now: Double = CFAbsoluteTimeGetCurrent()) {
- lock.withLock { until = max(until, now + Self.hang) }
+ lock.withLock {
+ if now - lastLoud > Self.stretchGap { stretchStart = now }
+ lastLoud = now
+ guard !musicLocked(now), echoLocked else { return }
+ until = max(until, now + Self.hang)
+ }
+ }
+
+ /// The Mac's recognizer heard words (a draft or a line).
+ func heardWords(now: Double = CFAbsoluteTimeGetCurrent()) {
+ lock.withLock {
+ lastWords = now
+ // The words were said a moment ago: close from now, so their echo is caught.
+ if now - lastLoud < Self.hang, echoLocked { until = max(until, lastLoud + Self.hang) }
+ }
}
func closed(now: Double = CFAbsoluteTimeGetCurrent()) -> Bool {
lock.withLock { now < until }
}
+
+ /// Whether the speakers reach the room mic, as last measured.
+ var echo: Bool { lock.withLock { echoLocked } }
+ /// Whether the Mac is playing something loud that has no words in it.
+ func playingMusic(now: Double = CFAbsoluteTimeGetCurrent()) -> Bool { lock.withLock { musicLocked(now) } }
+
+ private var echoLocked: Bool { forced ?? _echo }
+
+ private func musicLocked(_ now: Double) -> Bool {
+ now - lastLoud <= Self.stretchGap && now - stretchStart >= Self.music && lastWords < now - Self.music
+ }
+
+ /// A block of what the room mic heard, before any silencing.
+ func roomLevel(_ rms: Float, seconds: Double, now: Double = CFAbsoluteTimeGetCurrent()) {
+ lock.withLock {
+ let since = now - lastLoud
+ // Music echoes like speech: it counts for the measurement.
+ if since <= Self.during { during.append((now, rms, seconds)) } else if since >= Self.quietAfter { quiet.append((now, rms, seconds)) } else { return }
+ during.removeAll { $0.t < now - Self.window }
+ quiet.removeAll { $0.t < now - Self.window * 3 }
+ if let ratio = Self.ratio(during: during.map { ($0.rms, $0.s) }, quiet: quiet.map { ($0.rms, $0.s) }) {
+ let was = _echo
+ if ratio >= Self.echoRatio { _echo = true } else if ratio < Self.clearRatio { _echo = false }
+ if was != _echo {
+ debugLog("room echo: \(_echo ? "speakers reach the mic" : "none") (×\(String(format: "%.1f", ratio)))")
+ if !_echo { until = 0 }
+ }
+ }
+ }
+ }
+
+ /// For `hybridState`: seconds of each kind of room block kept, their levels, and the ratio.
+ var summary: String {
+ lock.withLock {
+ let d = during.map(\.rms).sorted(), q = quiet.map(\.rms).sorted()
+ let mid = d.isEmpty ? 0 : d[d.count * 4 / 5], floor = q.isEmpty ? 0 : q[q.count / 5]
+ return String(format: "during=%.1fs p80=%.4f quiet=%.1fs floor=%.4f", during.reduce(0) { $0 + $1.s }, mid,
+ quiet.reduce(0) { $0 + $1.s }, floor)
+ }
+ }
+
+ /// The room mic's loud end (a fifth of it louder) while the Mac is loud over its floor (the
+ /// quietest fifth) while the Mac is quiet, or nil without `enough` of both. Not the middle: echo
+ /// from a laptop's speakers is only a little over the room's noise between the words, and
+ /// clearly over it on them. People at the table talking over the Mac raise it too: that errs on
+ /// the side of echo.
+ static func ratio(during: [(Float, Double)], quiet: [(Float, Double)]) -> Float? {
+ guard during.reduce(0, { $0 + $1.1 }) >= enough, quiet.reduce(0, { $0 + $1.1 }) >= enough else { return nil }
+ let d = during.map(\.0).sorted(), q = quiet.map(\.0).sorted()
+ let floor = max(q[q.count / 5], 0.0002)
+ return d[d.count * 4 / 5] / floor
+ }
}
/// A microphone as an audio source. While `muted`, silence goes on in its place: the Mac reading a
@@ -216,6 +282,8 @@ final class RoomMic: AudioSource {
func start() throws {
startedAt = Date()
+ silentSince = nil
+ silenceChecked = false
AudioDevices.pinInput(engine, to: device)
let input = engine.inputNode
// The hardware format: after pinning, the client format can still be the system mic's,
@@ -233,6 +301,14 @@ final class RoomMic: AudioSource {
out.frameLength = buf.frameLength
let n = Int(buf.frameLength)
let channels = Int(buf.format.channelCount)
+ if let src = buf.floatChannelData, channels > 0 {
+ if Self.simulateSilence { for c in 0..<channels { src[c].update(repeating: 0, count: n) } }
+ var sum: Float = 0
+ var sound = false
+ for i in 0..<n { let v = src[0][i]; sum += v * v; if v != 0 { sound = true } }
+ self.echoGate?.roomLevel((sum / Float(max(n, 1))).squareRoot(), seconds: Double(n) / format.sampleRate)
+ self.watchSilence(sound: sound)
+ }
if self.muted || self.echoGate?.closed() == true || channels == 0 || buf.floatChannelData == nil {
dst.update(repeating: 0, count: n)
} else if let src = buf.floatChannelData {
@@ -266,6 +342,41 @@ final class RoomMic: AudioSource {
}
}
+ // MARK: A microphone that delivers nothing
+
+ /// Seconds of nothing but digital zeros after a start that make the mic count as silent. A real
+ /// mic is never exactly zero, however quiet the room; a mic starved by another audio unit is.
+ static let silentAfter = 5.0
+ /// Debug (`roomMicSilent:on`): every block from the mic is zeros.
+ nonisolated(unsafe) static var simulateSilence = false
+ /// Called on the main queue when the mic stayed silent after being opened again.
+ var onSilent: (() -> Void)?
+ private var silentSince: Date?
+ private var silentRestarts = 0
+ private var silenceChecked = false
+
+ /// On the audio thread, per block: a mic silent since it started is opened again once, and
+ /// reported (`onSilent`) when it is still silent after that.
+ private func watchSilence(sound: Bool) {
+ guard !silenceChecked else { return }
+ if sound { silenceChecked = true; return }
+ let since = silentSince ?? Date()
+ silentSince = since
+ guard Date().timeIntervalSince(since) >= Self.silentAfter else { return }
+ silenceChecked = true
+ DispatchQueue.main.async { [weak self] in
+ guard let self, !self.stopped else { return }
+ if self.silentRestarts == 0 {
+ self.silentRestarts += 1
+ self.startedAt = .distantPast
+ self.restart("silent since it started")
+ } else {
+ debugLog("room mic: still silent after opening it again")
+ self.onSilent?()
+ }
+ }
+ }
+
private var stopped = false
func stop() {
diff --git a/Sources/Cicada/Views.swift b/Sources/Cicada/Views.swift
index efcbf38..bb8b901 100644
--- a/Sources/Cicada/Views.swift
+++ b/Sources/Cicada/Views.swift
@@ -220,8 +220,6 @@ struct MenuPanelView: View {
if let p = model.ending { MeetingEndingStrip(model: model, pending: p, compact: true) }
// In subtitle-bar mode this is where the bar sends you to pick.
if model.running { LanguageNotice(model: model) }
- if model.roomPrompt { roomPromptStrip }
- if let app = model.onlinePrompt { onlinePromptStrip(app) }
if model.hybridMicDenied { hybridMicStrip }
if let next = model.roomMicLost { roomMicLostStrip(next) }
AIServiceStrip(model: model, ling: model.ling)
@@ -229,16 +227,6 @@ struct MenuPanelView: View {
UpdateBanner(updates: model.updates, model: model)
VStack(spacing: 6) {
- ChoiceRow(label: L("听哪里"), value: settings.listensToRoom ? L("会议室") : settings.hearsBoth ? L("电脑和会议室") : L("电脑声音"),
- compact: true, options: [("system", L("电脑声音(线上会议、视频)")), ("room", L("会议室(用麦克风听桌边的人)"))]
- // Two recognizers at once: macOS 26 only (14/15's interrupt each other).
- + (Recognition.legacy ? [] : [("both", L("电脑和会议室(线上和桌边的人都听)"))])) {
- model.listenSourceSelection = $0
- }
- if let note = model.hybridNote {
- Text(note).font(.system(size: 11)).foregroundStyle(Palette.tertiary)
- .frame(maxWidth: .infinity, alignment: .leading).padding(.horizontal, 12)
- }
ChoiceRow(label: L("听到"), value: heardValue.0, badge: heardValue.1, compact: true, sections: sourceSections) {
model.sourceSelection = $0
}
@@ -251,6 +239,8 @@ struct MenuPanelView: View {
}
}
+ micRow
+
Divider()
speakSection
@@ -333,25 +323,6 @@ private struct PanelHeightKey: PreferenceKey {
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = max(value, nextValue()) }
}
-extension MenuPanelView {
- /// 在会议室里开会?: the Mac has played nothing for a minute. Asked once a meeting.
- var roomPromptStrip: some View {
- VStack(alignment: .leading, spacing: 10) {
- VStack(alignment: .leading, spacing: 2) {
- Text("在会议室里开会?").font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.ink)
- Text("电脑里 1 分钟没放出声音").font(.system(size: 11)).foregroundStyle(Palette.secondary)
- }
- HStack(spacing: 8) {
- SoftButton(L("改听会议室"), dark: true) { model.answerRoomPrompt(true) }
- SoftButton(L("不是")) { model.answerRoomPrompt(false) }
- Spacer(minLength: 0)
- }
- }
- .padding(12).frame(maxWidth: .infinity, alignment: .leading)
- .background(RoundedRectangle(cornerRadius: 11).fill(Palette.accentPale))
- }
-}
-
extension MenuPanelView {
/// 电脑和会议室 without the microphone: the Mac's side is still recorded.
var hybridMicStrip: some View {
@@ -380,25 +351,6 @@ extension MenuPanelView {
}
}
-extension MenuPanelView {
- /// 线上也有人?: listening to the room while a meeting app here is in a call. Asked once a meeting.
- func onlinePromptStrip(_ app: String) -> some View {
- VStack(alignment: .leading, spacing: 10) {
- VStack(alignment: .leading, spacing: 2) {
- Text("线上也有人?").font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.ink)
- Text(L("\(app) 正在通话")).font(.system(size: 11)).foregroundStyle(Palette.secondary)
- }
- HStack(spacing: 8) {
- SoftButton(L("也听电脑"), dark: true) { model.answerOnlinePrompt(true) }
- SoftButton(L("不用")) { model.answerOnlinePrompt(false) }
- Spacer(minLength: 0)
- }
- }
- .padding(12).frame(maxWidth: .infinity, alignment: .leading)
- .background(RoundedRectangle(cornerRadius: 11).fill(Palette.accentPale))
- }
-}
-
/// Under the panel's status: the file being transcribed in the background, if any.
struct PanelImportLine: View {
@ObservedObject var importer: FileImporter
@@ -475,6 +427,63 @@ extension MenuPanelView {
}
}
+// MARK: - 麦克风 in the panel
+
+extension MenuPanelView {
+ /// 打开麦克风: the people in the room join the meeting the Mac is hearing.
+ var micRow: some View {
+ HStack(spacing: 10) {
+ VStack(alignment: .leading, spacing: 2) {
+ Text("麦克风").font(.system(size: 14, weight: .semibold)).foregroundStyle(Palette.ink)
+ Text(model.micOn ? L("桌边的人说话也会记下") : L("关着 · 只听电脑声音"))
+ .font(.system(size: 12)).foregroundStyle(Palette.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ Spacer(minLength: 8)
+ MicButton(model: model, settings: settings, inHeader: false)
+ }
+ }
+}
+
+/// 打开麦克风 / 关闭麦克风, the same switch in the panel and the notes window. In the panel it is
+/// the dark button while off (the thing to do) and a quiet one while on; in the notes window's
+/// header it sits beside 结束 like it, tinted while the microphone is on.
+struct MicButton: View {
+ @ObservedObject var model: AppModel
+ @ObservedObject var settings: AppSettings
+ let inHeader: Bool
+
+ var body: some View {
+ let on = model.micOn
+ Button { model.setMic(!on) } label: {
+ HStack(spacing: 5) {
+ Image(systemName: on ? "mic.fill" : "mic")
+ .font(.system(size: 11, weight: .semibold))
+ .foregroundStyle(on ? Palette.accent : (inHeader ? Palette.ink : Color.white))
+ Text(on ? L("关闭麦克风") : L("打开麦克风")).font(.system(size: 12, weight: .semibold))
+ .foregroundStyle(!on && !inHeader ? Color.white : Palette.ink)
+ .lineLimit(1).fixedSize()
+ }
+ .padding(.horizontal, inHeader ? 10 : 12).frame(height: 28)
+ .background(RoundedRectangle(cornerRadius: 7).fill(background(on)))
+ .overlay(RoundedRectangle(cornerRadius: 7).stroke(border(on), lineWidth: 1))
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .accessibilityLabel(on ? L("关闭麦克风") : L("打开麦克风"))
+ }
+
+ private func background(_ on: Bool) -> Color {
+ if inHeader { return on ? Palette.accentPale : .clear }
+ return on ? Color.white : Palette.ink
+ }
+
+ private func border(_ on: Bool) -> Color {
+ if inHeader { return on ? Palette.accentPale : Palette.line }
+ return on ? Palette.line : Palette.ink
+ }
+}
+
// MARK: - 同声传译 in the panel
extension MenuPanelView {
diff --git a/Tests/CicadaTests/HybridRecordTests.swift b/Tests/CicadaTests/HybridRecordTests.swift
index 181ebd0..65eaecd 100644
--- a/Tests/CicadaTests/HybridRecordTests.swift
+++ b/Tests/CicadaTests/HybridRecordTests.swift
@@ -20,26 +20,10 @@ import Testing
#expect(RecordList.placeStarts(ls) == ["a", "c", "e", "f"])
}
- @Test func onlinePromptAsksOnlyInTheRoomDuringACall() {
- #expect(RoomPrompt.asksOnline(roomOnly: true, bothAvailable: true, answered: false, inCall: true))
- #expect(!RoomPrompt.asksOnline(roomOnly: true, bothAvailable: true, answered: false, inCall: false))
- #expect(!RoomPrompt.asksOnline(roomOnly: true, bothAvailable: true, answered: true, inCall: true))
- // macOS 14/15 can't hear both: don't offer it.
- #expect(!RoomPrompt.asksOnline(roomOnly: true, bothAvailable: false, answered: false, inCall: true))
- #expect(!RoomPrompt.asksOnline(roomOnly: false, bothAvailable: true, answered: false, inCall: true))
- }
-
@Test func anUnpluggedMicSaysWhatTookOver() {
#expect(RoomMicLoss.detail(next: "MacBook Pro Microphone", builtIn: true, both: true) == L("已改用 Mac 自带的麦克风"))
#expect(RoomMicLoss.detail(next: "Jabra Speak 510", builtIn: false, both: false) == L("已改用 Jabra Speak 510"))
#expect(RoomMicLoss.detail(next: nil, builtIn: false, both: true) == L("只听电脑了"))
#expect(RoomMicLoss.detail(next: nil, builtIn: false, both: false) == L("没有别的麦克风,已暂停"))
}
-
- @Test func noteSaysHowTheRoomIsHeard() {
- #expect(HybridNote.line(roomRunning: true, echoCancelled: true, headsetDefault: false) == nil)
- #expect(HybridNote.line(roomRunning: false, echoCancelled: false, headsetDefault: true) == nil)
- #expect(HybridNote.line(roomRunning: true, echoCancelled: false, headsetDefault: true) == L("线上有人说话时,先不听会议室"))
- #expect(HybridNote.line(roomRunning: true, echoCancelled: true, headsetDefault: true) == L("用 Mac 麦克风听会议室"))
- }
}
diff --git a/Tests/CicadaTests/HybridTests.swift b/Tests/CicadaTests/HybridTests.swift
index 98dbc75..234fcb7 100644
--- a/Tests/CicadaTests/HybridTests.swift
+++ b/Tests/CicadaTests/HybridTests.swift
@@ -40,6 +40,80 @@ import Testing
#expect(g.closed(now: 100.3))
#expect(!g.closed(now: 100 + EchoGate.hang + 0.01))
}
+
+ /// The Mac loud every 0.1 s from `from` to `to`, words every second when `words`, and the room
+ /// mic at `during` while it plays and at `quiet` for as long again afterwards.
+ private func play(_ g: EchoGate, from: Double, to: Double, words: Bool, during: Float, quiet: Float) {
+ var t = from
+ while t < to {
+ g.hold(now: t)
+ if words, Int(t * 10) % 10 == 0 { g.heardWords(now: t) }
+ g.roomLevel(during, seconds: 0.1, now: t + 0.05)
+ t += 0.1
+ }
+ let end = t
+ while t < end + (to - from) + 2 {
+ g.roomLevel(quiet, seconds: 0.1, now: t)
+ t += 0.1
+ }
+ }
+
+ @Test func musicStopsClosingTheGate() {
+ let g = EchoGate()
+ var t = 0.0
+ while t < 3 { g.hold(now: t); t += 0.1 }
+ // Three seconds without words: still taken for speech that hasn't been recognized yet.
+ g.hold(now: 3.0)
+ #expect(g.closed(now: 3.1))
+ // Five: music. The room is heard over it.
+ while t < 5 { g.hold(now: t); t += 0.1 }
+ g.hold(now: 5)
+ #expect(g.playingMusic(now: 5))
+ #expect(!g.closed(now: 5 + EchoGate.hang + 0.01))
+ // Someone starts talking over it: words close it again.
+ g.heardWords(now: 5.5)
+ g.hold(now: 5.6)
+ #expect(g.closed(now: 5.7))
+ }
+
+ @Test func speechKeepsTheGateClosedThroughALongSentence() {
+ let g = EchoGate()
+ var t = 0.0
+ while t < 10 { g.hold(now: t); if Int(t * 10) % 10 == 0 { g.heardWords(now: t) }; t += 0.1 }
+ #expect(!g.playingMusic(now: 10))
+ #expect(g.closed(now: 10))
+ }
+
+ @Test func noEchoMeasuredOpensTheGate() {
+ let g = EchoGate()
+ #expect(g.echo)
+ // Headphones: the room mic stays at its floor while the Mac speaks.
+ play(g, from: 0, to: 6, words: true, during: 0.001, quiet: 0.001)
+ #expect(!g.echo)
+ g.hold(now: 20)
+ #expect(!g.closed(now: 20.1))
+ }
+
+ @Test func speakersReachingTheMicKeepTheGate() {
+ let g = EchoGate()
+ play(g, from: 0, to: 6, words: true, during: 0.03, quiet: 0.001)
+ #expect(g.echo)
+ g.hold(now: 20)
+ #expect(g.closed(now: 20.1))
+ }
+
+ @Test func echoComesBackWhenTheHeadphonesComeOff() {
+ let g = EchoGate()
+ play(g, from: 0, to: 6, words: true, during: 0.001, quiet: 0.001)
+ #expect(!g.echo)
+ play(g, from: 20, to: 45, words: true, during: 0.03, quiet: 0.001)
+ #expect(g.echo)
+ }
+
+ @Test func notEnoughToTellKeepsTheEcho() {
+ #expect(EchoGate.ratio(during: [(0.001, 1)], quiet: [(0.001, 10)]) == nil)
+ #expect(EchoGate.ratio(during: [(0.001, 5)], quiet: [(0.001, 1)]) == nil)
+ }
}
@Suite struct VoiceGateBlockTests {
diff --git a/Tests/CicadaTests/RoomTests.swift b/Tests/CicadaTests/RoomTests.swift
index 494115f..b3d4f3e 100644
--- a/Tests/CicadaTests/RoomTests.swift
+++ b/Tests/CicadaTests/RoomTests.swift
@@ -25,22 +25,6 @@ import Testing
#expect(RoomMicPlan.pick(defaultUID: "blackhole", inputs: [blackhole, airpods]) == "airpods")
#expect(RoomMicPlan.pick(defaultUID: nil, inputs: [blackhole]) == nil)
}
-
- @Test func asksAboutTheRoomAfterAQuietMinute() {
- #expect(!RoomPrompt.asks(room: false, listened: 30, voiced: 0))
- #expect(RoomPrompt.asks(room: false, listened: 61, voiced: 0))
- // Something played: it is an online meeting after all.
- #expect(!RoomPrompt.asks(room: false, listened: 300, voiced: 5))
- // Already listening to the room.
- #expect(!RoomPrompt.asks(room: true, listened: 300, voiced: 0))
- }
-
- @Test func notDuringACallOrOnceAnswered() {
- #expect(RoomPrompt.shows(silent: true, answered: false, inCall: false))
- #expect(!RoomPrompt.shows(silent: true, answered: true, inCall: false))
- #expect(!RoomPrompt.shows(silent: true, answered: false, inCall: true))
- #expect(!RoomPrompt.shows(silent: false, answered: false, inCall: false))
- }
}
@Suite struct VoiceGateTests {