Repository navigation
ネイティブTTSの音質向上とAndroidで英語が日本語音声で合成される問題の修正 - #6457
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HHRhvZfdgzmX8Dakjw7Dqt
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough端末のTTS音声を言語別に選択し、 ChangesネイティブTTS音声対応
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/screens/TTSSettings.tsx (1)
150-162: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
src/screens/TTSSettings.test.tsxに iOS / Android の分岐テストを追加してください
Platform.OSでttsVoiceQualityNoticeIOS/ttsVoiceQualityNoticeAndroidが切り替わるため、両ケースで正しい翻訳キーが描画されることを確認したいです。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/screens/TTSSettings.tsx` around lines 150 - 162, src/screens/TTSSettings.test.tsx に、Platform.OS が iOS の場合は ttsVoiceQualityNoticeIOS、Android の場合は ttsVoiceQualityNoticeAndroid が translate に渡されて描画されることを検証する分岐テストを追加してください。既存の TTSSettings テスト構成と Platform のモック方法を再利用し、両ケースを確認してください。Source: Coding guidelines
src/utils/nativeTtsVoice.test.ts (1)
11-46: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueテスト後にモック状態をリセットしてください。
この
.test.tsにはafterEach(() => jest.clearAllMocks())がありません。将来のモック追加時もテスト間の状態漏れを防ぐため、スイートに追加してください。
As per coding guidelines,afterEachではjest.clearAllMocks()を呼び出すこと。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/nativeTtsVoice.test.ts` around lines 11 - 46, scoreVoiceQuality テストスイートに afterEach フックを追加し、各テスト後に jest.clearAllMocks() を呼び出してモック状態をリセットしてください。Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/hooks/useTTS.ts`:
- Around line 83-106: Update the useTTS initialization and first Speech.speak
flow so the initial utterance waits for getAvailableVoicesAsync to finish, or
explicitly uses the default voice when voice IDs remain unavailable. Ensure
jaVoiceIdRef and enVoiceIdRef are not assumed initialized before the
asynchronous voice-loading effect completes.
---
Nitpick comments:
In `@src/screens/TTSSettings.tsx`:
- Around line 150-162: src/screens/TTSSettings.test.tsx に、Platform.OS が iOS の場合は
ttsVoiceQualityNoticeIOS、Android の場合は ttsVoiceQualityNoticeAndroid が translate
に渡されて描画されることを検証する分岐テストを追加してください。既存の TTSSettings テスト構成と Platform
のモック方法を再利用し、両ケースを確認してください。
In `@src/utils/nativeTtsVoice.test.ts`:
- Around line 11-46: scoreVoiceQuality テストスイートに afterEach フックを追加し、各テスト後に
jest.clearAllMocks() を呼び出してモック状態をリセットしてください。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e37ac1f8-16c1-427a-baf7-9cba3033d309
📒 Files selected for processing (7)
assets/translations/en.jsonassets/translations/ja.jsonsrc/hooks/useTTS.test.tssrc/hooks/useTTS.tssrc/screens/TTSSettings.tsxsrc/utils/nativeTtsVoice.test.tssrc/utils/nativeTtsVoice.ts
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HHRhvZfdgzmX8Dakjw7Dqt
…キップを追加 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HHRhvZfdgzmX8Dakjw7Dqt
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HHRhvZfdgzmX8Dakjw7Dqt
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HHRhvZfdgzmX8Dakjw7Dqt
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HHRhvZfdgzmX8Dakjw7Dqt
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HHRhvZfdgzmX8Dakjw7Dqt
There was a problem hiding this comment.
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)
119-131: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
voices.length > 0条件によりandroidVoicesLoadedRefが永久に false のままになりうる。
getAvailableVoicesAsync()が例外を投げずに空配列を返した場合(端末側の一時的な不具合など)、androidVoicesLoadedRef.currentは true にならず、canSpeakJa/canSpeakEnは「不明なら発話許可」にフォールバックします。結果として音声未検出時のスキップ判定が機能せず、本PRが修正対象とする「英語が日本語音声で読まれる」問題が再発する余地があります。🐛 Proposed fix
- if (Platform.OS === 'android' && voices.length > 0) { - androidVoicesLoadedRef.current = true; + if (Platform.OS === 'android') { + androidVoicesLoadedRef.current = true; if (!jaVoiceIdRef.current) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/useTTS.ts` around lines 119 - 131, Update the Android voice-loading logic in the useTTS hook so androidVoicesLoadedRef.current becomes true whenever getAvailableVoicesAsync completes successfully, including when voices is an empty array. Keep the existing voice-specific warnings and ensure canSpeakJa/canSpeakEn treat the completed empty result as unavailable rather than falling back to allowing speech.
🧹 Nitpick comments (1)
src/hooks/useTTS.ts (1)
304-334: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
Speech.speak()呼び出しを try/catch で保護してください。ループ内で
Speech.speakが同期的に例外を投げた場合、settle()が呼ばれずremainingが0に到達しないため、playingRef.currentはarmPlaybackWatchdogのタイムアウト(PLAYBACK_TIMEOUT_MS)まで解放されません。ファイル内の他箇所(Speech.stop())ではtry/catchで防御している一貫したスタイルがあるので、揃えることを推奨します。🛡️ Proposed fix
for (const utterance of utterances) { - Speech.speak(utterance.text, { - language: utterance.language, - ...(utterance.voice ? { voice: utterance.voice } : {}), - onDone: settle, - onStopped: settle, - onError: (error) => { - console.warn('[useTTS] speech error:', error); - settle(); - }, - }); + try { + Speech.speak(utterance.text, { + language: utterance.language, + ...(utterance.voice ? { voice: utterance.voice } : {}), + onDone: settle, + onStopped: settle, + onError: (error) => { + console.warn('[useTTS] speech error:', error); + settle(); + }, + }); + } catch (e) { + console.warn('[useTTS] Speech.speak failed:', e); + settle(); + } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/useTTS.ts` around lines 304 - 334, ループ内のSpeech.speak呼び出しをtry/catchで保護し、同期例外が発生した場合も既存のsettle()を必ず呼び出してremainingを減算し、再生状態を解放できるようにしてください。既存のonErrorログ・コールバック処理と、ファイル内のSpeech.stop()にある防御的な例外処理のスタイルを維持してください。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/hooks/useTTS.ts`:
- Around line 119-131: Update the Android voice-loading logic in the useTTS hook
so androidVoicesLoadedRef.current becomes true whenever getAvailableVoicesAsync
completes successfully, including when voices is an empty array. Keep the
existing voice-specific warnings and ensure canSpeakJa/canSpeakEn treat the
completed empty result as unavailable rather than falling back to allowing
speech.
---
Nitpick comments:
In `@src/hooks/useTTS.ts`:
- Around line 304-334:
ループ内のSpeech.speak呼び出しをtry/catchで保護し、同期例外が発生した場合も既存のsettle()を必ず呼び出してremainingを減算し、再生状態を解放できるようにしてください。既存のonErrorログ・コールバック処理と、ファイル内のSpeech.stop()にある防御的な例外処理のスタイルを維持してください。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9545c9a6-072c-4ce4-8cdd-9181b8e27e63
📒 Files selected for processing (5)
patches/expo-speech+55.0.16.patchsrc/hooks/useTTS.test.tssrc/hooks/useTTS.tssrc/utils/phoneme.test.tssrc/utils/phoneme.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/hooks/useTTS.test.ts
概要
OS ネイティブ TTS(expo-speech)の読み上げで、端末にインストール済みの最高品質音声(Premium / Enhanced)を自動選択するようにし、音質を可能な範囲で引き上げました。あわせて、Android で英語アナウンスが日本語音声で合成される問題を修正しました。実機調査の結果、真の根本原因は英語文への日本語表記の混入(
<phoneme>タグの表記テキストが日本語の駅データ)で、TTS エンジンが言語を誤判定していたことでした。TTS 設定画面への高品質音声の案内文追加、注意文言の更新も含みます。変更の種類
変更内容
Android で英語が日本語音声で合成される問題の修正(根本原因)
<phoneme alphabet="ipa" ph="...">表記</phoneme>は IPA 発音(ph 属性)が読まれ表記テキストは無視されていたが、ネイティブ TTS は IPA を解釈できないため表記テキストがそのまま読まれる。駅データによっては表記が日本語(例: surface が「あかさか」で fallbackText 未設定)のため、英語文が"Arriving at あかさか K 7."となり、voice を明示指定していても TTS エンジンが言語を誤判定して日本語音声で合成されていたwrapPhonemeで、セグメントから組み立てた可視テキストに日本語文字(ひらがな・カタカナ・CJK 漢字・半角カナ)が含まれる場合はセグメントを使わずローマ字名(nameRoman等の fallback)全体へフォールバックする。駅名・路線名・直通先などnameTtsSegmentsを使う全箇所に効く音質向上(音声の自動選択)
nativeTtsVoiceユーティリティを新設。Speech.getAvailableVoicesAsync()の結果から言語ごとに Premium > Enhanced > その他の優先順で音声を選び、useTTSがSpeech.speak()にvoiceを明示指定するAVSpeechSynthesisVoiceQuality.premiumを"Default"として報告するため、qualityフィールドに加えて音声識別子(com.apple.voice.premium.*等)でも品質を判定して補完voice未指定のままにし、ユーザーが OS 設定で選んだ既定音声を尊重allowDefaultQuality)。地域一致(en-US)が無ければ同一言語の別地域(en-GB 等)、ローカル優先でネットワーク必須音声は最後の手段、対象言語の音声が皆無ならその言語の発話をスキップ発話パイプラインの堅牢化
TextToSpeech#speak()は呼び出し時点の言語・音声設定を発話リクエストごとにスナップショットし、iOS のAVSpeechUtteranceも発話単位で音声を保持するため、発話ごとに異なる音声を安全に指定できる。エンジンが前の発話の再生中に次の合成を先行できるため、JA→EN 間の無音(合成待ちのラグ)が最小化されるpatches/expo-speech+55.0.16.patch): voice 指定時はsetVoiceを最優先で適用しsetLanguageとの競合を排除。voice が見つからない場合はLocale.forLanguageTagによる正しい BCP 47 解釈と言語のみ Locale への段階的フォールバックで解決(Locale(String)に地域付きタグを渡すと不正 Locale となり端末既定言語で合成される不備への対処)。音声一覧の取得失敗時など voice 未指定で発話する稀な経路の保険として維持その他
ttsAlertTextの「インターネット未接続状態では動作しません」という文言を、ネイティブ TTS の実態に合わせて更新nativeTtsVoice19 件、wrapPhonemeの日本語表記フォールバック 13 件、useTTSの音声指定・一括キュー・音声選択完了待ち・発話スキップテスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ることnpm run lint/npm run typecheck/npm test(193 スイート / 2070 件)すべてパス。日本語設定の Android 実機で、NEXT / ARRIVING 両方の英語アナウンスが英語音声で読まれることを確認済み(従来"Arriving at あかさか K 7."と日本語混入していた駅で検証)。留意点:
npm installで patch-package が適用されます)関連Issue
スクリーンショット(任意)
Summary by CodeRabbit