Repository navigation
TTS系の修正 - #4049
TTS系の修正#4049
Conversation
Walkthrough今回の変更では、 Changes
Sequence Diagram(s)sequenceDiagram
participant Client as クライアント
participant TTS as TTS関数(functions/src/index.ts)
participant Normalizer as normalizeRomanText関数
participant Logger as コンソールログ
Client->>TTS: テキストリクエスト送信
TTS->>Normalizer: normalizeRomanText(req.data.ssmlEn) 呼出
Normalizer-->>TTS: 正規化済みテキスト返却
TTS->>Logger: 加工後の ssmlEn をログ出力
TTS-->>Client: 音声合成結果返却
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
functions/src/index.ts (1)
Line range hint
146-195: 音声合成処理の保守性を改善できます。以下の改善点を提案します:
- 音素置換ルールを設定ファイルに分離
- 文字列置換をMap等を使用してより保守しやすい形に変更
- console.logの代わりに適切なロギングを使用
以下のような実装を提案します:
// phoneme-rules.ts export const PHONEME_RULES = new Map([ ['-itchome', '<phoneme alphabet="ipa" ph="itt͡ɕoːme">いっちょうめ</phoneme>'], ['-sanchome', '<phoneme alphabet="ipa" ph="sant͡ɕoːme">さんちょうめ</phoneme>'], ['Ube', '<phoneme alphabet="ipa" ph="ɯbe">うべ</phoneme>'], // ... 他のルール ]); // index.ts import { PHONEME_RULES } from './phoneme-rules'; const ssmlEn = normalizeRomanText(req.data.ssmlEn); let normalizedText = ssmlEn .replaceAll('・', ' ') .replaceAll('・', ' ') .replaceAll(/[!-/:-@[-`{-~、-〜"'・]+/g, ' ') .replaceAll('`', ''); for (const [pattern, replacement] of PHONEME_RULES) { normalizedText = normalizedText.replaceAll(pattern, replacement); } // ロギングの改善 const logger = functions.logger; logger.info('Text normalization', { original: req.data.ssmlEn, normalized: normalizedText });
🧹 Nitpick comments (5)
functions/src/utils/normalize.ts (1)
1-15: パフォーマンスと保守性の改善を提案します。以下の改善点を提案します:
- 大文字小文字の変換をより効率的に行うことができます。
- 'Jr' から 'J-R' への変換ロジックにコメントを追加することで、意図が明確になります。
以下のような実装を提案します:
export const normalizeRomanText = (str: string | undefined): string => { if (!str) return ''; + // 単語の先頭を大文字に、残りを小文字に変換 const replaced = str .split(' ') - .map((seg) => - /[A-Z]/.test(seg) - ? seg.charAt(0).toUpperCase() + seg.slice(1).toLowerCase() - : seg - ) + .map((seg) => seg.charAt(0).toUpperCase() + seg.slice(1).toLowerCase()) .join(' '); + // JR(Japan Railways)の表記を標準化 return replaced.replace('Jr', 'J-R'); };functions/src/utils/normalize.test.ts (1)
3-16: テストケースの追加を推奨します。以下のエッジケースのテストを追加することを推奨します:
describe('utils/normalize.ts', () => { + it('Should handle edge cases', () => { + expect(normalizeRomanText(undefined)).toBe(''); + expect(normalizeRomanText('')).toBe(''); + }); + it('Should be normalized', () => { expect(normalizeRomanText('TOKYO')).toBe('Tokyo'); // ... existing tests ... });functions/src/index.ts (1)
197-197: console.logの使用を避けてください。開発用のconsole.logが本番コードに残っています。Firebase Functionsのロガーを使用することを推奨します。
-console.log(req.data.ssmlEn, '->', ssmlEn); +functions.logger.info('Text normalization', { original: req.data.ssmlEn, normalized: ssmlEn });src/hooks/useTTSText.ts (2)
782-802: 英語アナウンステンプレートの改善提案現在のテンプレート構造は複雑で、メンテナンスが困難になる可能性があります。以下の改善を提案します:
- テンプレート文字列をより小さな関数に分割
- 共通のフレーズを定数として抽出
+ const COMMON_PHRASES = { + THANK_YOU: 'Thank you for using', + BOUND_FOR: 'bound for', + TERMINAL: 'terminal', + } as const; - ? `Thank you for using ${currentLine?.company?.nameEnglishShort}. This is the ${currentTrainType?.nameRoman ?? 'Local'} Service bound for ${boundForEn}` + ? `${COMMON_PHRASES.THANK_YOU} ${currentLine?.company?.nameEnglishShort}. This is the ${currentTrainType?.nameRoman ?? 'Local'} Service ${COMMON_PHRASES.BOUND_FOR} ${boundForEn}`
847-847: テンプレートリテラルの最適化長いテンプレートリテラルは可読性とメンテナンス性に影響を与える可能性があります。
テンプレート文字列を複数の小さな関数に分割することを推奨します:
const getTrainTypeAnnouncement = (type: string) => `This is the ${type ?? 'Local'} train`; const getDestinationAnnouncement = (destination: string) => `bound for ${destination}`;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
functions/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (10)
__tests__/utils/normalize.test.ts(0 hunks)functions/biome.json(1 hunks)functions/jest.config.js(1 hunks)functions/package.json(3 hunks)functions/src/index.ts(3 hunks)functions/src/utils/normalize.test.ts(1 hunks)functions/src/utils/normalize.ts(1 hunks)functions/tsconfig.json(1 hunks)src/hooks/useTTSText.ts(12 hunks)src/utils/normalize.ts(0 hunks)
💤 Files with no reviewable changes (2)
- tests/utils/normalize.test.ts
- src/utils/normalize.ts
✅ Files skipped from review due to trivial changes (1)
- functions/tsconfig.json
🔇 Additional comments (5)
functions/jest.config.js (1)
1-7: 設定は適切です!TypeScriptプロジェクト用の標準的なJest設定が実装されています。
src/hooks/useTTSText.ts (1)
72-72: nameRomanプロパティの直接アクセスへの変更を確認normalizeRomanText関数の削除に伴い、nameRomanプロパティへの直接アクセスに変更されています。この変更は適切ですが、以下の点に注意が必要です。
- nameRomanプロパティがundefinedの場合の処理
- 特殊文字を含む駅名の正規化
Also applies to: 81-81, 90-90, 99-101, 173-173, 182-182, 200-200, 203-203
✅ Verification successful
以下のスクリプトを実行して、src/hooks/useTTSText.ts 内での
nameRomanプロパティへの直接アクセスが意図どおりに変更されているか、該当箇所(例:l.nameRomanの使用部分)を確認してください。この結果をもとに、値が
undefinedになった場合の処理や、特殊文字を含む場合の対応が必要かどうかも合わせて検証してください。
nameRomanプロパティの直接アクセス変更を確認しました
src/hooks/useTTSText.ts内で、かつて使用されていた正規化関数を呼び出す処理がなくなり、全ての箇所でl.nameRomanへの直接アクセスに置き換えられているのが確認できました。(例: 行 72、173、203 など)- テンプレート文字列内でも同様の直接アクセスが行われており、仕様通りの変更になっています。
- なお、現状では
nameRomanがundefinedの可能性や、特殊文字を含むケースに対する明示的な対処は実装されていないため、必要に応じてその対応を検討することが望ましいです。🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # nameRomanプロパティの使用箇所を確認 rg "nameRoman" -A 2 -B 2Length of output: 116945
Script:
#!/bin/bash # src/hooks/useTTSText.ts 内で "l.nameRoman" の使用箇所とその前後の数行を抽出 rg "l\.nameRoman" -n --context 3 src/hooks/useTTSText.tsLength of output: 4372
functions/biome.json (1)
2-5: Biomeの設定が適切に更新されていますスキーマバージョンの更新と、ignoreパターンの簡素化が行われています。テスト関連ファイルの除外が適切に設定されています。
functions/package.json (2)
28-31: テスト環境の設定を確認Jestとts-jestの追加は適切ですが、以下の点を確認してください:
- テストカバレッジの設定
- TypeScriptの設定との整合性
テストカバレッジの設定やサンプルテストケースの作成をお手伝いしましょうか?
16-16: Node.jsバージョンの更新を確認Node.js 20への更新は適切ですが、以下の確認が必要です:
- 依存パッケージの互換性
- デプロイ環境のNode.jsバージョン
✅ Verification successful
依存パッケージとの互換性確認済み
firebase-functionsは Node.js>=14.10.0が必要なため、Node.js 20 で問題なしfirebase-adminは Node.js>=18が必要なため、Node.js 20 で問題なしデプロイ環境でも Node.js 20 が利用可能であることを合わせて確認してください。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 依存パッケージのNode.js互換性を確認 npm info firebase-functions engines npm info firebase-admin enginesLength of output: 110
Summary by CodeRabbit
New Features
Refactor
Tests
Chores