Skip to content

phonemeタグの内側テキストをひらがなに変更 - #5606

Merged
TinyKitten merged 3 commits into
devfrom
feature/phoneme-tag-hiragana-inner-text
Mar 15, 2026
Merged

TinyKitten merged 3 commits into
devfrom
feature/phoneme-tag-hiragana-inner-text

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 15, 2026 •

Copy link
Copy Markdown
Member

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

  • typecheckパス確認済み (npx tsc --noEmit)
  • biome check適用済み
  • TTS再生時にphonemeタグの発音が正しくIPA通りになることを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 新機能

    • 駅名・路線名のカタカナ表記が案内文や放送で利用可能になりました。
  • 改善

    • 日本語・英語の案内テンプレート(次駅、到着、接続/経由、終点など)でカタカナ表記が反映され、発話や表示がより自然になりました。
    • 放送文や終わりの案内で公共名のカタカナ版が適切に参照されます。

@github-actions github-actions Bot added the react label Mar 15, 2026
@TinyKitten TinyKitten self-assigned this Mar 15, 2026
@coderabbitai

coderabbitai Bot commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

TTS生成ロジックに駅名のカタカナ表記(nameKatakana)を渡してphonemeラップに反映するようにし、関連テンプレート群と依存配列を更新、phonemeユーティリティにnameKatakanaオプションを追加(公開API不変)。

Changes

Cohort / File(s) Summary
TTS テキスト生成テンプレート拡張
src/hooks/useTTSText.ts
NEXT/ARRIVING/終点/乗換/接続路線/経由など多数テンプレートで ph(...) 呼び出しを三引数(最後に nameKatakana)へ拡張。nextStation/name/currentLine/via 等の nameKatakana を伝搬し、memo 依存配列に nextStationKatakana 等を追加。null/空文字の扱いも条件変更。
音素ラッピング関数の拡張
src/utils/phoneme.ts
wrapPhoneme(nameRoman, nameRomanIpa, nameKatakana?) を追加。nameRomanIpa がある場合は nameKatakana をひらがなに変換して内部テキストに使う分岐を導入。既存挙動は維持。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • TTS系の修正 #4049: 同ファイル src/hooks/useTTSText.ts の TTS 生成変更と重複する可能性が高い。
  • TTS IPA追加 #4436: 駅名のIPA/カナ出力周りのphoneme処理を変更しており密接に関連。
  • TTS修正 #4195: replaceJapaneseText の空値/フォールバック挙動を扱っており、変更箇所がオーバーラップする。

詩

🐰🎤 カタカナ跳ねて箱庭で、
駅名の音がふわり聞こえる、
ひらがな抱えて phonemeは歌い、
レールの先に声が届くよ、
うさぎは拍手で見送るよ 🚄✨

🚥 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 プルリクエストのタイトルは、変更内容の主要な点を正確に反映しており、phonemeタグ内のテキストをカタカナからひらがなに変更するという明確で具体的な説明となっています。
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 (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/phoneme-tag-hiragana-inner-text
📝 Coding Plan
  • Generate coding plan for human review comments

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

@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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c3d373 and f328b8a.

📒 Files selected for processing (2)
  • src/hooks/useTTSText.ts
  • src/utils/phoneme.ts

Comment thread src/hooks/useTTSText.ts Resolved
Comment thread src/hooks/useTTSText.ts Resolved
Comment thread src/hooks/useTTSText.ts Resolved

@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/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

📥 Commits

Reviewing files that changed from the base of the PR and between f328b8a and fba699c.

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

@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)
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

📥 Commits

Reviewing files that changed from the base of the PR and between fba699c and 8911cad.

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

@TinyKitten
TinyKitten merged commit ffde6b1 into dev Mar 15, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/phoneme-tag-hiragana-inner-text branch March 15, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant