Skip to content
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

[HOTFIX]再生位置を指定するコードを移動させる #733

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
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