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.

fix(windows): Preview says why no sound played, and a Windows voice the PC doesn't have is no longer picked

wquguru3c8c9fd64ad1
diff --git a/site/changelog.json b/site/changelog.json
index 538d43b..5d64720 100644
--- a/site/changelog.json
+++ b/site/changelog.json
@@ -13,6 +13,14 @@
],
"title": "“打开麦克风”旁边可以选用哪个麦克风。",
"text": "以前听会议室只能用系统默认的麦克风,想用 iPhone、会议麦就得去系统设置里改。现在点实时纪要或菜单栏里“打开麦克风”旁边的小箭头就能选,开着麦也能换,会议不中断;选蓝牙耳机会注明只听得到戴的人。选的麦克风拔掉时先用“自动”,下次打开麦克风时它在就还用它。"
+ },
+ {
+ "kind": "fixed",
+ "platforms": [
+ "windows"
+ ],
+ "title": "“试听”放不出声音时会说明原因。",
+ "text": "以前选了“Windows 自带”的声音,而这台电脑没有那种语言的语音(中文 Windows 常常只有中文语音),声音一栏是空的,点“试听”也没反应。现在这种情况会改用 AI 服务的声音;真的放不出来时,“试听”下面会说是没有这个语言的语音(附“打开语音设置”)、找不到扬声器,还是 AI 服务的声音没连上。试听时按钮变成“停止”。"
}
]
},
diff --git a/windows/src/Cicada.Core/Speak.cs b/windows/src/Cicada.Core/Speak.cs
index 3aec24b..d90e6a8 100644
--- a/windows/src/Cicada.Core/Speak.cs
+++ b/windows/src/Cicada.Core/Speak.cs
@@ -54,14 +54,16 @@ public static class VoiceCatalog
public static IReadOnlyList<VoiceOption> Options(string language, AIConfig config, bool windowsHasIt = true) =>
windowsHasIt ? [.. Cloud(language, config), new(SystemId, "Windows", "本机")] : Cloud(language, config);
- /// What a language uses until the user picks: the service's first voice once it can speak,
- /// else Windows'.
- public static string DefaultId(string language, AIConfig config, bool speaks) => speaks && Cloud(language, config) is [var first, ..] ? first.Id : SystemId;
+ /// What a language uses until the user picks: the service's first voice once it can speak (or
+ /// when Windows has none for the language), else Windows'.
+ public static string DefaultId(string language, AIConfig config, bool speaks, bool windowsHasIt = true) =>
+ (speaks || !windowsHasIt) && Cloud(language, config) is [var first, ..] ? first.Id : SystemId;
- /// The voice chosen for a language, if this service still offers it: a Ming voice saved
- /// before switching to ZenMux is not sent there.
- public static string Chosen(AppSettings settings, string language, AIConfig config, bool speaks) =>
- settings.SpeakVoices.TryGetValue(Key(language), out var id) && Options(language, config).Any(v => v.Id == id) ? id : DefaultId(language, config, speaks);
+ /// The voice chosen for a language, if it is still offered: a Ming voice saved before switching
+ /// to ZenMux is not sent there, and "system" saved where Windows has no voice for the language
+ /// (Chinese Windows often has only Chinese ones) left the voice blank and 试听 silent (#22).
+ public static string Chosen(AppSettings settings, string language, AIConfig config, bool speaks, bool windowsHasIt = true) =>
+ settings.SpeakVoices.TryGetValue(Key(language), out var id) && Options(language, config, windowsHasIt).Any(v => v.Id == id) ? id : DefaultId(language, config, speaks, windowsHasIt);
/// A short line to try a voice with, in the language it will speak.
public static string Sample(string language) => Key(language) switch
@@ -231,7 +233,7 @@ public sealed class SpeakEngine
public async Task<bool> Voice(string text, string language, ISpeechSink sink)
{
var config = ling.Config;
- var id = VoiceCatalog.Chosen(settings, language, config, ling.Speaks);
+ var id = VoiceCatalog.Chosen(settings, language, config, ling.Speaks, systemVoice.Has(language));
var prefix = config.IsLing ? VoiceCatalog.MingPrefix : VoiceCatalog.CloudPrefix;
if (id.StartsWith(prefix) && ling.Speaks)
{
diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.cs
index 3b6008f..7fd6004 100644
--- a/windows/src/Cicada/App.cs
+++ b/windows/src/Cicada/App.cs
@@ -795,8 +795,40 @@ sealed class Controller
_ = Speak.Speak(Wav.Bytes(pcm), new DeviceSpeaker(Endpoints.Cable));
}
- /// 试听: a voice speaks its sample line on the speakers (not into the meeting).
- public Task Preview(string language) => Speak.Voice(VoiceCatalog.Sample(language), language, new DeviceSpeaker(() => Endpoints.Default(Endpoints.Flow.Render)));
+ public enum PreviewResult { Played, Stopped, NoSpeaker, NoVoice, FellBack, Failed }
+ DeviceSpeaker? previewing;
+ public bool Previewing => previewing is not null;
+ public void StopPreview() => previewing?.Stop();
+
+ /// 试听: a voice speaks its sample line on the speakers (not into the meeting). It used to fail
+ /// without a word (#22); now the result says why, for the line under the voice.
+ public async Task<PreviewResult> Preview(string language)
+ {
+ previewing?.Stop();
+ var speaker = new DeviceSpeaker(() => Endpoints.Default(Endpoints.Flow.Render));
+ PreviewResult result;
+ if (!speaker.Ready) result = PreviewResult.NoSpeaker;
+ else
+ {
+ previewing = speaker;
+ Changed();
+ try
+ {
+ var chosen = VoiceCatalog.Chosen(Settings, language, Ling.Config, Ling.Speaks, WindowsVoice.Has(language));
+ var voiced = await Speak.Voice(VoiceCatalog.Sample(language), language, speaker);
+ result = speaker.Stopped ? PreviewResult.Stopped
+ : !voiced ? (WindowsVoice.Has(language) ? PreviewResult.Failed : PreviewResult.NoVoice)
+ : speaker.Failed ? PreviewResult.NoSpeaker
+ : chosen != VoiceCatalog.SystemId && Speak.LastVoice == "system" ? PreviewResult.FellBack
+ : PreviewResult.Played;
+ }
+ catch (Exception e) { Log.Debug($"preview: failed {e.GetType().Name}"); result = PreviewResult.Failed; }
+ finally { if (previewing == speaker) previewing = null; }
+ }
+ Log.Debug($"preview: {language} {result}");
+ Changed();
+ return result;
+ }
// MARK: Windows
@@ -900,6 +932,8 @@ sealed class Controller
}
public void SettingsPage(string id) => settingsWindow?.Show(id);
+ /// The open settings window, for the debug pipe's preview.
+ public SettingsWindow? OpenSettings => settingsWindow;
/// Debug: 改这句… on a record's line; 词表 › 粘贴导入 with `text` pasted in.
public void DebugEditLine(string id, string line) { ShowRecords(id); mainWindow?.DebugEdit(id, line); }
public void DebugPaste(string text) { ShowSettings(); SettingsPage("words"); settingsWindow?.DebugImport(text); }
@@ -1337,7 +1371,11 @@ static class DebugServer
var p = arg.Split('|');
return new JsonObject { ["ok"] = app.Store.Audio?.Rewrap(p[0], p[1], p.Length > 2 ? double.Parse(p[2], System.Globalization.CultureInfo.InvariantCulture) : null) ?? false };
}
- case "preview": _ = app.Preview(arg.Length > 0 ? arg : app.Speak.Target); break;
+ // preview: 试听 in the open settings (its result line shows there), else on its own.
+ case "preview":
+ if (arg.Length == 0 && app.OpenSettings is { } sw) _ = sw.RunPreview();
+ else _ = app.Preview(arg.Length > 0 ? arg : app.Speak.Target);
+ break;
case "calls":
app.FakeCalls = arg switch { "real" => null, "" or "none" => [], _ => arg.Split(',').Select(p => p.Split('=', 2)).ToDictionary(p => p[0], p => p[^1]) };
break;
diff --git a/windows/src/Cicada/SettingsWindow.cs b/windows/src/Cicada/SettingsWindow.cs
index 3d31f65..b4060be 100644
--- a/windows/src/Cicada/SettingsWindow.cs
+++ b/windows/src/Cicada/SettingsWindow.cs
@@ -261,10 +261,13 @@ sealed partial class SettingsWindow : Window
var config = app.Ling.Config;
var voices = VoiceCatalog.Options(target, config, app.WindowsVoice.Has(target))
.Select(v => (v.Id, v.Id == VoiceCatalog.SystemId ? L("Windows 自带") : v.Tags.Length == 0 ? v.Name : $"{v.Name} · {string.Join(" · ", v.Tags.Split(" · ").Select(L))}")).ToList();
- var chosen = VoiceCatalog.Chosen(s, target, config, app.Ling.Speaks);
+ var chosen = VoiceCatalog.Chosen(s, target, config, app.Ling.Speaks, app.WindowsVoice.Has(target));
var voice = Ui.Row(8,
- Ui.Choice(voices, chosen, v => { s.SpeakVoices[VoiceCatalog.Key(target)] = v; Save(); }, 280),
- Ui.Button(L("试听"), () => _ = app.Preview(target), height: 32));
+ Ui.Choice(voices, chosen, v => { s.SpeakVoices[VoiceCatalog.Key(target)] = v; previewNote = null; Save(); Render(); }, 280),
+ Ui.Button(app.Previewing ? L("停止") : L("试听"), () => { if (app.Previewing) app.StopPreview(); else _ = RunPreview(); }, height: 32));
+ // No voice at all for the language (Windows has none, the service speaks none): say so before
+ // 试听 is pressed, as it would after.
+ var note = previewNote ?? (voices.Count == 0 ? PreviewNote(Controller.PreviewResult.NoVoice, target) : null);
var mine = Languages.Sources.FirstOrDefault(x => x.Code == Languages.FromSystem(System.Globalization.CultureInfo.CurrentUICulture.Name))?.Name ?? "";
yield return Label(L("说话"));
yield return Group(
@@ -272,12 +275,52 @@ sealed partial class SettingsWindow : Window
Card(null, L("我说的语言"), null, Ui.Choice([("system", LF("跟随系统(%@)", mine)), .. Languages.Sources.Select(x => (x.Code, x.Name))], s.SpeakFrom, v => { s.SpeakFrom = v; Save(); Render(); })),
Card(null, L("线上的人听到的语言"), s.SpeakTo == "room" ? LF("现在是 %@", Ui.TargetName(target)) : null,
Ui.Choice([("room", L("对方说的语言")), .. Languages.Targets.Select(t => (t.Code, t.Name))], s.SpeakTo, v => { s.SpeakTo = v; Save(); Render(); })),
- Card(null, LF("线上的人听到的声音(%@)", Ui.TargetName(target)), null, voice));
+ note 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));
}
+ // 试听's result, shown under the voice until another voice is picked or 试听 is pressed again.
+ (string Title, string Help, bool VoiceSettings)? previewNote;
+
+ public async Task RunPreview()
+ {
+ var target = app.Speak.Target;
+ previewNote = null;
+ var playing = app.Preview(target);
+ Render();
+ var result = await playing;
+ previewNote = PreviewNote(result, target);
+ Render();
+ }
+
+ (string Title, string Help, bool VoiceSettings)? PreviewNote(Controller.PreviewResult result, string target) => result switch
+ {
+ Controller.PreviewResult.NoVoice => (LF("这台电脑没有%@的声音,没放出来。", Ui.TargetName(target)), L("在 Windows 设置里添加这个语言的语音,或者换一个 AI 服务的声音。"), true),
+ Controller.PreviewResult.NoSpeaker => (L("没放出声音:找不到扬声器。"), L("看看耳机或扬声器有没有连上。"), false),
+ Controller.PreviewResult.FellBack => (LF("%@ 的声音没连上,刚才放的是 Windows 自带的。", app.Ling.Config.Name), L("开会时也会这样换过去,不会不出声。"), false),
+ Controller.PreviewResult.Failed => (L("没放出声音。"), L("再试一次,还不行就换一个声音。"), false),
+ _ => null,
+ };
+
+ static FrameworkElement PreviewNoteBox((string Title, string Help, bool VoiceSettings) note)
+ {
+ // One wrapping line with the link inline: English runs wider than the card.
+ var help = Ui.Helper(note.Help);
+ help.TextWrapping = TextWrapping.Wrap;
+ if (note.VoiceSettings)
+ {
+ var link = new System.Windows.Documents.Hyperlink(new System.Windows.Documents.Run(L("打开语音设置"))) { Foreground = Palette.AccentText, TextDecorations = null, Cursor = System.Windows.Input.Cursors.Hand };
+ link.Click += (_, _) => { try { Process.Start(new ProcessStartInfo("ms-settings:speech") { UseShellExecute = true }); } catch { } };
+ help.Inlines.Add(new System.Windows.Documents.Run(" "));
+ help.Inlines.Add(link);
+ }
+ var text = Ui.Stack(3, Ui.Text(note.Title, 13, Palette.Ink), help);
+ return new Border { Background = Palette.Mica, CornerRadius = new CornerRadius(8), Padding = new Thickness(12, 9, 12, 10), Margin = new Thickness(0, 0, 0, 12), Child = text };
+ }
+
async Task InstallCable()
{
cableProgress = L("正在下载…"); Render();
diff --git a/windows/src/Cicada/Strings/en.lproj/Windows.strings b/windows/src/Cicada/Strings/en.lproj/Windows.strings
index b8cd754..fd1add6 100644
--- a/windows/src/Cicada/Strings/en.lproj/Windows.strings
+++ b/windows/src/Cicada/Strings/en.lproj/Windows.strings
@@ -325,3 +325,15 @@
/* 改正听错的词: Ming translates with the audio, so fixing is a request of its own; the list is on this PC. */
"每句话说完多发一次文字请求" = "One more text request per finished sentence";
"最多 %lld 个,满了优先用最近的。只存在这台电脑上" = "Up to %lld, recent ones first. Stored only on this PC";
+
+/* 试听's result under the voice (#22: it used to fail silently). */
+"停止" = "Stop";
+"这台电脑没有%@的声音,没放出来。" = "This PC has no %@ voice, so nothing played.";
+"在 Windows 设置里添加这个语言的语音,或者换一个 AI 服务的声音。" = "Add a voice for this language in Windows Settings, or pick an AI service voice.";
+"打开语音设置" = "Open speech settings";
+"没放出声音:找不到扬声器。" = "Nothing played: no speakers found.";
+"看看耳机或扬声器有没有连上。" = "Check that headphones or speakers are connected.";
+"%@ 的声音没连上,刚才放的是 Windows 自带的。" = "Couldn't reach the %@ voice, so that was the Windows voice.";
+"开会时也会这样换过去,不会不出声。" = "Meetings fall back the same way, so you're never silent.";
+"没放出声音。" = "Nothing played.";
+"再试一次,还不行就换一个声音。" = "Try again, or pick another voice.";
diff --git a/windows/src/Cicada/Strings/ja.lproj/Windows.strings b/windows/src/Cicada/Strings/ja.lproj/Windows.strings
index 9c3310f..f966c10 100644
--- a/windows/src/Cicada/Strings/ja.lproj/Windows.strings
+++ b/windows/src/Cicada/Strings/ja.lproj/Windows.strings
@@ -325,3 +325,15 @@
/* 改正听错的词: Ming translates with the audio, so fixing is a request of its own; the list is on this PC. */
"每句话说完多发一次文字请求" = "文ごとにテキストのリクエストが 1 回増えます";
"最多 %lld 个,满了优先用最近的。只存在这台电脑上" = "最大 %lld 個、最近使ったものを優先。この PC にだけ保存";
+
+/* 试听's result under the voice (#22: it used to fail silently). */
+"停止" = "停止";
+"这台电脑没有%@的声音,没放出来。" = "この PC には%@の音声がないため、再生されませんでした。";
+"在 Windows 设置里添加这个语言的语音,或者换一个 AI 服务的声音。" = "Windows の設定でこの言語の音声を追加するか、AI サービスの音声を選んでください。";
+"打开语音设置" = "音声の設定を開く";
+"没放出声音:找不到扬声器。" = "再生されませんでした:スピーカーが見つかりません。";
+"看看耳机或扬声器有没有连上。" = "ヘッドホンやスピーカーが接続されているか確認してください。";
+"%@ 的声音没连上,刚才放的是 Windows 自带的。" = "%@ の音声につながらなかったため、Windows の音声で再生しました。";
+"开会时也会这样换过去,不会不出声。" = "会議中も同じように切り替わるので、無音にはなりません。";
+"没放出声音。" = "再生されませんでした。";
+"再试一次,还不行就换一个声音。" = "もう一度試すか、別の音声を選んでください。";
diff --git a/windows/src/Cicada/Strings/ko.lproj/Windows.strings b/windows/src/Cicada/Strings/ko.lproj/Windows.strings
index cbdbee3..28822dc 100644
--- a/windows/src/Cicada/Strings/ko.lproj/Windows.strings
+++ b/windows/src/Cicada/Strings/ko.lproj/Windows.strings
@@ -325,3 +325,15 @@
/* 改正听错的词: Ming translates with the audio, so fixing is a request of its own; the list is on this PC. */
"每句话说完多发一次文字请求" = "문장마다 텍스트 요청이 한 번 더 갑니다";
"最多 %lld 个,满了优先用最近的。只存在这台电脑上" = "최대 %lld개, 최근 것을 우선. 이 PC에만 저장";
+
+/* 试听's result under the voice (#22: it used to fail silently). */
+"停止" = "중지";
+"这台电脑没有%@的声音,没放出来。" = "이 PC에 %@ 음성이 없어 재생되지 않았습니다.";
+"在 Windows 设置里添加这个语言的语音,或者换一个 AI 服务的声音。" = "Windows 설정에서 이 언어의 음성을 추가하거나 AI 서비스 음성을 고르세요.";
+"打开语音设置" = "음성 설정 열기";
+"没放出声音:找不到扬声器。" = "재생되지 않았습니다: 스피커를 찾을 수 없습니다.";
+"看看耳机或扬声器有没有连上。" = "헤드폰이나 스피커가 연결되어 있는지 확인하세요.";
+"%@ 的声音没连上,刚才放的是 Windows 自带的。" = "%@ 음성에 연결되지 않아 Windows 음성으로 재생했습니다.";
+"开会时也会这样换过去,不会不出声。" = "회의 중에도 같은 방식으로 바뀌어 소리가 끊기지 않습니다.";
+"没放出声音。" = "재생되지 않았습니다.";
+"再试一次,还不行就换一个声音。" = "다시 시도하거나 다른 음성을 고르세요.";
diff --git a/windows/src/Cicada/Wasapi.cs b/windows/src/Cicada/Wasapi.cs
index 66a61eb..ed482d0 100644
--- a/windows/src/Cicada/Wasapi.cs
+++ b/windows/src/Cicada/Wasapi.cs
@@ -262,30 +262,41 @@ sealed class DeviceSpeaker : ISpeechSink
readonly Func<Endpoints.Device?> device;
readonly Queue<byte[]> queue = new();
Thread? thread;
- volatile bool ending;
+ volatile bool ending, stopped;
TaskCompletionSource? done;
int rate;
public string? DeviceName { get; private set; }
+ /// The device was there but wouldn't play (or vanished): nothing, or not all, was heard.
+ public bool Failed { get; private set; }
+ public bool Stopped => stopped;
public DeviceSpeaker(Func<Endpoints.Device?> device) { this.device = device; }
public bool Ready => device() is not null;
+ /// 试听's 停止: what is queued is dropped and End returns; later chunks are ignored.
+ public void Stop()
+ {
+ stopped = true; ending = true;
+ lock (queue) queue.Clear();
+ }
+
public void Begin(int rate)
{
this.rate = rate;
- ending = false;
+ ending = stopped;
lock (queue) queue.Clear();
done = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
+ if (stopped) { done.TrySetResult(); return; }
var d = device();
DeviceName = d?.Name;
- if (d is null) { Log.Debug("speaker: no device"); done.TrySetResult(); return; }
+ if (d is null) { Log.Debug("speaker: no device"); Failed = true; done.TrySetResult(); return; }
thread = new Thread(() => Run(d.Id)) { IsBackground = true, Name = "DeviceSpeaker" };
thread.SetApartmentState(ApartmentState.MTA);
thread.Start();
}
- public void Write(byte[] pcm) { lock (queue) queue.Enqueue(pcm); }
+ public void Write(byte[] pcm) { if (!stopped) lock (queue) queue.Enqueue(pcm); }
public Task End() { ending = true; return done?.Task ?? Task.CompletedTask; }
@@ -306,7 +317,7 @@ sealed class DeviceSpeaker : ISpeechSink
byte[] pending = [];
int offset = 0;
bool started = false;
- while (true)
+ while (!stopped)
{
client.GetCurrentPadding(out var padding);
var room = (int)(size - padding);
@@ -333,7 +344,7 @@ sealed class DeviceSpeaker : ISpeechSink
}
client.Stop();
}
- catch (Exception e) { Log.Debug($"speaker: failed 0x{e.HResult:X8}"); }
+ catch (Exception e) { Log.Debug($"speaker: failed 0x{e.HResult:X8}"); Failed = true; }
finally
{
if (client is not null) Marshal.ReleaseComObject(client);
diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.cs
index 9365ca6..9c2678d 100644
--- a/windows/tests/Cicada.Tests/Program.cs
+++ b/windows/tests/Cicada.Tests/Program.cs
@@ -2685,6 +2685,12 @@ static class Tests
var settings = new AppSettings { SpeakVoices = { ["en"] = "ming:US_Emma" } };
Equal("cloud:Kore", VoiceCatalog.Chosen(settings, "en", zen, true), "a Ming voice isn't sent to ZenMux");
Equal("ming:US_Emma", VoiceCatalog.Chosen(settings, "en", new AppSettings().AIConfig(), true), "and is used again on Ling");
+ // #22: Windows' voice saved for a language this PC has no voice for.
+ var system = new AppSettings { SpeakVoices = { ["en"] = "system" } };
+ var ling = new AppSettings().AIConfig();
+ Equal("system", VoiceCatalog.Chosen(system, "en", ling, true, windowsHasIt: true), "kept where Windows has it");
+ Equal("ming:US_Emma", VoiceCatalog.Chosen(system, "en", ling, true, windowsHasIt: false), "the service's voice where it doesn't");
+ Equal("ming:US_Emma", VoiceCatalog.Chosen(system, "en", ling, false, windowsHasIt: false), "even before the service is checked");
}
public static async Task HearingGoesToTheChosenHearModel()
@@ -3414,4 +3420,5 @@ static class Tests
Equal(null, client.Store.Read(s.Id), "forgotten after revoke");
Equal(2, server.Seen.Count(x => x == "POST /api/v1/devices"), "the device file is reused");
}
+
}