Skip to content

英語TTSの音量を8dB上げる - #5537

Merged
TinyKitten merged 4 commits into
devfrom
claude/increase-tts-volume-RrStk
Mar 7, 2026
Merged

TinyKitten merged 4 commits into
devfrom
claude/increase-tts-volume-RrStk

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 7, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

リリースノート

  • 改善

    • Geminiテキスト読み上げの音声出力にボリュームブーストを適用し、聞き取りやすさを向上しました。
    • MP3エンコーディングで任意のボリューム調整が可能になりました。
    • 音声フォーマット検出を拡張し、複数形式の入力をより安定して処理します。
  • 修正

    • MP3判定ロジックを強化し、誤判定による処理ミスを低減しました。

@coderabbitai

coderabbitai Bot commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

TTSのMP3エンコードフローに音量調整パラメータを追加し、Gemini出力用に8dBのボリュームブーストを適用するように変更。MP3ヘッダー判定を厳格化し、ensureMp3のシグネチャを拡張、内部キャッシュ用ハッシュバージョンを6→7に更新。

Changes

Cohort / File(s) Summary
TTS関連パイプライン
functions/src/funcs/tts.ts
EN_GEMINI_VOLUME_BOOST_DB(8dB)を追加し、Gemini向けのensureMp3呼び出しでvolumeDbを渡すよう変更。内部ハッシュペイロードのバージョンを6→7に更新。
MP3エンコーディング処理
functions/src/utils/encodeMp3.ts
encodePcmToMp3に任意のvolumeDb?引数を追加。ffmpeg呼び出しに音量フィルタを条件挿入。WAV判定を拡張してMP3ヘッダ/フレーム同期も検出するhasKnownHeaderロジックに変更。
共通署名変更
functions/src/funcs/tts.ts, functions/src/utils/encodeMp3.ts
ensureMp3(audioBuffer, mimeType) → ensureMp3(audioBuffer, mimeType, volumeDb?)にシグネチャ更新。関連する呼び出し site をすべて更新。

Sequence Diagram(s)

sequenceDiagram
    participant TTS as TTS Service
    participant Ensure as ensureMp3
    participant Encoder as encodePcmToMp3
    participant FFmpeg as ffmpeg

    TTS->>Ensure: audioBuffer, mimeType, volumeDb (EN_GEMINI_VOLUME_BOOST_DB)
    Ensure->>Ensure: validate MP3 header (strict)
    alt needs encoding
        Ensure->>Encoder: pcmBuffer, sampleRate, volumeDb
        Encoder->>FFmpeg: input args (+volume filter if volumeDb)
        FFmpeg-->>Encoder: encoded MP3
        Encoder-->>Ensure: mp3Buffer, mimeType
    else already MP3 and no volumeDb
        Ensure-->>TTS: passthrough mp3Buffer
    end
    Ensure-->>TTS: final mp3Buffer (possibly boosted)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

ポエム

🐇 小さな耳で聞いたよ、音が伸びる道
八デシベルの跳ねる光景、ふわり🎶
ヘッダーは賢く見張りつつ
エンコードは優しく音を抱く
バージョン七でまた跳ねるよ ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは、英語TTSの音量を8dB上げるという実装内容と完全に一致しており、変更の主要な目的を明確に要約している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/increase-tts-volume-RrStk

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

@TinyKitten TinyKitten changed the title MP3入力時にffmpegがフォーマットを自動判別するよう修正 英語TTSの音量を8dB上げる Mar 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
functions/src/funcs/tts.ts (1)

26-26: 音量ブースト値もキャッシュキーに含めてください。

Line 347-350 で EN_GEMINI_VOLUME_BOOST_DB が出力に効くようになりましたが、Line 263-269 のハッシュ payload には入っていません。今は version = 7 で無効化できていますが、将来ブースト量だけ変えると古い音量のキャッシュを再利用します。

修正案
     const hashPayloadObj = {
       enModel: GEMINI_TTS_MODEL,
+      enVolumeBoostDb: EN_GEMINI_VOLUME_BOOST_DB,
       enVoiceName,
       jaVoiceName,
       ssmlEn,
       ssmlJa,
       version,
     } as const;

