Skip to content

Commit 815a34e

Browse files
committed
Fix: ユーザー辞書追加・変更画面で、中間のアクセント句の末尾に「が」を付与しないように修正
これで動作はかなり完璧になったはず
1 parent 183073d commit 815a34e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/components/Dialog/DictionaryEditWordDialog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ const play = async () => {
348348
// 音声合成用の AudioItem を生成
349349
const audioItem = await store.actions.GENERATE_AUDIO_ITEM({
350350
// wordAccentPhraseItems 内の surface を結合したものを入力テキストとする
351-
text: props.wordAccentPhraseItems.map(item => item.surface + "").join(""),
351+
// AccentPhrase と挙動を合わせるため、末尾に「が」を追加する
352+
text: props.wordAccentPhraseItems.map(item => item.surface).join("") + "",
352353
voice: { engineId, speakerId, styleId },
353354
});
354355
if (audioItem.query == undefined)

src/composables/useDictionaryEditor.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,14 @@ export function useDictionaryEditor(initialSurface = "", initialPronunciation =
265265
if (isValid && pronunciation.length) {
266266
pronunciation = convertHiraToKana(pronunciation);
267267
pronunciation = convertLongVowel(pronunciation);
268+
269+
// 現在の項目が最後の要素の場合のみ「ガ」を追加する
270+
const isLastItem = accentPhraseIndex === wordAccentPhraseItems.value.length - 1;
271+
const textToFetch = isLastItem ? pronunciation + "ガ'" : pronunciation + "'";
272+
268273
const fetchedAccentPhrase = (
269274
await store.actions.FETCH_ACCENT_PHRASES({
270-
text: pronunciation + "ガ'",
275+
text: textToFetch,
271276
engineId,
272277
styleId,
273278
isKana: true,
@@ -322,12 +327,22 @@ export function useDictionaryEditor(initialSurface = "", initialPronunciation =
322327
pronunciation: "",
323328
isValid: true,
324329
});
330+
// 追加したアクセント句を含め、すべてのアクセント句の発音を更新する
331+
// そうしないと、常に wordAccentPhraseItems の最後の要素にのみ「ガ」を付与する挙動が維持できない
332+
for (let i = 0; i < wordAccentPhraseItems.value.length; i++) {
333+
void updatePronunciation(wordAccentPhraseItems.value[i].pronunciation, i, true);
334+
}
325335
}
326336

327337
// 指定されたアクセント句を削除する
328338
function removeWordAccentPhraseItem(accentPhraseIndex: number): void {
329339
if (wordAccentPhraseItems.value.length > 1) {
330340
wordAccentPhraseItems.value.splice(accentPhraseIndex, 1);
341+
// 追加したアクセント句を含め、すべてのアクセント句の発音を更新する
342+
// そうしないと、常に wordAccentPhraseItems の最後の要素にのみ「ガ」を付与する挙動が維持できない
343+
for (let i = 0; i < wordAccentPhraseItems.value.length; i++) {
344+
void updatePronunciation(wordAccentPhraseItems.value[i].pronunciation, i, true);
345+
}
331346
}
332347
}
333348

0 commit comments

Comments
 (0)