Skip to content

駅名のカッコ書きを TTS で読み上げないように案内テンプレへ渡す前に取り除く (#1175) - #5926

Merged
TinyKitten merged 2 commits into
devfrom
fix/tts-strip-station-name-parens
May 11, 2026
Merged

TinyKitten merged 2 commits into
devfrom
fix/tts-strip-station-name-parens

Conversation

@TinyKitten

@TinyKitten TinyKitten commented May 11, 2026 •

Copy link
Copy Markdown
Member

概要

駅名に併記されたカッコ書き (例: 命名権スポンサー名 電鉄富山(トヨタモビリティ富山)) が TTS で読み上げられてしまう問題を修正する。<sub alias="..."> の中身 (= 実際に音声化される読み) にもスポンサー名が混入していたため、案内テンプレに渡す前段で駅データの TTS 関連フィールドからカッコと中身を取り除く方針に切り替える。表示用データには影響させない。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • src/hooks/tts/formatters.ts に TTS 専用ヘルパを追加。
    • stripParensForTTS(value): 半角・全角両対応で文字列からカッコと中身を取り除く。既存の parenthesisRegexp は半角のみで駅 API が全角を返すケースをカバーできないため別定義。
    • stripStationParensForTTS(station): name / nameKatakana / nameRoman / nameTtsSegments[].surface / fallbackText をまとめて落とした新しい Station を返す (非破壊)。
  • src/hooks/useTTSText.ts: nextStation / slicedStations / afterNextStation を stripStationParensForTTS 経由に。allStops / viaStation / lastAnnouncedStop / betweenNextStation も自動的にカバーされる。
  • src/hooks/useBusTTSText.ts: 同様に適用。あわせて slicedStations を useMemo 化し、型ガードも s is Station で明示。
  • テスト追加:
    • src/hooks/tts/formatters.test.ts: 文字列ヘルパ (半角/全角/複数/非対象) と Station ヘルパ (各フィールド適用 / 非 TTS フィールド保持 / 非破壊) を検証。
    • src/hooks/useTTSText.test.tsx: (トヨタモビリティ富山) を含む駅をモックし、JA/EN SSML にカッコと中身が出ない integration テストを追加。

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

Closes TrainLCD/Issues#1175

スクリーンショット(任意)

Summary by CodeRabbit

  • バグ修正

    • 駅名の括弧(半角・全角)で囲まれたスポンサー等の文言が音声読み上げで発話されないよう改善しました。駅名(日本語表記・カタカナ・ローマ字)やTTS用セグメント、経路案内文(bound 表現)など読み上げ対象の各所で適用されます。
  • テスト

    • 括弧除去の動作を網羅するテストを追加し、日本語・英語の生成SSMLで括弧内が除外されることを検証しました。

Review Change Stack

@TinyKitten TinyKitten self-assigned this May 11, 2026
@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f6c5bf9-4b3d-4b2e-bfba-e363ecb0e298

📥 Commits

Reviewing files that changed from the base of the PR and between f905f09 and 848937c.

📒 Files selected for processing (4)
  • src/hooks/tts/formatters.test.ts
  • src/hooks/tts/formatters.ts
  • src/hooks/useBusTTSText.ts
  • src/hooks/useTTSText.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/hooks/tts/formatters.ts
  • src/hooks/tts/formatters.test.ts

📝 Walkthrough

Walkthrough

TTS音声出力時に駅名から括弧内テキスト(スポンサー表記など)を除外するフォーマッター機能を実装。新しいstripParensForTTSとstripStationParensForTTSを追加し、useBusTTSTextおよびuseTTSTextの駅オブジェクト処理に統合。関連テストで括弧除外と音声出力の整合性を確認。

Changes

駅名括弧除外フォーマッター

Layer / File(s) Summary
文字列フォーマッター実装
src/hooks/tts/formatters.ts
半角・全角括弧の両方を処理する正規表現とジェネリック関数stripParensForTTSを追加。null/undefinedを型保持しながら括弧で囲まれたテキストを除外。
駅オブジェクトフォーマッター
src/hooks/tts/formatters.ts
TtsSegmentの内部ヘルパーとstripStationParensForTTSを実装。駅の名前フィールド3種類とTtsSegments内の各surface/fallbackTextから括弧を一括除外。
フォーマッター単体テスト
src/hooks/tts/formatters.test.ts
stripParensForTTSとstripStationParensForTTSの単体テストを追加。括弧処理、複数グループ対応、null/undefined処理、非破壊性を検証。
バスTTS統合
src/hooks/useBusTTSText.ts
nextStation、slicedStations、afterNextStationの駅オブジェクトに括弧除外を適用。メモ化によってテンプレートレンダリングロジックは変更なし。
メインTTS統合
src/hooks/useTTSText.ts
useTTSText内で同様に駅オブジェクトに括弧除外を適用。停車駅リストと駅間表示のTTS音声出力から括弧内テキストを除外。
TTS統合テスト
src/hooks/useTTSText.test.tsx
issue #1175対応テスト。括弧付き駅名でJA/EN両SSMLが括弧文字と括弧内テキストを含まないことを確認。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22分

Poem

小さな兎の歌 🐇
括弧の中の文字はそっと消して
駅名は清らかに口をつむぐ
スポンサーは心に、声は澄んで
さあ行こう、きれいな放送へ

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR タイトルは、駅名のカッコ書きを TTS で読み上げないように取り除くという主要な変更内容を簡潔かつ明確に記述しており、課題番号 #1175 も含まれている。
Description check ✅ Passed PR説明は提供されたテンプレートの要素をほぼすべて含んでおり、概要、変更の種類、変更内容、テスト実施状況、関連Issueが記載されている。
Linked Issues check ✅ Passed PR の変更内容は Issue #1175 の要件を満たしており、駅名のカッコ書き(スポンサー表記)を TTS で読み上げないようにする実装が行われている。
Out of Scope Changes check ✅ Passed すべての変更は Issue #1175 の要件に直結しており、TTS からカッコ書きを除去するための実装、テスト、およびバスルート案内への適用に限定されている。
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 fix/tts-strip-station-name-parens

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

@github-actions github-actions Bot added the react label May 11, 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.

Actionable comments posted: 2

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)

