Skip to content

TTS関数でStandard音声以外を既定値へフォールバックする - #5657

Merged
TinyKitten merged 1 commit into
devfrom
codex/fix-tts-standard-voice-fallback
Mar 23, 2026
Merged

TinyKitten merged 1 commit into
devfrom
codex/fix-tts-standard-voice-fallback

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 23, 2026 •

Copy link
Copy Markdown
Member

概要

  • TTS関数でStandard音声名だけを許可するよう修正
  • リクエスト値やFirestore設定値がStandard以外なら既定のStandard音声へフォールバック
  • 音声選択ロジックの単体テストを追加

リスク

  • FirestoreにStandard以外の音声名が残っていても既定のStandard音声で再生される
  • 音声の種類は減るが、model指定不足による400は回避できる

確認

  • npm test -- --runInBand src/utils/ttsVoice.test.ts
  • npx tsc -p tsconfig.json --noEmit # 既存のテストファイル重複定義で失敗

Summary by CodeRabbit

リリースノート

  • Refactor

    • テキスト読み上げシステムの音声名処理ロジックを最適化しました。
  • Tests

    • 音声名の検証と解決処理に関する包括的なテストスイートを追加しました。

@coderabbitai

coderabbitai Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

ウォークスルー

TTS音声名の解決ロジックを専用のユーティリティ関数に抽出しました。新しいttsVoice.tsモジュールにisStandardVoiceNameとresolveStandardVoiceNameを追加し、リクエスト値、設定値、デフォルト値のフォールバック処理を統一化しました。既存のTTS処理フロー(キャッシュ検索、音声合成、パブリッシュ)は変更なし。

変更内容

コホート / ファイル(s) 概要
新しいユーティリティモジュール
functions/src/utils/ttsVoice.ts
標準音声名の判定と解決を行う2つの関数を追加。isStandardVoiceNameは音声名が-Standard-マーカーを含むかチェック、resolveStandardVoiceNameはリクエスト値→設定値→デフォルト値の優先度でフォールバック処理を実施。
ユーティリティのテスト
functions/src/utils/ttsVoice.test.ts
3つのテストケースで新しいユーティリティ関数の動作をカバー。標準音声名の判定、有効なリクエスト時の選択、無効時のフォールバック処理を検証。
TTS処理の簡略化
functions/src/funcs/tts.ts
jaVoiceNameとenVoiceNameの解決ロジックをインラインからresolveStandardVoiceName呼び出しに変更。音声名の後処理(ハッシング、キャッシュ参照、合成、パブリッシュ)は継続。

推定レビュー工数

🎯 2 (Simple) | ⏱️ ~10 分

ポエム

🐰 ウサギが新しく声の扉を整理した
フォールバック、検証、すべてきれい
リクエストから設定、デフォルトへと流れて
音声選びもスムーズに✨
テストは完璧、安心安全だね🎵

🚥 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関数でStandard音声以外を既定値へフォールバックするという主要な変更内容を明確に説明しており、変更セットの中心的な目的と一致しています。
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
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-tts-standard-voice-fallback

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

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

🧹 Nitpick comments (1)
functions/src/utils/ttsVoice.test.ts (1)

6-43: エッジケースのテスト追加を検討してください。

現在のテストは主要なシナリオをカバーしていますが、resolveStandardVoiceName の堅牢性を確認するために、以下のエッジケースの追加を推奨します:

  • 空文字列 '' の入力
  • 空白のみ ' ' の入力
  • null や undefined の入力
🧪 追加テスト例
+  it('handles empty and whitespace-only inputs', () => {
+    expect(
+      resolveStandardVoiceName('', '', 'en-US-Standard-G')
+    ).toBe('en-US-Standard-G');
+    expect(
+      resolveStandardVoiceName('  ', '  ', 'en-US-Standard-G')
+    ).toBe('en-US-Standard-G');
+  });
+
+  it('handles null and undefined inputs', () => {
+    expect(
+      resolveStandardVoiceName(null, undefined, 'en-US-Standard-G')
+    ).toBe('en-US-Standard-G');
+  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@functions/src/utils/ttsVoice.test.ts` around lines 6 - 43, Add tests for
resolveStandardVoiceName and isStandardVoiceName covering empty string,
whitespace-only, null, and undefined inputs; specifically, assert that
isStandardVoiceName returns false for '' and '  ' and that
resolveStandardVoiceName treats '' / '  ' / null / undefined as invalid requests
(falling back to the configured standard voice parameter or ultimately to the
provided defaultStandardVoice), and include cases where requestedVoice is
null/undefined and configuredVoice is valid, and where both are null/invalid to
confirm defaultStandardVoice is returned. Ensure you add new it blocks in the
ttsVoice test suite referencing isStandardVoiceName and resolveStandardVoiceName
so behavior for these edge cases is verified.
🤖 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/utils/ttsVoice.test.ts`:
- Around line 6-43: Add tests for resolveStandardVoiceName and
isStandardVoiceName covering empty string, whitespace-only, null, and undefined
inputs; specifically, assert that isStandardVoiceName returns false for '' and '
' and that resolveStandardVoiceName treats '' / '  ' / null / undefined as
invalid requests (falling back to the configured standard voice parameter or
ultimately to the provided defaultStandardVoice), and include cases where
requestedVoice is null/undefined and configuredVoice is valid, and where both
are null/invalid to confirm defaultStandardVoice is returned. Ensure you add new
it blocks in the ttsVoice test suite referencing isStandardVoiceName and
resolveStandardVoiceName so behavior for these edge cases is verified.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ebda0078-3c10-4db8-8f25-2e915a5879d9

📥 Commits

Reviewing files that changed from the base of the PR and between f7dbfcc and e7bf71d.

📒 Files selected for processing (3)
  • functions/src/funcs/tts.ts
  • functions/src/utils/ttsVoice.test.ts
  • functions/src/utils/ttsVoice.ts

@TinyKitten
TinyKitten merged commit 41aa438 into dev Mar 23, 2026
4 checks passed
@TinyKitten
TinyKitten deleted the codex/fix-tts-standard-voice-fallback branch March 23, 2026 16:36
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