Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/utils/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,25 @@ describe('utils/normalize.ts', () => {
expect(normalizeRomanText('Keiseibus')).toBe('Keiseibus');
});

it('replaces Seibu with a spelling English TTS reads as せいぶ', () => {
expect(
normalizeRomanText('Change here for the Seibu Ikebukuro Line.')
).toBe('Change here for the Say-boo Ikebukuro Line.');
expect(normalizeRomanText('The next station is Seibu-Shinjuku.')).toBe(
'The next station is Say-boo-shinjuku.'
);
// 西武園 (Seibuen) は 1 語なので語単位の一致では対象外
expect(normalizeRomanText('Seibuen')).toBe('Seibuen');
});

it('keeps Kay-say stable when normalized twice', () => {
// 二重に適用しても結果が変わらないこと(キャッシュキーの安定性)
expect(normalizeRomanText(normalizeRomanText('Keisei Main Line'))).toBe(
'Kay-say Main Line'
);
expect(normalizeRomanText(normalizeRomanText('Seibu Shinjuku Line'))).toBe(
'Say-boo Shinjuku Line'
);
});

it.each(['Tokyo', 'tOkyo'])('text: %s', (text) => {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ const normalizeTextNode = (text: string): string =>
// 明治神宮前駅等の駅名にバッククォートが含まれる場合があるため除去
.replace(/`/g, '')
.replace(/JR/gi, 'J-R')
// 「Keisei(京成)」は英語 TTS が "ei" を /aɪ/ と推定して「かいせい」と読むため、
// 英単語 "Kay" + "say" で /keɪ.seɪ/(けいせい)を確定させる。読み替え先を
// 「Keisei(京成)」「Seibu(西武)」は英語 TTS が "ei" を /aɪ/ と推定して
// 「かいせい」「さいぶ」と読むため、英単語 "Kay" + "say" / "Say" + "boo" で
// /keɪ.seɪ/(けいせい)/ /seɪ.buː/(せいぶ)を確定させる。読み替え先を
// 未知語の綴りにすると G2P の推定に戻ってエンジンごとに結果がぶれるので、
// 辞書語のハイフン連結にする。単語境界で一致させ、Keisei-Ueno のような
// ハイフン連結の駅名も語単位で置換する
.replace(/\bKeisei\b/gi, 'Kay-say')
.replace(/\bSeibu\b/gi, 'Say-boo')
// 都営バスを想定
.replace(/\bSta\./gi, ' Station')
.replace(/\bUniv\./gi, ' University')
Expand Down
Loading