Also applies to: 262-270, 347-350

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/src/funcs/tts.ts` at line 26, The cache/hash payload construction
that builds the payload around the `version` (lines ~263-269) must include the
`EN_GEMINI_VOLUME_BOOST_DB` constant so changes in the boost value produce a
different cache key; update the payload or key generation (where the hash
payload is assembled and `version` is set) to append or incorporate
`EN_GEMINI_VOLUME_BOOST_DB` (and not just keep `version = 7`) so the output
affected by `EN_GEMINI_VOLUME_BOOST_DB` (lines ~347-350) won't incorrectly reuse
stale cached audio.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@functions/src/utils/encodeMp3.ts`:
- Around line 14-25: The MP3 frame-sync branch in hasKnownHeader is too
permissive; update the MP3 detection to require at least 4 header bytes (use
pcmBuffer.subarray(0,4)), verify the 0xFF sync byte and (pcmBuffer[1] & 0xE0)
=== 0xE0, then decode header fields and reject reserved/invalid values (version
= (hdr[1] >> 3) & 0x03 must not equal 0x01, layer = (hdr[1] >> 1) & 0x03 must
not equal 0x00, sampling = (hdr[2] >> 2) & 0x03 must not equal 0x03); only treat
as MP3 if all these checks pass. Apply the same stricter header validation
wherever the MP3-frame-sync check appears (the other occurrence mentioned) so
genuine PCM isn't misclassified.

---

Nitpick comments:
In `@functions/src/funcs/tts.ts`:
- Line 26: The cache/hash payload construction that builds the payload around
the `version` (lines ~263-269) must include the `EN_GEMINI_VOLUME_BOOST_DB`
constant so changes in the boost value produce a different cache key; update the
payload or key generation (where the hash payload is assembled and `version` is
set) to append or incorporate `EN_GEMINI_VOLUME_BOOST_DB` (and not just keep
`version = 7`) so the output affected by `EN_GEMINI_VOLUME_BOOST_DB` (lines
~347-350) won't incorrectly reuse stale cached audio.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9f21a05f-56a6-4f06-a53a-8db34d039439

📥 Commits

Reviewing files that changed from the base of the PR and between 3368484 and 5018b22.

📒 Files selected for processing (2)
  • functions/src/funcs/tts.ts
  • functions/src/utils/encodeMp3.ts

Comment thread functions/src/utils/encodeMp3.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
functions/src/funcs/tts.ts (1)

51-64: MP3ヘッダー検出ロジックの重複があります。

sniffAudioMimeTypeのMP3フレーム同期検出ロジックがencodeMp3.tsのhasKnownHeaderと重複しています。将来のメンテナンス性のため、共通ユーティリティへの抽出を検討してください。

♻️ 共通ユーティリティの抽出案
// utils/audioFormat.ts などに抽出
export const isMp3FrameSync = (buffer: Buffer): boolean =>
  buffer.length >= 4 &&
  buffer[0] === 0xff &&
  (buffer[1] & 0xe0) === 0xe0 &&
  ((buffer[1] >> 3) & 0x03) !== 0x01 &&
  ((buffer[1] >> 1) & 0x03) !== 0x00 &&
  ((buffer[2] >> 2) & 0x03) !== 0x03;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/src/funcs/tts.ts` around lines 51 - 64, The MP3 frame-sync
detection in sniffAudioMimeType duplicates logic in encodeMp3.ts's
hasKnownHeader; extract that predicate into a shared utility (e.g.,
isMp3FrameSync) and replace the inline checks in both sniffAudioMimeType and
hasKnownHeader with a call to the new utility to avoid duplication and improve
maintainability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@functions/src/funcs/tts.ts`:
- Around line 51-64: The MP3 frame-sync detection in sniffAudioMimeType
duplicates logic in encodeMp3.ts's hasKnownHeader; extract that predicate into a
shared utility (e.g., isMp3FrameSync) and replace the inline checks in both
sniffAudioMimeType and hasKnownHeader with a call to the new utility to avoid
duplication and improve maintainability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 226f805a-802a-43a9-bec0-b8fc335c6c62

📥 Commits

Reviewing files that changed from the base of the PR and between 5018b22 and 1b81558.

📒 Files selected for processing (2)
  • functions/src/funcs/tts.ts
  • functions/src/utils/encodeMp3.ts

@TinyKitten
TinyKitten merged commit ff72342 into dev Mar 7, 2026
3 checks passed
@TinyKitten
TinyKitten deleted the claude/increase-tts-volume-RrStk branch March 7, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants