Skip to content

TTS合成をCloud Text-to-Speech Gemini TTSモデルに統一 - #5590

Merged
TinyKitten merged 2 commits into
devfrom
feature/gemini-tts-unification
Mar 12, 2026
Merged

TinyKitten merged 2 commits into
devfrom
feature/gemini-tts-unification

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • TTS合成バックエンドをVertex AI Gemini + Google Cloud TTS API(APIキー方式)からCloud Text-to-Speech API(OAuth認証 + Gemini TTSモデル)に統一
  • 日本語音声もGemini TTSモデルに移行し、鉄道自動放送スタイルのプロンプトを追加
  • 日本語音声名のカスタマイズUIをTuningSettingsに追加
  • 不要になったユーティリティ(encodeMp3.ts, legacyIpa.ts, ssml.ts)を削除
  • 再生タイムアウトを60秒→300秒に延長(長い路線放送対応)
  • キャッシュバージョンを9に更新

Test plan

  • TTS音声合成が日本語・英語ともに正常に動作すること
  • TuningSettingsから日本語音声名を変更でき、次回合成に反映されること
  • キャッシュミス時に新規合成→キャッシュ保存が正常に行われること
  • 長時間の路線放送でタイムアウトしないこと

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 新機能

    • 設定画面に日本語TTS音声選択機能を追加しました。
  • 改善

    • 再生のタイムアウト時間を延長し、再生安定性を向上しました。
    • TTS合成処理を刷新し、音声出力の安定性やフォールバック動作を改善しました。
  • リファクタリング

    • 旧SSMLユーティリティ、レガシーIPA置換、および古い音声エンコード関連コードを整理・削除しました。

@coderabbitai

coderabbitai Bot commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7eb2095f-e051-4535-b4f1-0ad653749257

📥 Commits

Reviewing files that changed from the base of the PR and between aa1be1e and 1dec4f3.

📒 Files selected for processing (1)
  • src/hooks/useTTS.test.ts

📝 Walkthrough

Walkthrough

Google VertexAI/Google TTS から Gemini TTS へ移行し、GoogleAuth トークン取得を導入。不要な MP3 エンコーダ、IPA/SSML ユーティリティと関連テストを削除。フロントエンドに日本語音声選択を追加し、再生タイムアウトを延長。

Changes

Cohort / File(s) Summary
Gemini TTS 統合の置き換え
functions/src/funcs/tts.ts
VertexAI/Google TTS を廃止し、GoogleAuth によるトークン取得と Gemini ベースの合成フローへ移行。synthesizeWithGemini の署名変更(languageCode、options)、mime タイプ算出、キャッシュペイロード形状更新、バージョン番号調整など。
削除されたユーティリティ
functions/src/utils/encodeMp3.ts, functions/src/utils/legacyIpa.ts, src/utils/ssml.ts, src/utils/ssml.test.ts
MP3 エンコード、レガシーIPA置換、SSMLビルダーAPIおよびそのテストを削除。関連ヘルパー(ensureMp3, numberToEnglishWord 等)も削除。
フロントエンド: 日本語音声選択の追加
src/components/TuningSettings.tsx
AsyncStorage から ja/en の音声名を並行取得し、ttsJaVoiceName の状態と handleJaVoiceNameChange を追加。日本語音声選択UI(ピッカー)を導入。
再生タイムアウト延長
src/hooks/useTTS.ts, src/hooks/useTTS.test.ts
PLAYBACK_TIMEOUT_MS を 60000ms から 300000ms に延長。テストのタイムアウトも同様に更新。

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client as Client (App)
    participant CF as Cloud Function (tts.ts)
    participant Auth as GoogleAuth
    participant Gemini as Gemini TTS API
    participant Store as Firestore/Storage
    participant PubSub as Pub/Sub (cache publish)

    Client->>CF: TTS リクエスト (text, languageCode, voiceName, options)
    CF->>Auth: アクセストークン取得
    Auth-->>CF: access_token
    CF->>Gemini: 音声合成リクエスト (token, ssml/text, modelName, options)
    Gemini-->>CF: 合成オーディオ (raw bytes, mimeType?)
    CF->>Store: キャッシュ用メタデータ保存/取得
    CF->>PubSub: 合成完了ペイロード公開 (audio, mimeType, metadata)
    CF-->>Client: 合成結果レスポンス (audioURL/bytes, mimeType, metadata)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 小さな耳で聴いたよ、Gemini の歌
古いMP3とIPAはひと休み
日本語の声、選べるようにしたよ
長く待つタイムアウトは安心の毛布
さぁ、新しい声で走ろう 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトル「TTS合成をCloud Text-to-Speech Gemini TTSモデルに統一」は、変更セットの主な目的を正確かつ簡潔に説明しており、TTS実装をVertex AIおよびGoogle Cloud TTS APIからGemini TTSモデルへの統一という中核的な変更を明確に反映している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 feature/gemini-tts-unification

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

@TinyKitten TinyKitten self-assigned this Mar 12, 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/useTTS.ts (1)

90-102: ⚠️ Potential issue | 🟠 Major

旧AsyncStorageの音声名が無検証でGemini-TTSに送信され、アップグレード直後に合成が失敗します。

AsyncStorage に保存された旧Cloud TTS の voice id(例:ja-JP-Standard-B、en-US-Standard-C)が、フロントエンドで無検証に復元され、バックエンドに送信されます。バックエンドは受け取った音声名をそのまま Gemini-TTS API に渡していますが、Gemini-TTS は 30個の事前定義された voice 名(Aoede、Achernar など)のみを受け入れるため、既存ユーザーがアップデート直後に合成を実行すると API エラーが発生します。

復元時に既知の旧 voice id を Gemini 互換の名前へマイグレーションするか、許可リストでフィルタリングしてください。

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

In `@src/hooks/useTTS.ts` around lines 90 - 102, The stored AsyncStorage voice ids
(ASYNC_STORAGE_KEYS.TTS_JA_VOICE_NAME / ASYNC_STORAGE_KEYS.TTS_EN_VOICE_NAME)
may be legacy Cloud TTS ids and must be validated/migrated before restoring into
state; update the useEffect in useTTS.ts to pass loaded jaVoice/enVoice through
a migration/validation step (e.g., call migrateOldVoiceIdToGemini(voice) which
maps known legacy ids like "ja-JP-Standard-B" → "Aoede" or similar) and/or
filter against a VOICE_ALLOWLIST (isAllowedGeminiVoice) and only set
ttsJaVoiceName/ttsEnVoiceName if the result is a valid Gemini name, otherwise
use '' or a safe default; add the helper mapping/allowlist functions/constants
and ensure setTuning receives the migrated/validated names.
🧹 Nitpick comments (1)
functions/src/funcs/tts.ts (1)

209-218: キャッシュキーにプロンプトと言語コードも含めておくと安全です。

今回の出力は languageCode と prompt に強く依存していますが、ハッシュ対象は text/voice/version だけです。将来ここを調整したときに version の上げ忘れで古い音声を返し続けるので、実際の合成パラメータをそのままキーに入れておく方が保守しやすいです。

🤖 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 209 - 218, hashPayloadObj currently
hashes {enModel: GEMINI_TTS_MODEL, enVoiceName, jaVoiceName, ssmlEn, ssmlJa,
version} which misses the actual prompt and languageCode used for synthesis;
update the payload used for hashing (the object assigned to hashPayloadObj
referenced alongside hashAlgorithm and version) to include prompt and
languageCode (and any other synthesis params like speakingRate/pitch if present)
so the cache key uniquely reflects the real input parameters that affect output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/hooks/useTTS.ts`:
- Around line 90-102: The stored AsyncStorage voice ids
(ASYNC_STORAGE_KEYS.TTS_JA_VOICE_NAME / ASYNC_STORAGE_KEYS.TTS_EN_VOICE_NAME)
may be legacy Cloud TTS ids and must be validated/migrated before restoring into
state; update the useEffect in useTTS.ts to pass loaded jaVoice/enVoice through
a migration/validation step (e.g., call migrateOldVoiceIdToGemini(voice) which
maps known legacy ids like "ja-JP-Standard-B" → "Aoede" or similar) and/or
filter against a VOICE_ALLOWLIST (isAllowedGeminiVoice) and only set
ttsJaVoiceName/ttsEnVoiceName if the result is a valid Gemini name, otherwise
use '' or a safe default; add the helper mapping/allowlist functions/constants
and ensure setTuning receives the migrated/validated names.

---

Nitpick comments:
In `@functions/src/funcs/tts.ts`:
- Around line 209-218: hashPayloadObj currently hashes {enModel:
GEMINI_TTS_MODEL, enVoiceName, jaVoiceName, ssmlEn, ssmlJa, version} which
misses the actual prompt and languageCode used for synthesis; update the payload
used for hashing (the object assigned to hashPayloadObj referenced alongside
hashAlgorithm and version) to include prompt and languageCode (and any other
synthesis params like speakingRate/pitch if present) so the cache key uniquely
reflects the real input parameters that affect output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b32a0734-5b10-4afa-be74-269c3921df95

📥 Commits

Reviewing files that changed from the base of the PR and between 30abddf and aa1be1e.

📒 Files selected for processing (7)
  • functions/src/funcs/tts.ts
  • functions/src/utils/encodeMp3.ts
  • functions/src/utils/legacyIpa.ts
  • src/components/TuningSettings.tsx
  • src/hooks/useTTS.ts
  • src/utils/ssml.test.ts
  • src/utils/ssml.ts
💤 Files with no reviewable changes (4)
  • functions/src/utils/legacyIpa.ts
  • functions/src/utils/encodeMp3.ts
  • src/utils/ssml.test.ts
  • src/utils/ssml.ts

@TinyKitten
TinyKitten merged commit c30fade into dev Mar 12, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/gemini-tts-unification branch March 12, 2026 03:33
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.

1 participant