Skip to content

feat: 集成豆包 ASR 语音识别后端,支持 /voice doubao 切换#357

Merged
claude-code-best merged 2 commits intomainfrom
feature/voice-doubao-support
Apr 25, 2026
Merged

feat: 集成豆包 ASR 语音识别后端,支持 /voice doubao 切换#357
claude-code-best merged 2 commits intomainfrom
feature/voice-doubao-support

Conversation

@claude-code-best
Copy link
Copy Markdown
Owner

@claude-code-best claude-code-best commented Apr 25, 2026

  • 新增 src/services/doubaoSTT.ts 适配模块,将 doubaoime-asr 的 AsyncGenerator 协议适配为现有 VoiceStreamConnection 接口
  • /voice doubao 启用豆包后端,/voice 使用默认 Anthropic 后端
  • 后端选择持久化到 settings.json 的 voiceProvider 字段
  • 豆包后端跳过 Anthropic OAuth 认证、语言限制和 Focus Mode
  • 豆包后端松手即出结果,跳过 processing 状态
  • 凭证文件存放在 ~/.claude/tts/doubao/credentials.json
  • doubaoime-asr 作为 optionalDependencies 安装
  • 移除 /voice 命令的 claude-ai 可用性限制,所有用户可用

Summary by CodeRabbit

  • New Features

    • Added Doubao ASR as an alternative voice input backend and allow switching between Anthropic and Doubao via voice commands; provider reflected in prompts.
  • Documentation

    • Updated Voice Mode docs and README to describe dual-backend usage, credentials, and switching workflow.
  • Chores

    • Added Doubao ASR as an optional dependency and ignored local credentials file.
    • Added a voiceProvider setting to persist backend choice.
  • Tests

    • Minor test typing adjustments (no runtime changes).

- 新增 src/services/doubaoSTT.ts 适配模块,将 doubaoime-asr 的
  AsyncGenerator 协议适配为现有 VoiceStreamConnection 接口
- /voice doubao 启用豆包后端,/voice 使用默认 Anthropic 后端
- 后端选择持久化到 settings.json 的 voiceProvider 字段
- 豆包后端跳过 Anthropic OAuth 认证、语言限制和 Focus Mode
- 豆包后端松手即出结果,跳过 processing 状态
- 凭证文件存放在 ~/.claude/tts/doubao/credentials.json
- doubaoime-asr 作为 optionalDependencies 安装
- 移除 /voice 命令的 claude-ai 可用性限制,所有用户可用

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mintlify
Copy link
Copy Markdown

mintlify Bot commented Apr 25, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ccb-863780bf 🟢 Ready View Preview Apr 25, 2026, 5:51 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c81743b-7fee-40f6-8c48-fd3dd992017e

📥 Commits

Reviewing files that changed from the base of the PR and between dce10e6 and b0a9d95.

📒 Files selected for processing (2)
  • README.md
  • docs/features/voice-mode.md

📝 Walkthrough

Walkthrough

This PR adds Doubao ASR as an optional voice provider alongside Anthropic: new Doubao streaming adapter, settings schema for provider selection, command/hook changes to route between providers, optional dependency and gitignore update, and documentation updates reflecting dual-backend voice mode.

Changes

Cohort / File(s) Summary
Config & Dependencies
/.gitignore, package.json
Adds credentials.json to .gitignore and adds doubaoime-asr as an optionalDependencies entry.
Doubao ASR Adapter
src/services/doubaoSTT.ts
New streaming adapter: dynamic imports doubaoime-asr, provides isDoubaoAvailable()/isDoubaoAvailableSync(), connectDoubaoStream() with AsyncGenerator-based streaming, transcript/error/c lifecycle handling, and re-exports FinalizeSource.
Voice Command
src/commands/voice/index.ts, src/commands/voice/voice.ts
Command metadata updated (description, removes availability), uses isVoiceAvailable() for enabled/hidden checks, accepts optional args to select provider, switches/stores voiceProvider, runs Anthropic auth checks only when selecting Anthropic, and tailors post-enable messaging/behavior per provider.
Voice Hooks & Runtime
src/hooks/useVoice.ts, src/hooks/useVoiceEnabled.ts
Provider-aware logic: routes connect calls to connectDoubaoStream vs connectVoiceStream, skips keyterm fetch for Doubao, uses Doubao synchronous availability in some flows, and branches enablement/auth checks based on settings.voiceProvider. Adds internal isDoubaoProvider() helper.
Settings & Feature Flags
src/utils/settings/types.ts, src/voice/voiceModeEnabled.ts
Adds optional `voiceProvider: 'anthropic'
Docs & README
README.md, docs/features/voice-mode.md
Updates Voice Mode docs and README to document Doubao backend, credentials, usage (/voice doubao), architecture changes, and acknowledgements.
Tests
src/utils/suggestions/__tests__/commandSuggestions.test.ts
Minor test typing change: cast helpers to as unknown as Command.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Cmd as Voice Command
    participant Settings as Settings Store
    participant Hook as useVoice Hook
    participant Provider as Provider Adapter<br/>(Doubao / Anthropic)
    participant ASR as ASR Backend

    User->>Cmd: /voice doubao (or anthropic)
    Cmd->>Settings: isVoiceAvailable()
    alt available
        Cmd->>Settings: determine provider from args
        alt provider == Anthropic
            Cmd->>Provider: run Anthropic auth check
        else provider == Doubao
            Note right of Cmd: Skip Anthropic OAuth check
        end
        Cmd->>Settings: set voiceProvider, enable voice
        User->>Hook: start recording
        Hook->>Settings: read voiceProvider
        alt provider == Doubao
            Hook->>Provider: connectDoubaoStream(language?)
            Provider->>ASR: open stream (credentials file)
        else provider == Anthropic
            Hook->>Provider: connectVoiceStream(keyterms)
            Provider->>ASR: open stream (OAuth)
        end
        ASR->>Provider: stream audio chunks
        Provider->>Hook: INTERIM_RESULT / FINAL_RESULT
        Hook->>User: display transcripts
    else unavailable
        Cmd->>User: return unavailable message
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • KonghaYao

Poem

🐰 A Doubao hops into the stream,
Two voices now to chase the dream,
Settings set, the choice is clear,
Streams whisper—near and near,
Rabbit cheers: record and gleam! 🎤✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: integrating Doubao ASR voice recognition backend with support for switching via /voice doubao command.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/voice-doubao-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@claude-code-best claude-code-best merged commit 2e7fc42 into main Apr 25, 2026
8 checks passed
@claude-code-best claude-code-best deleted the feature/voice-doubao-support branch April 25, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant