Skip to content

Commit

Permalink
[HOTFIX]再生位置を指定するコードを移動させる (#733)
Browse files Browse the repository at this point in the history
* move part of setting current time

* Update src/store/audio.ts

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
  • Loading branch information
y-chan and Hiroshiba authored Mar 1, 2022
1 parent 973e15e commit 9b753ca
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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,
Expand All @@ -1311,14 +1296,31 @@ export const audioStore: VoiceVoxStoreOptions<
),
PLAY_AUDIO_BLOB: createUILockAction(
async (
{ state, commit },
{ state, commit, dispatch },
{
audioBlob,
audioElem,
audioKey,
}: { 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) => {
Expand Down

0 comments on commit 9b753ca

Please sign in to comment.