From a8acfed8716a321b9976861f49549dbb3900d6c7 Mon Sep 17 00:00:00 2001 From: y-chan Date: Tue, 1 Mar 2022 22:03:01 +0900 Subject: [PATCH 1/2] move part of setting current time --- src/store/audio.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index 5dadf31257..5510bccce5 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -1266,10 +1266,7 @@ export const audioStore: VoiceVoxStoreOptions< } ), PLAY_AUDIO: createUILockAction( - async ( - { state, commit, dispatch }, - { audioKey }: { audioKey: string } - ) => { + async ({ commit, dispatch }, { audioKey }: { audioKey: string }) => { const audioElem = audioElements[audioKey]; audioElem.pause(); @@ -1289,18 +1286,6 @@ export const audioStore: VoiceVoxStoreOptions< throw new Error(); } } - const accentPhraseOffsets = await dispatch("GET_AUDIO_PLAY_OFFSETS", { - audioKey, - }); - if (accentPhraseOffsets.length === 0) { - audioElem.currentTime = 0; - } else { - const startTime = accentPhraseOffsets[state.audioPlayStartPoint ?? 0]; - if (startTime === undefined) throw Error("startTime === undefined"); - // 小さい値が切り捨てられることでフォーカスされるアクセントフレーズが一瞬元に戻るので、 - // 再生に影響のない程度かつ切り捨てられない値を加算する - audioElem.currentTime = startTime + 10e-6; - } return dispatch("PLAY_AUDIO_BLOB", { audioBlob: blob, @@ -1311,7 +1296,7 @@ export const audioStore: VoiceVoxStoreOptions< ), PLAY_AUDIO_BLOB: createUILockAction( async ( - { state, commit }, + { state, commit, dispatch }, { audioBlob, audioElem, @@ -1319,6 +1304,22 @@ export const audioStore: VoiceVoxStoreOptions< }: { audioBlob: Blob; audioElem: HTMLAudioElement; audioKey?: string } ) => { audioElem.src = URL.createObjectURL(audioBlob); + if (audioKey) { + const accentPhraseOffsets = await dispatch("GET_AUDIO_PLAY_OFFSETS", { + audioKey, + }); + if (accentPhraseOffsets.length === 0) { + audioElem.currentTime = 0; + } else { + const startTime = + accentPhraseOffsets[state.audioPlayStartPoint ?? 0]; + if (startTime === undefined) throw Error("startTime === undefined"); + // 小さい値が切り捨てられることでフォーカスされるアクセントフレーズが一瞬元に戻るので、 + // 再生に影響のない程度かつ切り捨てられない値を加算する + audioElem.currentTime = startTime + 10e-6; + } + } + audioElem .setSinkId(state.savingSetting.audioOutputDevice) .catch((err) => { From 46db101f562fc89cbea21943cf2580787a0f6960 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Tue, 1 Mar 2022 23:43:02 +0900 Subject: [PATCH 2/2] Update src/store/audio.ts --- src/store/audio.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/store/audio.ts b/src/store/audio.ts index 5510bccce5..4d49f88c7a 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -1304,6 +1304,7 @@ export const audioStore: VoiceVoxStoreOptions< }: { audioBlob: Blob; audioElem: HTMLAudioElement; audioKey?: string } ) => { audioElem.src = URL.createObjectURL(audioBlob); + // 途中再生用の処理 if (audioKey) { const accentPhraseOffsets = await dispatch("GET_AUDIO_PLAY_OFFSETS", { audioKey,