Skip to content

TTSの読み方補正処理修正 - #4059

Merged
TinyKitten merged 1 commit into
devfrom
fix/functions-replace
Feb 9, 2025
Merged

TinyKitten merged 1 commit into
devfrom
fix/functions-replace

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Feb 9, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • リファクタ
     - 音声合成時のテキスト変換ロジックを最適化し、特殊文字やパターンの処理精度と柔軟性を向上させ、出力品質の改善が期待されます。

@TinyKitten TinyKitten self-assigned this Feb 9, 2025
@coderabbitai

coderabbitai Bot commented Feb 9, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

この変更は、tts関数内でssmlEn変数の文字列置換処理を更新するものです。従来のreplaceAllメソッドからreplaceメソッドに変更し、正規表現を活用して大文字小文字を区別しない置換やパターンマッチングを適用しています。公開エンティティの宣言には変更はありません。

Changes

ファイル 変更内容
functions/.../index.ts 複数の置換処理がupdateされました。具体的には、「・」「・」、全角句読点、バッククォート、'-itchome'、'-sanchome'、および "Ube", "Isesaki", "Mejiro", "Keisei", "Oshiage", "Meitetsu", "Seibu", "jo" の置換が、replaceAllから正規表現を使ったreplaceへ変更。さらに新たに「JR」の置換を追加。

Possibly related PRs

  • TTS系の修正 #4049: tts関数の文字列処理とnormalizeRomanText関数のテストが直接関連するコードレベルの変更が含まれている。

Suggested labels

react

Poem

ぴょんぴょんと駆ける小さなうさぎ
コードの森で変化を見つけたよ
「replaceAll」から「replace」へと踊り変わり
軽やかなリズムに心躍る
✨Happy Coding, ぴょんぴょん!✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (2)
functions/src/index.ts (2)

47-74: 発音記号(IPA)の使用に関するドキュメントの追加を推奨します

各置換パターンの意図と発音記号の選択理由を説明するコメントを追加することで、将来の保守性が向上します。

以下のようなコメントの追加を提案します:

+    // 一丁目: itt͡ɕoːme - 促音「っ」と長音「ー」を正確に表現
     .replace(
       /\-itchome/gi,
       `<phoneme alphabet="ipa" ph="itt͡ɕoːme">いっちょうめ</phoneme>`
     )

75-81: 鉄道会社名の置換パターンの整理を提案します

鉄道会社名の置換パターンをより管理しやすい形に整理することを推奨します。

以下のような定数オブジェクトとしての切り出しを提案します:

+const RAILWAY_COMPANY_PRONUNCIATIONS = {
+  Meitetsu: { ipa: 'meitetsɯ', kana: 'めいてつ' },
+  Seibu: { ipa: 'seibɯ', kana: 'せいぶ' },
+} as const;
+
+Object.entries(RAILWAY_COMPANY_PRONUNCIATIONS).forEach(([company, { ipa, kana }]) => {
+  ssmlEn = ssmlEn.replace(
+    new RegExp(company, 'gi'),
+    `<phoneme alphabet="ipa" ph="${ipa}">${kana}</phoneme>`
+  );
+});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c5148a and 7319555.

📒 Files selected for processing (1)
  • functions/src/index.ts (1 hunks)
🔇 Additional comments (2)
functions/src/index.ts (2)

39-44: 正規表現を使用した文字列置換の改善を確認しました!

全角記号のグループ化と正規表現の使用により、コードの効率性と保守性が向上しています。


82-84: 最終的な置換パターンの順序の確認をお願いします

置換パターンの順序が結果に影響を与える可能性があります。特に「JR」の置換が他のパターンに影響を与えないか確認してください。

以下のようなテストケースの追加を推奨します:

const testCases = [
  { input: 'JR Joto Line', expected: 'J-R じょと Line' },
  { input: 'Joto JR Line', expected: 'じょと J-R Line' },
];
✅ Verification successful

最終置換パターンの順序に問題はありません

コードでは、大文字小文字の区別なく「jo」を対象に変換し、その後で「JR」を変換する処理が意図通り順序立てて実行されています。実際のテストケース(例:"JR Joto Line" → "J-R じょと Line"、"Joto JR Line" → "じょと J-R Line")で確認されるように、各置換処理は互いに影響せず、順序問題は見受けられません。

  • 「jo」の正規表現で対象部分の変換を正しく置換できる
  • その後に「JR」も適切に置換されることで、両パターンが意図通りに作用している

このため、提案されたテストケースを用いて最終確認を行うことを推奨しますが、現在のコードの順序に影響する問題は見当たりません。

@TinyKitten
TinyKitten merged commit 9c7ccfd into dev Feb 9, 2025
@TinyKitten
TinyKitten deleted the fix/functions-replace branch February 9, 2025 03:21
@coderabbitai coderabbitai Bot mentioned this pull request Feb 9, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Feb 17, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Aug 8, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Aug 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant