知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
feat(windows): with your own AI service, meeting audio and text can stay off Google Translate
wquguru6e90cdf00ad9
diff --git a/windows/scripts/cicadactl.ps1 b/windows/scripts/cicadactl.ps1index 17a8748..6459a32 100644--- a/windows/scripts/cicadactl.ps1+++ b/windows/scripts/cicadactl.ps1@@ -1,6 +1,6 @@# Sends one debug command to a running dev build (Cicada.exe --dev) and prints its JSON state.# .\cicadactl.ps1 state | start | stop | end | notesproblem failed | sample | feed C:\clip.wav | view subtitles | capture on | show records | hide notes | quit-# AI 服务: provider ling|openrouter|zenmux|custom | switchtoling (a status line's 改用 Ling) | ai-model hear|text|voice <id> | show settings ai models+# AI 服务: provider ling|openrouter|zenmux|custom | switchtoling (a status line's 改用 Ling) | ai-model hear|text|voice <id> | ai-custom-only on|off | show settings ai models# AI 服务检查: ai-check | ai-check-sim <unreachable|invalidKey|noCredit|mgmtKey|noModel|noJSON|deaf|busy|serverError|lowBalance|off> (state › ai.check: every step)# 结束会议: calls zoom.exe=Zoom|none|real | realcalls | endtimes <silence> <countdown> <grace>|off | endkeepparam([Parameter(ValueFromRemainingArguments = $true)][string[]]$Command)diff --git a/windows/src/Cicada.Cli/Program.cs b/windows/src/Cicada.Cli/Program.csindex 5d1eb23..2be5b15 100644--- a/windows/src/Cicada.Cli/Program.cs+++ b/windows/src/Cicada.Cli/Program.cs@@ -103,10 +103,10 @@ switch (args_[0])Console.WriteLine($"{provider}: hear {ling.Config.HearModel}, text {ling.Config.TextModel}");var store = new SessionStore();var notes = new NotesEngine(ling, store);- var engine = new ListenEngine(ling, new Translator(ling), store, notes, settings);+ var engine = new ListenEngine(ling, new Translator(ling) { GoogleOff = settings.GoogleOff }, store, notes, settings);var roomFile = Opt("--room", "");var roomOnly = args_.Contains("--room-only");- var roomEngine = roomFile.Length > 0 && !roomOnly ? new ListenEngine(ling, new Translator(ling), store, notes, settings, roomSide: true) : null;+ var roomEngine = roomFile.Length > 0 && !roomOnly ? new ListenEngine(ling, new Translator(ling) { GoogleOff = settings.GoogleOff }, store, notes, settings, roomSide: true) : null;var printed = new HashSet<string>();var shown = new Dictionary<string, string>();diff --git a/windows/src/Cicada.Core/AICheck.cs b/windows/src/Cicada.Core/AICheck.csindex 5d4b216..cc46d22 100644--- a/windows/src/Cicada.Core/AICheck.cs+++ b/windows/src/Cicada.Core/AICheck.cs@@ -261,10 +261,14 @@ public sealed class AICheck/// Why translations are slow, and what to do (a custom service). The Mac's words: the/// translation timeout is the same 6 s here.- public string? SlowLine()+ public string? SlowLine(bool googleOff = false){if (!Slow || Translate is not { } t) return null;var secs = t.Seconds.ToString("0.0", System.Globalization.CultureInfo.InvariantCulture);+ // 语音和文字只发给你的服务: a sentence that takes too long isn't handed to Google.+ if (googleOff)+ return t.Thinks ? Strings.LF("这个模型先思考再回答,翻一句要 %@ 秒,超过 6 秒这句就不等它了。在服务端关掉思考,或换一个不思考的模型。", secs)+ : Strings.LF("翻一句要 %@ 秒,超过 6 秒这句就不等它了。换一个更小的模型会快一些。", secs);return t.Thinks ? Strings.LF("这个模型先思考再回答,翻一句要 %@ 秒,超过 6 秒会改用 Google。在服务端关掉思考,或换一个不思考的模型。", secs): Strings.LF("翻一句要 %@ 秒,超过 6 秒会改用 Google。换一个更小的模型会快一些。", secs);}diff --git a/windows/src/Cicada.Core/Settings.cs b/windows/src/Cicada.Core/Settings.csindex 06b979d..1d07a48 100644--- a/windows/src/Cicada.Core/Settings.cs+++ b/windows/src/Cicada.Core/Settings.cs@@ -23,6 +23,10 @@ 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): with the custom service, Google Translate is never+ /// asked. Kept when another service is picked, but only acts on the custom one (GoogleOff).+ [JsonPropertyName("aiCustomOnly")] public bool AiCustomOnly { get; set; }+ [JsonIgnore] public bool GoogleOff => AiProvider == "custom" && AiCustomOnly;/// 打开麦克风: "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;diff --git a/windows/src/Cicada.Core/Translator.cs b/windows/src/Cicada.Core/Translator.csindex 2cdb23f..86ae3a1 100644--- a/windows/src/Cicada.Core/Translator.cs+++ b/windows/src/Cicada.Core/Translator.cs@@ -16,6 +16,37 @@ public sealed class Translator(LingClient ling, HttpMessageHandler? google = nul// Tests hand in their own handler, so they never reach the real Google.readonly HttpClient Http = google is null ? Shared : MakeHttp(google);DateTime googleBackoffUntil = DateTime.MinValue;+ bool googleOff, sentencesUntranslated;++ /// Set by the app (语音和文字只发给你的服务, custom service only): Google is never asked, so the+ /// text stays with the user's service. A stale Google backoff goes with it either way.+ public bool GoogleOff+ {+ get => googleOff;+ set+ {+ if (value == googleOff) return;+ googleOff = value;+ googleBackoffUntil = DateTime.MinValue;+ sentencesUntranslated = false;+ Changed?.Invoke();+ }+ }++ /// With Google left out, the last finished sentence went untranslated (the service failed): the+ /// notes window says new lines show the original until it answers again.+ public bool SentencesUntranslated+ {+ get => sentencesUntranslated;+ private set+ {+ if (value == sentencesUntranslated) return;+ sentencesUntranslated = value;+ Changed?.Invoke();+ }+ }++ public event Action? Changed;/// Names and terms the notes have settled on, e.g. "江充 (…; misheard as 江松)".public Func<IReadOnlyList<string>> Glossary { get; set; } = () => [];@@ -179,10 +210,12 @@ public sealed class Translator(LingClient ling, HttpMessageHandler? google = nulreturn now - last >= TimeSpan.TicksPerSecond * 15 && Interlocked.CompareExchange(ref lastUnreachableTry, now, last) == last;}- /// The AI service (finished sentences only) → Google. Null when both fail.+ /// The AI service (finished sentences only) → Google. Null when both fail. With GoogleOff the+ /// service alone: drafts get nothing (they never go to the service) and show the original.public async Task<string?> Translate(string text, string source, string target, Kind kind, Priority priority = Priority.Translate){if (source == target) return text;+ if (kind == Kind.Draft && GoogleOff) return null;if (kind != Kind.Draft && ling.Usable && LingWorthTrying()){try@@ -194,10 +227,20 @@ public sealed class Translator(LingClient ling, HttpMessageHandler? google = nulif (names.Count > 0) prompt += "\nKnown names and terms (use these spellings): " + string.Join("; ", names);prompt += "\nSubtitle: " + text;var out_ = await ling.Chat(prompt, "Translate.", priority, maxTokens: 400, timeout: 6);- if (CleanTranslation(out_, target) is { } clean) return clean;+ if (CleanTranslation(out_, target) is { } clean)+ {+ if (GoogleOff) SentencesUntranslated = false;+ return clean;+ }}catch (LingException e) { Log.Debug($"translate ling failed: {e.Message}"); }}+ if (GoogleOff)+ {+ // Left out on purpose: no attempt, so nothing counts as Google failing.+ if (kind != Kind.Draft) SentencesUntranslated = true;+ return null;+ }if (DateTime.UtcNow < googleBackoffUntil) return null;try { return await Google(text, source, target); }catch (GoogleException e)diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex d7bfa73..eb1061c 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -116,7 +116,8 @@ sealed class ControllerLing.Changed += Changed;SpeakerLabels.Voices = Settings.SpeakerVoices;Notes = new NotesEngine(Ling, Store);- Translator = new Translator(Ling);+ Translator = new Translator(Ling) { GoogleOff = Settings.GoogleOff };+ Translator.Changed += Changed;Listen = new ListenEngine(Ling, Translator, Store, Notes, Settings);Speak = new SpeakEngine(Ling, Translator, Store, Settings, () => Listen.Spoken,() => Listen.Listening && Listen.SessionId is { } id && Store.Get(id) is { } s ? (id, s.StartedAt) : null, WindowsVoice);@@ -989,6 +990,7 @@ sealed class Controller/// The service, its address, models or key changed: forget the old check and check again.public void AIChanged(){+ Translator.GoogleOff = Settings.GoogleOff;Ling.KeyChanged();if (Ling.HasKey) _ = Ling.Check();Changed();@@ -1011,6 +1013,7 @@ sealed class Controller["notified"] = problemNotified,["simulated"] = Ling.SimulateCheck?.ToString() ?? (Ling.SimulateBalance is null ? null : "lowBalance"),["catalog"] = new JsonArray(Ling.TextCatalog.Count, Ling.HearCatalog.Count), ["keyFile"] = Path.GetFileName(Key.File_),+ ["customOnly"] = Settings.AiCustomOnly, ["googleOff"] = Translator.GoogleOff, ["untranslated"] = Translator.SentencesUntranslated,};}@@ -1174,6 +1177,7 @@ sealed class Controller/// open <id> [transcript] | play <seconds>|toggle|speed | recordaudio on|off (保存会议录音 and 回放)/// aacencode <wav>|<out.aac> | aacrewrap <in.aac>|<out.m4a>[|<seconds>]/// ai-check | ai-check-sim <reason|lowBalance|off> (unreachable, invalidKey, noCredit, noModel, deaf, busy…)+/// ai-custom-only on|off (语音和文字只发给你的服务; acts with the custom service only)static class DebugServer{static string Pipe => Paths.Dev ? "cicada-dev" : "cicada";@@ -1261,6 +1265,7 @@ static class DebugServerapp.Ling.SimulateBalance = arg == "lowBalance" ? 0.4 : null;_ = app.Ling.Check();break;+ case "ai-custom-only": app.Settings.AiCustomOnly = arg == "on"; app.Settings.Save(); app.AIChanged(); break;case "ai-model":{var kv = arg.Split(' ', 2);diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.csindex d3fffff..7609745 100644--- a/windows/src/Cicada/NotesWindow.cs+++ b/windows/src/Cicada/NotesWindow.cs@@ -179,7 +179,7 @@ sealed class NotesWindow : Windowif (Subtitles) { live.Content = SubtitleLine(); return; }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}";+ 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.Translator.GoogleOff && app.Translator.SentencesUntranslated}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";if (bk != barsKey) { barsKey = bk; bars.Content = Bars(); }live.Content = LiveCard();var count = app.Listen.SessionId is { } sid ? app.Store.Get(sid)?.Lines.Count ?? 0 : 0;@@ -291,6 +291,13 @@ sealed class NotesWindow : Windowelse Add(Ui.StatusLine(Ui.Tone.Waiting, text, (L("重试"), () => { app.Listen.ClearProblem(); _ = app.Ling.Check(); })));}var unreachable = app.Ling.Health.Failure?.Why == AICheck.Reason.Unreachable;+ // 语音和文字只发给你的服务, and finished sentences go untranslated: it picks up by itself, and+ // no 改用 Ling (that would send the meeting elsewhere). When hearing failed, its line says so.+ var notesWait = app.Notes.Status is NotesEngine.State.Unreachable or NotesEngine.State.Updating && unreachable;+ var stalled = problem is null && app.Listen.Listening && app.Translator.GoogleOff && app.Translator.SentencesUntranslated;+ if (stalled)+ Add(Ui.StatusLine(Ui.Tone.Waiting, notesWait ? LF("译文和纪要等 %@ 恢复 · 字幕先显示原文", ServiceLabel())+ : LF("译文等 %@ 恢复 · 字幕先显示原文", ServiceLabel())));if (app.Listen.Listening)switch (app.Notes.Status){@@ -302,7 +309,7 @@ sealed class NotesWindow : Window// only timed out while translations still came back retry on the next round. The retry// that follows (Updating) hangs as long as a timeout: the line stays meanwhile. When// hearing can't reach it either, its line above says so already.- case NotesEngine.State.Unreachable or NotesEngine.State.Updating when unreachable:+ case NotesEngine.State.Unreachable or NotesEngine.State.Updating when unreachable && !stalled:if (problem is not (LingException.Kind.Network or LingException.Kind.Timeout)){// A hear model served at another address still brings subtitles.diff --git a/windows/src/Cicada/SettingsWindow.cs b/windows/src/Cicada/SettingsWindow.csindex ed33c2b..91c8e3f 100644--- a/windows/src/Cicada/SettingsWindow.cs+++ b/windows/src/Cicada/SettingsWindow.cs@@ -440,17 +440,45 @@ sealed class SettingsWindow : Windowintro.Margin = new Thickness(6, -8, 0, 0);yield return intro;yield return Group(TextSection(), VoiceSection(), HearSection());+ yield return Group(OnlyRow());var host = ling.ServiceHost.Length > 0 ? ling.ServiceHost : L("你填的地址");var lockLine = Ui.Helper(LF("仅保存在本机当前账户下,仅发送至 %@", host));lockLine.Margin = new Thickness(6, -4, 0, 0);yield return lockLine;// What it costs depends on where it runs; what is sent where is the port's own line (it hears through the service).var cost = c.Base is { } b && AIProvider.IsNearby(b) ? L("跑在你自己的机器上,不按量计费。") : L("费用以这个服务为准。");- var foot = Ui.Helper(cost + LF("听的时候,电脑里的声音会发给 %@。", ling.HearHost.Length > 0 ? ling.HearHost : L("你填的地址")));+ var foot = Ui.Helper(cost + (app.Settings.AiCustomOnly+ ? LF("会议的语音和文字只发给 %@,不经过 Google 等外部服务。", CustomHosts())+ : LF("听的时候,电脑里的声音会发给 %@。", ling.HearHost.Length > 0 ? ling.HearHost : L("你填的地址"))));foot.Margin = new Thickness(6, 0, 0, 0);yield return foot;}+ /// 语音和文字只发给你的服务 (AISettings.swift › onlyRow): Google is never asked. The grey line says+ /// what it costs, and while the service can't be reached, that new lines show the original+ /// (Windows has no translation of its own to stand in).+ FrameworkElement OnlyRow()+ {+ var s = app.Settings;+ var ling = app.Ling;+ var check = ling.Health;+ var down = s.AiCustomOnly && ling.HasKey && !check.IsRunning && check.Failure is not null && !check.IsBusy;+ var detail = down ? L("现在连不上:新字幕暂时只有原文") : L("不用 Google 翻译;说话时要等整句说完才出译文");+ return Card(null, L("语音和文字只发给你的服务"), detail,+ Ui.Switch(s.AiCustomOnly, v => { s.AiCustomOnly = v; s.Save(); app.AIChanged(); Render(); }, L("语音和文字只发给你的服务")));+ }++ /// Where the custom service's audio and text go: one host when text, hearing and voice share it.+ string CustomHosts()+ {+ var ling = app.Ling;+ var c = ling.Config;+ var hosts = new List<string> { ling.ServiceHost, ling.HearHost };+ if (c.HasVoices && Uri.TryCreate(c.VoiceBase, UriKind.Absolute, out var v)) hosts.Add(v.Host);+ var set = hosts.Where(h => h.Length > 0).Distinct().ToList();+ return set.Count == 1 ? set[0] : L("你填的地址");+ }+/// A row that opens to its fields: a state dot, the use, what it runs on, and how it's doing.FrameworkElement SectionHeader(string id, string title, string detail, Brush dot, string? trailing, Brush? trailingColor = null){@@ -547,7 +575,7 @@ sealed class SettingsWindow : WindowCard(null, L("模型"), null, model),Card(null, "key", null, CustomKey()),};- if (check.SlowLine() is { } slow) parts.Add(Line(slow, Palette.WarnIcon));+ if (check.SlowLine(app.Settings.GoogleOff) is { } slow) parts.Add(Line(slow, Palette.WarnIcon));var key = ling.CurrentKey();if (key is not null && (check.IsRunning || textFailed || check.IsBusy || check.At is not null && !check.Passed && check.Failure is null))parts.Add(AICheckView.Steps(app, ChangeKey, recheckInStep: false));diff --git a/windows/src/Cicada/Strings/en.lproj/Windows.strings b/windows/src/Cicada/Strings/en.lproj/Windows.stringsindex bb1a32a..220e01e 100644--- a/windows/src/Cicada/Strings/en.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/en.lproj/Windows.strings@@ -320,3 +320,5 @@/* The talk key: the computer was playing through the press, so what the mic heard may be its echo. */"对方在说话时说的,没有说出去" = "Said while they were talking, so not sent";"只存在这台电脑上" = "Stored only on this PC";+"例如 kokoro" = "e.g. kokoro";+"例如 af_heart" = "e.g. af_heart";diff --git a/windows/src/Cicada/Strings/ja.lproj/Windows.strings b/windows/src/Cicada/Strings/ja.lproj/Windows.stringsindex c0991b7..88053a4 100644--- a/windows/src/Cicada/Strings/ja.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ja.lproj/Windows.strings@@ -320,3 +320,5 @@/* The talk key: the computer was playing through the press, so what the mic heard may be its echo. */"对方在说话时说的,没有说出去" = "相手が話している間の発言なので、送っていません";"只存在这台电脑上" = "このPCにのみ保存";+"例如 kokoro" = "例:kokoro";+"例如 af_heart" = "例:af_heart";diff --git a/windows/src/Cicada/Strings/ko.lproj/Windows.strings b/windows/src/Cicada/Strings/ko.lproj/Windows.stringsindex e64598e..87cf8dc 100644--- a/windows/src/Cicada/Strings/ko.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ko.lproj/Windows.strings@@ -320,3 +320,5 @@/* The talk key: the computer was playing through the press, so what the mic heard may be its echo. */"对方在说话时说的,没有说出去" = "상대방이 말하는 중이라 보내지 않았어요";"只存在这台电脑上" = "이 PC에만 저장됨";+"例如 kokoro" = "예: kokoro";+"例如 af_heart" = "예: af_heart";diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex 01b261b..26b94eb 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -1888,6 +1888,9 @@ static class Tests"the hear model at its own address, which refused it on its own");Check(ling.Health.Translate is { Thinks: true } && ling.Health.Slow, ling.Health.Summary);Check(ling.Health.SlowLine()!.Contains("先思考"), "says why");+ Check(ling.Health.SlowLine()!.Contains("Google"), "and that Google stands in");+ Check(ling.Health.SlowLine(googleOff: true) is { } only && only.Contains("先思考") && only.Contains("不等它了") && !only.Contains("Google"),+ "语音和文字只发给你的服务: no Google to fall back on");Equal(AICheck.Kind.Ok, ling.Health[AICheck.StepId.Hear].Kind, "hears");ling.KeyChanged();fake.Sent.Clear();@@ -1897,6 +1900,73 @@ static class Testsfinally { LingClient.Spacing = old; }}+ // 语音和文字只发给你的服务 (issue #15; the Mac's GoogleOffTests): Google is never asked.++ public static void CustomOnlyActsWithTheCustomServiceAlone()+ {+ var s = new AppSettings { AiProvider = "custom", AiCustomOnly = true };+ Check(s.GoogleOff, "on with the custom service");+ s.AiProvider = "zenmux";+ Check(!s.GoogleOff && s.AiCustomOnly, "kept but inert with another service");+ Check(Json.Write(new AppSettings { AiCustomOnly = true }).Contains("\"aiCustomOnly\": true"), "the Mac's key");+ Check(Json.Read<AppSettings>("{\"aiCustomOnly\":true}")!.AiCustomOnly, "read back");+ }++ public static async Task WithGoogleOffPartialTextGoesNowhere()+ {+ var google = new Service((_, _) => Status(200, "[[[\"周五\",\"Friday\"]]]"));+ var service = new Service((_, _) => Reply("我们周五发布。"));+ var (ling, _) = Using(service);+ var t = new Translator(ling, google) { GoogleOff = true };+ for (var i = 0; i < 3; i++) Equal(null, await t.Translate("We ship on Friday", "en", "zh-CN", Translator.Kind.Draft), "the original shows");+ Check(google.Sent.Count == 0 && service.Sent.Count == 0, "neither Google nor the service sees a draft");+ Check(!t.SentencesUntranslated, "a draft says nothing about sentences");+ }++ public static async Task WithGoogleOffSentencesGoToTheServiceOnly()+ {+ var old = LingClient.Spacing; LingClient.Spacing = 0;+ try+ {+ var google = new Service((_, _) => Status(200, "[[[\"谷歌的译文\",\"x\"]]]"));+ var up = false;+ var service = new Service((_, _) => up ? Reply("我们周五发布。") : Status(400, "{\"error\":{\"message\":\"bad\"}}"));+ var (ling, _) = Using(service);+ var t = new Translator(ling, google) { GoogleOff = true };+ var changes = 0;+ t.Changed += () => changes++;+ Equal(null, await t.Translate("We ship on Friday.", "en", "zh-CN", Translator.Kind.Sentence), "the service failed: the original only");+ Check(service.Sent.Count > 0, "the service was asked");+ Equal(0, google.Sent.Count, "Google never was");+ Check(t.SentencesUntranslated && changes == 1, "the notes window is told");+ up = true;+ Equal("我们周五发布。", await t.Translate("We ship on Friday.", "en", "zh-CN", Translator.Kind.Sentence), "the service answers again");+ Check(!t.SentencesUntranslated && changes == 2, "and the notice goes");+ Equal(0, google.Sent.Count, "still no Google");++ // Off again: Google stands in as before.+ t.GoogleOff = false;+ up = false;+ Equal("谷歌的译文", await t.Translate("We ship on Friday.", "en", "zh-CN", Translator.Kind.Sentence), "Google once more");+ Equal(1, google.Sent.Count, "one request to Google");+ }+ finally { LingClient.Spacing = old; }+ }++ public static async Task FlippingGoogleOffClearsAGoogleBackoff()+ {+ var google = new Service((_, _) => Status(429));+ var (ling, _) = Using(new Service((_, _) => Reply("x")), key: null);+ var t = new Translator(ling, google);+ Equal(null, await t.Translate("Hello", "en", "zh-CN", Translator.Kind.Draft), "rate-limited");+ Equal(null, await t.Translate("Hello", "en", "zh-CN", Translator.Kind.Draft), "backing off");+ Equal(1, google.Sent.Count, "the second waits out the backoff");+ t.GoogleOff = true;+ t.GoogleOff = false;+ await t.Translate("Hello", "en", "zh-CN", Translator.Kind.Draft);+ Equal(2, google.Sent.Count, "the backoff went with the flip");+ }+public static async Task AHearServerRefusingKwargsLeavesTheTextServerAlone(){var old = LingClient.Spacing; LingClient.Spacing = 0;