Repository navigation
phonemeタグの内側テキストをひらがなに変更 - #5606
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 WalkthroughWalkthroughTTS生成ロジックに駅名のカタカナ表記(nameKatakana)を渡してphonemeラップに反映するようにし、関連テンプレート群と依存配列を更新、phonemeユーティリティにnameKatakanaオプションを追加(公開API不変)。 Changes
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)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/hooks/useTTSText.ts`:
- Around line 1095-1098: The ph() call that constructs the after-next station
text is missing the third (katakana) argument; update the expression where you
call ph(afterNextStation.nameRoman, afterNextStation.nameRomanIpa) to include
afterNextStation.nameKatakana as the third parameter (matching the JR_WEST
usage), ensuring the ternary that appends 'the last stop' still uses
isAfterNextStopTerminus and nextStation?.nameRoman/nameRomanIpa remain
unchanged.
- Around line 892-895: The TTS sentence construction calls ph(...) for
afterNextStation but omits the 3rd argument (katakana) similar to the
TOKYO_METRO bug; update the ph invocation that uses afterNextStation (inside
useTTSText.ts) to pass afterNextStation.nameKatakana as the third parameter so
ph(afterNextStation.nameRoman, afterNextStation.nameRomanIpa,
afterNextStation.nameKatakana) matches other station ph calls.
- Around line 814-817: The template call for afterNextStation is missing the
third (katakana) argument causing inconsistency with nextStation; update the
ph(...) invocation for afterNextStation to pass afterNextStation?.nameKatakana
as the third parameter (same pattern used by nextStation) within the string that
builds the "next stop" TTS, ensuring you still reference ph, nextStation,
afterNextStation and isAfterNextStopTerminus.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dc45ffc4-46b9-423a-9da7-01519be12407
📒 Files selected for processing (2)
src/hooks/useTTSText.tssrc/utils/phoneme.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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/useTTSText.ts (1)
104-113:⚠️ Potential issue | 🟠 Major
replaceJapaneseText()がnameKatakana欠損時に誤案内へフォールバックします。
nameがあるのにnameKatakanaだけ欠けたケースでも、Line 109-110 で各駅停車に置き換わります。駅名・路線名・会社名まで同じフォールバックになるので、ここは各駅停車を返すのではなくnameをそのまま返すか、フォールバックを呼び出し側で分けた方が安全です。🔧 修正例
const replaceJapaneseText = useCallback( - ( - name: string | undefined | null, - nameKatakana: string | undefined | null - ) => - !name || !nameKatakana - ? `<sub alias="かくえきていしゃ">各駅停車</sub>` - : `<sub alias="${katakanaToHiragana(nameKatakana)}">${name}</sub>`, + ( + name: string | undefined | null, + nameKatakana: string | undefined | null + ) => { + if (!name) return ''; + if (!nameKatakana) return name; + return `<sub alias="${katakanaToHiragana(nameKatakana)}">${name}</sub>`; + }, [] );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useTTSText.ts` around lines 104 - 113, The fallback in replaceJapaneseText currently returns the fixed string "<sub alias=\"かくえきていしゃ\">各駅停車</sub>" whenever nameKatakana is missing, even if name is present; change the logic in replaceJapaneseText so that if name is present but nameKatakana is missing it simply returns the raw name (i.e., no substitution), and only return the special "各駅停車" sub-alias when both name and nameKatakana are absent; keep using katakanaToHiragana(nameKatakana) when nameKatakana is present to build the <sub> element.
♻️ Duplicate comments (1)
src/hooks/useTTSText.ts (1)
787-845:⚠️ Potential issue | 🟠 Major英語テンプレートの
ph()がまだ一部 2 引数のままです。今回の変更目的だと、
nameKatakanaを渡していないph()は<phoneme>の内側テキストが旧挙動のまま残ります。Line 804, Line 809, Line 827, Line 860, Line 910, Line 1010, Line 1037, Line 1115 などが未更新で、案内文ごとに発音補助の挙動が揃っていません。残りの呼び出しも同じ 3 引数パターンに揃えたいです。Also applies to: 848-903, 905-944, 950-1061, 1064-1146
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useTTSText.ts` around lines 787 - 845, The English templates in useTTSText.ts still call ph() with only two arguments in several places (e.g., inside the NEXT and ARRIVING template strings and other speech blocks), which leaves nameKatakana out and causes inconsistent phoneme output; update every ph(nameRoman, nameRomanIpa) call to ph(nameRoman, nameRomanIpa, nameKatakana) (including calls for stations, lines, currentTrainType, afterNextStation, transferLines mapping, and any ph usages within NEXT/ARRIVING/other templates) so all phoneme helpers use the three-argument form and behavior is consistent across firstSpeech, nextStation, afterNextStation, transferLines, currentLine, and currentTrainType contexts.
🤖 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/useTTSText.ts`:
- Around line 104-113: The fallback in replaceJapaneseText currently returns the
fixed string "<sub alias=\"かくえきていしゃ\">各駅停車</sub>" whenever nameKatakana is
missing, even if name is present; change the logic in replaceJapaneseText so
that if name is present but nameKatakana is missing it simply returns the raw
name (i.e., no substitution), and only return the special "各駅停車" sub-alias when
both name and nameKatakana are absent; keep using
katakanaToHiragana(nameKatakana) when nameKatakana is present to build the <sub>
element.
---
Duplicate comments:
In `@src/hooks/useTTSText.ts`:
- Around line 787-845: The English templates in useTTSText.ts still call ph()
with only two arguments in several places (e.g., inside the NEXT and ARRIVING
template strings and other speech blocks), which leaves nameKatakana out and
causes inconsistent phoneme output; update every ph(nameRoman, nameRomanIpa)
call to ph(nameRoman, nameRomanIpa, nameKatakana) (including calls for stations,
lines, currentTrainType, afterNextStation, transferLines mapping, and any ph
usages within NEXT/ARRIVING/other templates) so all phoneme helpers use the
three-argument form and behavior is consistent across firstSpeech, nextStation,
afterNextStation, transferLines, currentLine, and currentTrainType contexts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0b4989a3-ba24-4056-9e9a-401d62db3313
📒 Files selected for processing (1)
src/hooks/useTTSText.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/hooks/useTTSText.ts (1)
1022-1035: 可読性向上のため、繰り返し計算を変数に抽出することを検討してください。
allStops.slice(0, 5).filter((s) => s).reverse()[0]がnameRoman、nameRomanIpa、nameKatakanaのために3回計算されています。useMemo内なのでパフォーマンス上の問題は軽微ですが、変数に抽出するとコードの可読性が向上します。♻️ リファクタリング案
テンプレート外で事前に計算する方法:
const lastAnnouncedStop = useMemo( () => allStops.slice(0, 5).filter((s) => s).reverse()[0], [allStops] );そして、テンプレート内で使用:
- : `Stops after ${ph( - allStops - .slice(0, 5) - .filter((s) => s) - .reverse()[0]?.nameRoman, - allStops - .slice(0, 5) - .filter((s) => s) - .reverse()[0]?.nameRomanIpa, - allStops - .slice(0, 5) - .filter((s) => s) - .reverse()[0]?.nameKatakana - )} will be announced later. ` + : `Stops after ${ph( + lastAnnouncedStop?.nameRoman, + lastAnnouncedStop?.nameRomanIpa, + lastAnnouncedStop?.nameKatakana + )} will be announced later. `🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useTTSText.ts` around lines 1022 - 1035, Extract the repeated expression allStops.slice(0, 5).filter((s) => s).reverse()[0] used in useTTSText (inside the template that references nameRoman, nameRomanIpa, nameKatakana) into a single memoized variable (e.g., lastAnnouncedStop) using useMemo with allStops as dependency, and then replace the three repeated calls in the template with that variable (accessing lastAnnouncedStop?.nameRoman, lastAnnouncedStop?.nameRomanIpa, lastAnnouncedStop?.nameKatakana) to improve readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/hooks/useTTSText.ts`:
- Around line 1022-1035: Extract the repeated expression allStops.slice(0,
5).filter((s) => s).reverse()[0] used in useTTSText (inside the template that
references nameRoman, nameRomanIpa, nameKatakana) into a single memoized
variable (e.g., lastAnnouncedStop) using useMemo with allStops as dependency,
and then replace the three repeated calls in the template with that variable
(accessing lastAnnouncedStop?.nameRoman, lastAnnouncedStop?.nameRomanIpa,
lastAnnouncedStop?.nameKatakana) to improve readability.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f88eff7e-0c4e-4fea-8864-5eb039358294
📒 Files selected for processing (1)
src/hooks/useTTSText.ts
Summary
wrapPhonemeに第3引数nameKatakanaを追加し、IPA phonemeタグ使用時の内側テキストをカタカナ→ひらがな変換した文字列に変更<phoneme alphabet="ipa" ph="ɯbe">Ube</phoneme><phoneme alphabet="ipa" ph="ɯbe">うべ</phoneme>useTTSText.tsの英語テンプレート内の全ph()呼び出しに対応するnameKatakanaを追加Test plan
npx tsc --noEmit)🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート
新機能
改善