189-220: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

directionalStops 経路が未対応のため、括弧読み上げが残る可能性があります。

nextStation 系の前処理は入っていますが、boundForJa / boundForEn は未加工の directionalStops を使っています。駅名括弧が方面案内側で再混入するため、同様に stripStationParensForTTS を適用してください。

🤖 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/useTTSText.ts` around lines 189 - 220, The directionalStops path
isn't being preprocessed so station-name parentheses can reappear in
boundForJa/boundForEn; update the code that builds boundForJa and boundForEn to
use a preprocessed directionalStops array (apply stripStationParensForTTS to
each entry) similar to how nextStation/afterNextStation/slicedStations are
handled — create a memoized strippedDirectionalStops from directionalStopsOrigin
(or wherever directionalStops comes from) using stripStationParensForTTS and
then reference that strippedDirectionalStops when computing boundForJa and
boundForEn.
🧹 Nitpick comments (1)
src/hooks/useTTSText.test.tsx (1)

769-832: ⚡ Quick win

全角カッコの統合テストも追加しておくと回帰耐性が上がります。

現在は半角 ( ) 中心の検証なので、実運用で問題になりやすい ( ) を useTTSText 経路でも1ケース押さえるのを推奨します。

🤖 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/useTTSText.test.tsx` around lines 769 - 832, Add a complementary
test case that covers full-width Japanese parentheses so regressions are caught:
either extend buildStationWithParens to also return a variant using full-width
brackets `(` `)` or add a new helper (e.g., buildStationWithFullWidthParens) and
a new test in the same describe block that calls useTTSTextWithJotaiAndNumbering
(the hook under test) and asserts the JA and EN SSML (result.current.text) do
not contain the full-width contents or the full-width paren characters; update
test names to reflect full-width coverage and keep assertions analogous to the
existing half-width checks.
🤖 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/tts/formatters.ts`:
- Around line 12-15: stripParensForTTS currently removes parentheses via
ttsParensRegexp but leaves trailing or consecutive spaces, producing awkward TTS
output; update stripParensForTTS to, after applying ttsParensRegexp, collapse
multiple whitespace to a single space and trim leading/trailing spaces (e.g. use
replace(/\s+/g, ' ') and trim()) while preserving the generic return type T and
handling null/undefined the same way so callers like nameRoman or
nameTtsSegments get normalized strings.

In `@src/hooks/useBusTTSText.ts`:
- Around line 120-146: directionalStops used by boundForJa/boundForEn is not
sanitized for TTS and still contains parenthesized station names; apply the same
sanitization (use stripStationParensForTTS) to directionalStops before
boundForJa/boundForEn consume it. Locate where directionalStops is
created/derived in useBusTTSText (similar to slicedStationsOrigin handling) and
map each station through stripStationParensForTTS (preserving types and nullable
handling like nextStation/afterNextStation) so boundForJa and boundForEn always
receive sanitized station objects.

---

Outside diff comments:
In `@src/hooks/useTTSText.ts`:
- Around line 189-220: The directionalStops path isn't being preprocessed so
station-name parentheses can reappear in boundForJa/boundForEn; update the code
that builds boundForJa and boundForEn to use a preprocessed directionalStops
array (apply stripStationParensForTTS to each entry) similar to how
nextStation/afterNextStation/slicedStations are handled — create a memoized
strippedDirectionalStops from directionalStopsOrigin (or wherever
directionalStops comes from) using stripStationParensForTTS and then reference
that strippedDirectionalStops when computing boundForJa and boundForEn.

---

Nitpick comments:
In `@src/hooks/useTTSText.test.tsx`:
- Around line 769-832: Add a complementary test case that covers full-width
Japanese parentheses so regressions are caught: either extend
buildStationWithParens to also return a variant using full-width brackets `(`
`)` or add a new helper (e.g., buildStationWithFullWidthParens) and a new test
in the same describe block that calls useTTSTextWithJotaiAndNumbering (the hook
under test) and asserts the JA and EN SSML (result.current.text) do not contain
the full-width contents or the full-width paren characters; update test names to
reflect full-width coverage and keep assertions analogous to the existing
half-width checks.
🪄 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: 1de08e57-484b-4b1f-a9de-21a3cbb1532a

📥 Commits

Reviewing files that changed from the base of the PR and between 6c9109e and f905f09.

📒 Files selected for processing (5)
  • src/hooks/tts/formatters.test.ts
  • src/hooks/tts/formatters.ts
  • src/hooks/useBusTTSText.ts
  • src/hooks/useTTSText.test.tsx
  • src/hooks/useTTSText.ts

Comment thread src/hooks/tts/formatters.ts Resolved
Comment thread src/hooks/useBusTTSText.ts Resolved
@TinyKitten

TinyKitten commented May 11, 2026 •

Copy link
Copy Markdown
Member Author

Fixes Applied Successfully

CodeRabbit のレビュースレッド 2 件に対する修正を適用しました。

Files modified:

  • src/hooks/tts/formatters.ts
  • src/hooks/tts/formatters.test.ts
  • src/hooks/useTTSText.ts
  • src/hooks/useBusTTSText.ts

反映内容:

  • 指摘 1 (stripParensForTTS の空白): 括弧除去後に連続空白の畳み込みと両端トリムを入れ、nameRoman などで残る不自然な空白が読み上げに乗らないようにした
  • 指摘 2 (directionalStops 未サニタイズ): stripStationParensForTTS を通してから boundForJa / boundForEn に渡すよう変更。useBusTTSText.ts だけでなく同じパターンを抱えていた useTTSText.ts にも適用
  • 既存テストの末尾スペース期待値の更新と、空白正規化を確認する追加ケース

Commit: 848937cd3

The latest autofix changes are on the fix/tts-strip-station-name-parens branch.

@TinyKitten
TinyKitten merged commit 1dfbe0d into dev May 11, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the fix/tts-strip-station-name-parens branch May 11, 2026 01:27
This was referenced May 11, 2026
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