Repository navigation
英語TTSの音量を8dB上げる - #5537
英語TTSの音量を8dB上げる#5537
Conversation
📝 WalkthroughWalkthroughTTSのMP3エンコードフローに音量調整パラメータを追加し、Gemini出力用に8dBのボリュームブーストを適用するように変更。MP3ヘッダー判定を厳格化し、ensureMp3のシグネチャを拡張、内部キャッシュ用ハッシュバージョンを6→7に更新。 Changes
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
ポエム
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
functions/src/funcs/tts.tsfunctions/src/utils/encodeMp3.ts
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (2)
functions/src/funcs/tts.tsfunctions/src/utils/encodeMp3.ts
Summary by CodeRabbit
リリースノート
改善
修正