diff --git a/src/utils/normalize.test.ts b/src/utils/normalize.test.ts index 63948d1..40e7ac7 100644 --- a/src/utils/normalize.test.ts +++ b/src/utils/normalize.test.ts @@ -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) => { diff --git a/src/utils/normalize.ts b/src/utils/normalize.ts index c777663..cfd4deb 100644 --- a/src/utils/normalize.ts +++ b/src/utils/normalize.ts @@ -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')