Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): simplify empty companion voice settings

JiangJiahao400fc878eb47
diff --git a/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx b/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx
index b19ddd5bb3..7412b1b9d1 100644
--- a/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotsHomeView.tsx
@@ -733,7 +733,12 @@ export function BotSettings({
) : null}
{page === 'voice' ? (
<CompanionVoiceSettings botId={bot.id} sessionId={canonicalBotSessionId(bot) ?? undefined}
- beforeLeaveRef={voiceLeaveRef} />
+ beforeLeaveRef={voiceLeaveRef}
+ onOpenProviders={() => {
+ void canLeave().then((allowed) => {
+ if (allowed) navigate('/settings?tab=providers');
+ });
+ }} />
) : null}
{page === 'memory' ? (
<BotMemorySettings
diff --git a/apps/desktop/src/renderer/features/bots/voice/CompanionVoiceSettings.tsx b/apps/desktop/src/renderer/features/bots/voice/CompanionVoiceSettings.tsx
index 3ae376bc05..7de7711bc7 100644
--- a/apps/desktop/src/renderer/features/bots/voice/CompanionVoiceSettings.tsx
+++ b/apps/desktop/src/renderer/features/bots/voice/CompanionVoiceSettings.tsx
@@ -31,6 +31,7 @@ type Props = {
botId: string;
sessionId?: string;
beforeLeaveRef?: { current: (() => Promise<boolean>) | null };
+ onOpenProviders(): void;
};
/** Per-companion settings. Opening this page never starts ASR or submits a message. */
@@ -249,15 +250,57 @@ export function CompanionVoiceSettings(props: Props) {
void persist(next);
};
+ // Keep unavailable controls out of the empty state, including while its first
+ // catalog request is pending. This only changes presentation, not saved preferences.
+ if (models.length === 0) {
+ return (
+ <div className="space-y-4 pt-3">
+ {loading ? (
+ <p role="status" className="text-13 text-[var(--text-secondary)]">
+ {t('bots.voiceMode.status.loading')}
+ </p>
+ ) : catalogError ? (
+ <>
+ <p className="text-13 text-[var(--text-secondary)]">
+ {t('bots.voiceMode.catalogError')}
+ </p>
+ <Button
+ variant="secondary"
+ size="sm"
+ compact
+ onClick={() => {
+ void refresh(true);
+ if (!ready) loadPreference();
+ }}
+ >
+ {t('bots.voiceMode.refresh')}
+ </Button>
+ </>
+ ) : (
+ <div className="space-y-2">
+ <p className="text-13 text-[var(--text-secondary)]">{t('bots.voiceMode.noModels')}</p>
+ <p className="text-12 leading-relaxed text-[var(--text-secondary)]">
+ {t('bots.voiceMode.noModelsSupportedProtocols')}
+ </p>
+ <p className="text-12 leading-relaxed text-[var(--text-secondary)]">
+ {t('bots.voiceMode.noModelsSetupHint')}
+ </p>
+ <Button variant="secondary" size="sm" compact onClick={props.onOpenProviders}>
+ {t('bots.voiceMode.openProviders')}
+ </Button>
+ </div>
+ )}
+ </div>
+ );
+ }
+
return (
<div className="space-y-4 pt-3">
<p className="text-13 leading-relaxed text-[var(--text-secondary)]">
{t('bots.voiceMode.settingsHint')}
</p>
- {catalogError || (!loading && models.length === 0) ? (
- <p className="text-13 text-[var(--text-secondary)]">
- {t(catalogError ? 'bots.voiceMode.catalogError' : 'bots.voiceMode.noModels')}
- </p>
+ {catalogError ? (
+ <p className="text-13 text-[var(--text-secondary)]">{t('bots.voiceMode.catalogError')}</p>
) : null}
<div className="flex flex-wrap items-start gap-3">
<FormField label={t('bots.voiceMode.model')} className="min-w-52 flex-[2]">
diff --git a/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsx b/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsx
index b7c60f4803..f639fca643 100644
--- a/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsx
@@ -75,6 +75,7 @@ vi.mock('@/lib/makerChatStore', () => ({
let models: VoiceConversationModel[];
const start = vi.fn(async () => ({ callId: 'call' }));
const refresh = vi.fn(async () => undefined);
+const openProviders = vi.fn();
beforeEach(() => {
vi.clearAllMocks();
window.localStorage.clear();
@@ -104,11 +105,14 @@ beforeEach(() => {
});
afterEach(cleanup);
const renderSettings = (botId = 'bot') =>
- render(<CompanionVoiceSettings botId={botId} sessionId="canonical" />);
+ render(
+ <CompanionVoiceSettings botId={botId} sessionId="canonical" onOpenProviders={openProviders} />,
+ );
-it('defaults to sentence playback, persists a toggle without a model, and restores the default', async () => {
+it('defaults to sentence playback, persists a playback-only change, and restores the default', async () => {
+ models = [{ id: 'tts', name: 'Speech', defaultVoice: 'alloy' }];
const view = renderSettings();
- const toggle = screen.getByRole('switch', { name: 'bots.voiceMode.sentencePlayback' });
+ const toggle = await screen.findByRole('switch', { name: 'bots.voiceMode.sentencePlayback' });
await waitFor(() => expect(toggle.hasAttribute('disabled')).toBe(false));
expect(toggle.getAttribute('aria-checked')).toBe('true');
vi.mocked(window.electronAPI.voiceConversation.setPreference).mockResolvedValueOnce({
@@ -144,8 +148,9 @@ it('defaults to sentence playback, persists a toggle without a model, and restor
});
it('retains the saved toggle and reports a save failure', async () => {
+ models = [{ id: 'tts', name: 'Speech', defaultVoice: 'alloy' }];
renderSettings();
- const toggle = screen.getByRole('switch');
+ const toggle = await screen.findByRole('switch');
await waitFor(() => expect(toggle.hasAttribute('disabled')).toBe(false));
vi.mocked(window.electronAPI.voiceConversation.setPreference).mockRejectedValueOnce(
new Error('disk'),
@@ -176,13 +181,60 @@ it('does not erase an unsaved manual voice when only changing playback', async (
});
it('shows a useful empty state without requesting a microphone or inventing models', async () => {
- renderSettings();
+ const savedSelection = { modelId: 'tts', voice: 'nova' };
+ vi.mocked(window.electronAPI.voiceConversation.preference).mockResolvedValue({
+ selection: savedSelection,
+ customized: true,
+ sentencePlayback: false,
+ });
+ const view = renderSettings();
+ expect(screen.getByRole('status').textContent).toBe('bots.voiceMode.status.loading');
+ expect(screen.queryByLabelText('bots.voiceMode.model')).toBeNull();
+ expect(screen.queryByRole('switch')).toBeNull();
await screen.findByText('bots.voiceMode.noModels');
+ expect(screen.getByText('bots.voiceMode.noModelsSupportedProtocols')).toBeTruthy();
+ expect(screen.getByText('bots.voiceMode.noModelsSetupHint')).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'bots.voiceMode.openProviders' }));
+ expect(openProviders).toHaveBeenCalledOnce();
expect(screen.queryByRole('button', { name: 'bots.voiceMode.preview' })).toBeNull();
+ expect(screen.queryByText('bots.voiceMode.settingsHint')).toBeNull();
+ expect(screen.queryByText('bots.voiceMode.preferenceHint')).toBeNull();
+ expect(screen.queryByLabelText('bots.voiceMode.model')).toBeNull();
+ expect(screen.queryByRole('switch')).toBeNull();
+ expect(screen.getAllByRole('button')).toHaveLength(1);
+ expect(window.electronAPI.voiceConversation.setPreference).not.toHaveBeenCalled();
expect(start).not.toHaveBeenCalled();
expect(audio.start).not.toHaveBeenCalled();
+ view.unmount();
+ models = [{ id: 'tts', name: 'Speech', defaultVoice: 'alloy' }];
+ renderSettings();
+ await screen.findByRole('option', { name: 'Speech' });
+ expect(screen.queryByText('bots.voiceMode.noModelsSupportedProtocols')).toBeNull();
+ expect(screen.queryByRole('button', { name: 'bots.voiceMode.openProviders' })).toBeNull();
+ expect(screen.getByText('bots.voiceMode.settingsHint')).toBeTruthy();
+ await waitFor(() =>
+ expect((screen.getByLabelText('bots.voiceMode.voiceId') as HTMLInputElement).value).toBe(
+ 'nova',
+ ),
+ );
+ expect(screen.getByRole('switch').getAttribute('aria-checked')).toBe('false');
+ expect(window.electronAPI.voiceConversation.setPreference).not.toHaveBeenCalled();
+});
+
+it('does not present a catalog failure as missing models or suggest adding a connection', async () => {
+ window.electronAPI.voiceConversation.models = vi.fn(async () => {
+ throw new Error('catalog unavailable');
+ });
+ renderSettings();
+ await screen.findByText('bots.voiceMode.catalogError');
+ expect(screen.queryByText('bots.voiceMode.noModelsSupportedProtocols')).toBeNull();
+ expect(screen.queryByRole('button', { name: 'bots.voiceMode.openProviders' })).toBeNull();
+ expect(screen.queryByLabelText('bots.voiceMode.model')).toBeNull();
+ expect(screen.queryByRole('switch')).toBeNull();
+ window.electronAPI.voiceConversation.models = vi.fn(async () => models);
fireEvent.click(screen.getByRole('button', { name: 'bots.voiceMode.refresh' }));
- await waitFor(() => expect(refresh).toHaveBeenCalledWith('xd'));
+ await screen.findByText('bots.voiceMode.noModels');
+ expect(refresh).toHaveBeenCalledWith('xd');
});
it('selects the exact BYOK connection for duplicate IDs and persists it for this companion', async () => {
@@ -806,7 +858,12 @@ it('flushes a manually typed voice before leaving and keeps the page open on sav
models = [{ id: 'tts', name: 'Speech', defaultVoice: 'alloy' }];
const beforeLeaveRef = { current: null as null | (() => Promise<boolean>) };
render(
- <CompanionVoiceSettings botId="bot" sessionId="canonical" beforeLeaveRef={beforeLeaveRef} />,
+ <CompanionVoiceSettings
+ botId="bot"
+ sessionId="canonical"
+ beforeLeaveRef={beforeLeaveRef}
+ onOpenProviders={openProviders}
+ />,
);
const input = await screen.findByLabelText('bots.voiceMode.voiceId');
await waitFor(() => expect((input as HTMLInputElement).disabled).toBe(false));
@@ -833,7 +890,7 @@ it('flushes a manually typed voice before leaving and keeps the page open on sav
it('allows model configuration but disables preview before a canonical conversation exists', async () => {
models = [{ id: 'tts', name: 'Speech', defaultVoice: 'alloy' }];
- render(<CompanionVoiceSettings botId="bot" />);
+ render(<CompanionVoiceSettings botId="bot" onOpenProviders={openProviders} />);
await waitFor(() =>
expect((screen.getByLabelText('bots.voiceMode.model') as HTMLSelectElement).disabled).toBe(
false,
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index bb12111f7c..e92bb3b82b 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -9497,7 +9497,10 @@
"voice": "Voice",
"voiceHint": "Use a voice name supported by the selected model, such as alloy.",
"modelUnavailable": "The saved speech model is unavailable. Choose another model.",
- "noModels": "No usable speech model. Connect a speech provider in Settings, enable a model, then refresh here.",
+ "noModels": "No text-to-speech models available.",
+ "noModelsSupportedProtocols": "Supports MiniMax, ElevenLabs, and providers with an OpenAI-compatible text-to-speech API.",
+ "noModelsSetupHint": "Connect a provider and enable a speech model to set up your companion’s voice.",
+ "openProviders": "Open Model Providers",
"catalogError": "Could not load or save speech settings. Please try again.",
"start": "Start talking",
"resume": "Resume",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 39a537d05f..416ae81f53 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -9460,7 +9460,10 @@
"voice": "音声",
"voiceHint": "選択したモデルが対応する音声名を入力してください(例:alloy)。",
"modelUnavailable": "保存した読み上げモデルは利用できません。別のモデルを選んでください。",
- "noModels": "利用できる音声合成モデルがありません。設定でプロバイダーに接続し、モデルを有効にしてから更新してください。",
+ "noModels": "利用可能な音声合成モデルがありません。",
+ "noModelsSupportedProtocols": "MiniMax、ElevenLabs、および OpenAI 互換の音声合成 API を提供するプロバイダーに対応しています。",
+ "noModelsSetupHint": "プロバイダーに接続して音声モデルを有効にすると、パートナーの読み上げ音声を設定できます。",
+ "openProviders": "モデルプロバイダーを開く",
"catalogError": "音声設定の読み込み、または保存に失敗しました。もう一度お試しください。",
"start": "会話を始める",
"resume": "再開",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 97a9b5df5b..34b134bf02 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -9460,7 +9460,10 @@
"voice": "목소리",
"voiceHint": "선택한 모델이 지원하는 음성 이름을 입력하세요. 예: alloy.",
"modelUnavailable": "저장된 읽어주기 모델을 사용할 수 없습니다. 다른 모델을 선택하세요.",
- "noModels": "사용 가능한 음성 합성 모델이 없습니다. 설정에서 제공자를 연결하고 모델을 활성화한 다음 새로고침하세요.",
+ "noModels": "사용 가능한 음성 합성 모델이 없습니다.",
+ "noModelsSupportedProtocols": "MiniMax, ElevenLabs 및 OpenAI 호환 음성 합성 API 제공자를 지원합니다.",
+ "noModelsSetupHint": "제공자를 연결하고 음성 모델을 활성화하면 파트너의 낭독 음성을 설정할 수 있습니다.",
+ "openProviders": "모델 제공자 열기",
"catalogError": "음성 설정을 불러오거나 저장하지 못했습니다. 다시 시도하세요.",
"start": "대화 시작",
"resume": "계속",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 1d7bbfe2cc..71d64b8ea6 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -9460,7 +9460,10 @@
"voice": "音色",
"voiceHint": "填写所选模型支持的音色名称,例如 alloy。",
"modelUnavailable": "之前选择的朗读模型已不可用,请重新选择。",
- "noModels": "暂无可用的语音合成模型。请在设置中连接供应商并启用模型,然后刷新。",
+ "noModels": "暂无可用的语音合成模型。",
+ "noModelsSupportedProtocols": "支持 MiniMax、ElevenLabs,以及提供 OpenAI 兼容语音合成接口的供应商。",
+ "noModelsSetupHint": "连接供应商并启用语音模型后,即可设置伙伴的朗读声音。",
+ "openProviders": "前往模型供应商",
"catalogError": "语音设置读取或保存失败,请重试。",
"start": "开始说话",
"resume": "继续",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 5cbfc80529..9ded19f6ed 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -9460,7 +9460,10 @@
"voice": "音色",
"voiceHint": "填入所選模型支援的音色名稱,例如 alloy。",
"modelUnavailable": "先前選擇的朗讀模型已無法使用,請重新選擇。",
- "noModels": "暫無可用的語音合成模型。請在設定中連接供應商並啟用模型,然後重新整理。",
+ "noModels": "目前沒有可用的語音合成模型。",
+ "noModelsSupportedProtocols": "支援 MiniMax、ElevenLabs,以及提供 OpenAI 相容語音合成介面的供應商。",
+ "noModelsSetupHint": "連接供應商並啟用語音模型後,即可設定夥伴的朗讀聲音。",
+ "openProviders": "前往模型供應商",
"catalogError": "語音設定讀取或儲存失敗,請重試。",
"start": "開始說話",
"resume": "繼續",
diff --git a/docs/product-rules/companion-voice-mode.md b/docs/product-rules/companion-voice-mode.md
index 2df05b2232..de0a72809e 100644
--- a/docs/product-rules/companion-voice-mode.md
+++ b/docs/product-rules/companion-voice-mode.md
@@ -7,7 +7,7 @@
- 最后一次声音活动或识别文字更新后,至少等待 1.25 秒再自动发送;期间继续说话会合并到同一段发言,只有 ASR 检出的弱声也遵守相同门槛。900ms 的声音释放只负责提前提交 ASR 缓冲,不触发发送;还须等待全部分段为最终文字及最后一次 ASR 更新后的 350ms 稳定窗口,延迟返回的识别结果可能延长等待。手动发送可跳过停顿等待,但不能发送未完成的识别文字。只有最终、非空文字能发送;声音活动检测本身不能产生消息。
- 原任务空闲时正常发送,仍在运行时沿既有插话路径投递。语音是本机用户本人输入,不盖自动化或远程设备来源标签,不增加系统提示词。识别结果按普通文字发送,不执行桌面斜杠命令。
- 默认开启“按句朗读”:可靠标记为 `final_answer` 的回复在输出完整句子后即可开始朗读,未完成的尾句留到后续输出或完成时再处理。关闭后,等整条最终回复经过持久化完成标记确认再朗读。按本次语音发送的 clientId 关联,不朗读历史、过程文字、工具、子代理、内部协调或群来源私信。文本消息始终是对话记录的正本。
-- 在“伙伴设置 → 语音”中独立选择朗读模型和音色,按当前账号下的伙伴保存,不改变聊天模型。来源包括有权限的 Cindy AI,以及已连接的本地 BYOK 供应商;候选必须是 `audio_speech`、未停用且具备可用的 API key 或明确的本机免鉴权连接。同名模型按连接 ID、runtime 和上游模型 ID 区分,不能借另一连接的密钥。无候选时显示空状态,不采集麦克风。
+- 在“伙伴设置 → 语音”中独立选择朗读模型和音色,按当前账号下的伙伴保存,不改变聊天模型。来源包括有权限的 Cindy AI,以及已连接的本地 BYOK 供应商;候选必须是 `audio_speech`、未停用且具备可用的 API key 或明确的本机免鉴权连接。同名模型按连接 ID、runtime 和上游模型 ID 区分,不能借另一连接的密钥。无候选时显示空状态,不采集麦克风。语音设置页在目录读取成功且候选为空时仅显示介绍(支持 MiniMax、ElevenLabs 与 OpenAI 兼容语音合成接口)和“前往模型供应商”入口,隐藏配置说明、模型选择与刷新、按句朗读、保存说明和恢复默认,不清除已有偏好。跳转复用既有离页保存检查;返回页面时重新读取目录,有可用候选后显示完整配置并隐藏接入提示。首次加载不闪现配置控件;目录读取失败时显示错误和重试入口,不误报为空列表。
- “按句朗读”同样按伙伴保存,未设置时继承开启默认值。显式开关保存在已有语音设置的 `conversationSentencePlayback` 映射中,不另建配置文件;恢复默认删除当前伙伴的覆盖,不影响其他伙伴。切换模型或音色不重置此开关;仅修改开关不丢弃尚未补齐的音色草稿。设置在下一次开始语音对话时生效。
- BYOK 支持 OpenAI 兼容、ElevenLabs、MiniMax 三种语音接口。已知官方 HTTPS 地址自动匹配并固定接口,设置页隐藏接口选择及自动匹配说明,用户只需选择模型和音色;Main 同样采用该官方接口,不接受旧偏好或调用参数切换到其他厂商协议。自定义/中转地址保留手动选择;已声明的 OpenAI speech 协议可作为默认,其余候选(包括显式未验证协议)须用户明确选择。不能只凭模型名、`mode` 或聊天协议推断,切换接口不会更换连接地址或凭证。这个覆盖仅作用于当前伙伴的朗读,不重写公共 Registry 或供应商的聊天协议。音色支持列表选择、手动输入和试听;本次不提供创建或删除克隆音色的能力。
- 模型、语音接口和音色为伙伴级显式偏好,重开设置、重启后保留。设置页只负责配置与试听,不创建通话。离开设置前等待试听停止和有效音色保存;保存失败保留当前页面。未补齐的型号/接口/音色选择仅作本地草稿,不覆盖此前可用偏好。尚无 canonical 任务时可配置,试听需等待伙伴对话建立。恢复默认删除该伙伴的选择,继续跟随可用目录;已有旧版全局偏好仍可继承,单独重置一个伙伴时以 `null` 清除该伙伴的旧偏好继承,不复制默认模型、不影响其他伙伴。保存失败明确提示。保存的连接消失或停用时保留选择并禁止开始,不静默改用同名模型。