-
-
Notifications
You must be signed in to change notification settings - Fork 143
英単語を日本語で読み上げるオプション追加 #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
英単語を日本語で読み上げるオプション追加 #85
Conversation
Walkthroughこの変更は、英語の単語を日本語で読み上げる新機能を導入し、テキスト読み上げ機能の言語サポートを向上させます。 Changes
Poem
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
|
@coderabbitai review src/features/messages/speakCharacter.ts |
|
@tegnike, 以下は コードの構造と機能
PRの目的との整合性
改善の提案
このコードは、PRの目的に沿った機能を適切に実装しており、いくつかの改善を加えることでさらに堅牢なものになるでしょう。もしテストの例やエラーハンドリングの具体的な実装についてさらに情報が必要であれば、お知らせください。 Analysis chainScripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Fetch the content of the file speakCharacter.ts
cat src/features/messages/speakCharacter.ts
Length of output: 7604 Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range and nitpick comments (1)
src/pages/index.tsx (1)
Line range hint
347-347: オプショナルチェーンを使用することをお勧めします。安全なアクセスのために、オプショナルチェーンの使用を検討してください。
- const params = JSON.parse(storedData); + const params = JSON.parse(storedData || '{}');
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- locales/ja/translation.json (1 hunks)
- src/components/menu.tsx (3 hunks)
- src/components/settings.tsx (3 hunks)
- src/features/messages/speakCharacter.ts (3 hunks)
- src/pages/index.tsx (7 hunks)
Files skipped from review due to trivial changes (1)
- locales/ja/translation.json
Additional context used
Biome
src/pages/index.tsx
[error] 347-347: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
src/components/settings.tsx
[error] 384-533: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 415-533: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 443-533: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 473-533: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 503-533: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 711-855: This else clause can be omitted because previous branches break early.
Unsafe fix: Omit the else clause.
(lint/style/noUselessElse)
[error] 740-855: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 767-855: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
[error] 807-855: This else clause can be omitted because previous branches break early.
(lint/style/noUselessElse)
Additional comments not posted (9)
src/features/messages/speakCharacter.ts (3)
6-7: インポートと定数の追加が適切です。英語から日本語への変換を扱うためのJSONデータとインターフェースが正しく導入されています。
Also applies to: 9-14
36-45: 英語から日本語への読み上げ変換機能の統合が適切です。
changeEnglishToJapaneseフラグを使用して、選択された言語が日本語の場合に英語を日本語に変換するロジックが正しく実装されています。
84-91: 英単語を日本語読みに変換する関数の実装が効率的です。英単語のキーを長さでソートし、正規表現を使用して日本語読みに置換する処理が適切に行われています。
src/components/menu.tsx (1)
73-74: 新しいプロパティの統合が適切です。
changeEnglishToJapaneseとsetChangeEnglishToJapaneseプロパティがMenuコンポーネントに正しく統合されており、言語変換の状態を適切に管理しています。Also applies to: 149-150
src/pages/index.tsx (2)
44-44: 言語変換機能の状態管理が適切に行われています。
changeEnglishToJapanese状態変数がコンポーネント全体で一貫して使用され、localStorageによる永続化も適切に実装されています。Also applies to: 109-109, 150-150, 193-193, 260-260, 744-745
278-279: レンダリングロジックにおける状態変数の使用が適切です。言語変換の設定に基づいてコンポーネントの挙動を制御するために、状態変数が適切に使用されています。
src/components/settings.tsx (3)
80-81: Propsに新しいプロパティが追加されました
changeEnglishToJapaneseとsetChangeEnglishToJapaneseがPropsに追加されました。これにより、英語から日本語への読み上げ変更をUIから制御できるようになります。ただし、これらのプロパティの説明がドキュメントに追加されていないため、追加することをお勧めします。
157-158: コンポーネント関数での新しいプロパティの分解コンポーネント関数で
changeEnglishToJapaneseとsetChangeEnglishToJapaneseがPropsから分解されています。これにより、関数内でこれらのプロパティを直接使用できるようになり、機能の統合がスムーズに行われます。
848-865: 条件付きレンダリングでの機能切り替え
changeEnglishToJapaneseを使用した条件付きレンダリングが行われています。この機能により、ユーザーは英語から日本語への読み上げ変更を簡単に切り替えることができます。ただし、StatusOnとStatusOffのラベルが逆のようです。直感的に操作しやすいように、これを修正することをお勧めします。- <TextButton onClick={() => setChangeEnglishToJapanese(false)}> - {t('StatusOn')} - </TextButton> - <TextButton onClick={() => setChangeEnglishToJapanese(true)}> - {t('StatusOff')} - </TextButton> + <TextButton onClick={() => setChangeEnglishToJapanese(false)}> + {t('StatusOff')} + </TextButton> + <TextButton onClick={() => setChangeEnglishToJapanese(true)}> + {t('StatusOn')} + </TextButton>
| buffer = await fetchAudio(screenplay.talk, koeiroApiKey).catch(() => null); | ||
| } else if (selectVoice == "voicevox") { | ||
| buffer = await fetchAudioVoiceVox(screenplay.talk, voicevoxSpeaker).catch( | ||
| () => null | ||
| ); | ||
| buffer = await fetchAudioVoiceVox(screenplay.talk, voicevoxSpeaker).catch(() => null); | ||
| } else if (selectVoice == "google") { | ||
|
|
||
| const getGppgleTTsType = (selectLanguage: string) => { | ||
| if (selectLanguage) { | ||
| switch (selectLanguage) { | ||
| case 'JP': | ||
| return 'ja-JP-Standard-B'; | ||
| case 'EN': | ||
| return 'en-US-Neural2-F'; | ||
| case 'ZH': | ||
| return 'cmn-TW-Standard-A'; | ||
| default: | ||
| return 'en-US-Neural2-F'; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let googleTtsTypeByLang:string = ''; | ||
| if (!googleTtsType || googleTtsType === "") { | ||
| const storedData = window.localStorage.getItem('chatVRMParams'); | ||
|
|
||
| if (storedData) { | ||
| const params = JSON.parse(storedData); | ||
| const langCode = params.selectLanguage; | ||
| if (langCode) { | ||
| googleTtsTypeByLang = getGppgleTTsType(langCode) ?? ''; | ||
| } | ||
| } | ||
| } else { | ||
| googleTtsTypeByLang = googleTtsType; | ||
| } | ||
| buffer = await fetchAudioGoogle(screenplay.talk, googleTtsTypeByLang).catch( | ||
| () => null | ||
| ); | ||
| const googleTtsTypeByLang = getGoogleTtsType(googleTtsType, selectLanguage); | ||
| buffer = await fetchAudioGoogle(screenplay.talk, googleTtsTypeByLang).catch(() => null); | ||
| } else if (selectVoice == "stylebertvits2") { | ||
| buffer = await fetchAudioStyleBertVITS2(screenplay.talk, stylebertvits2ServerUrl, stylebertvits2ModelId, stylebertvits2Style, selectLanguage).catch( | ||
| () => null | ||
| ); | ||
| buffer = await fetchAudioStyleBertVITS2(screenplay.talk, stylebertvits2ServerUrl, stylebertvits2ModelId, stylebertvits2Style, selectLanguage).catch(() => null); | ||
| } else if (selectVoice == "gsvitts") { | ||
| buffer = await fetchAudioVoiceGSVIApi(screenplay.talk, gsviTtsServerUrl, gsviTtsModelId, gsviTtsBatchSize, gsviTtsSpeechRate).catch( | ||
| () => null | ||
| ); | ||
| buffer = await fetchAudioVoiceGSVIApi(screenplay.talk, gsviTtsServerUrl, gsviTtsModelId, gsviTtsBatchSize, gsviTtsSpeechRate).catch(() => null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API呼び出しのエラーハンドリングを改善することをお勧めします。
現在、.catch(() => null) を使用してエラーを抑制していますが、エラーログを出力するなどの改善を行うことで、デバッグやユーザーエクスペリエンスの向上が期待できます。
…-to-japanese-reading 英単語を日本語で読み上げるオプション追加
Summary by CodeRabbit