From 9b753ca741ded90b3b78660f976be1061b079ce3 Mon Sep 17 00:00:00 2001 From: Yuto Ashida Date: Tue, 1 Mar 2022 23:43:08 +0900 Subject: [PATCH] =?UTF-8?q?[HOTFIX]=E5=86=8D=E7=94=9F=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=82=92=E7=A7=BB=E5=8B=95=E3=81=95=E3=81=9B=E3=82=8B?= =?UTF-8?q?=20(#733)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * move part of setting current time * Update src/store/audio.ts Co-authored-by: Hiroshiba --- src/store/audio.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index 5dadf31257..4d49f88c7a 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,23 @@ 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) => {