From f49ea7962e9032fce610ee5dd140efa76fe00d10 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sat, 2 Dec 2023 22:33:29 +0900 Subject: [PATCH 1/6] =?UTF-8?q?Fix:=20=E8=A4=87=E6=95=B0=E8=A9=B1=E8=80=85?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=99=E3=82=8B=E3=81=A8AudioQuery?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=AD=E3=82=B9=E3=83=88=E3=81=A8=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E3=81=97=E3=81=AA=E3=81=8F=E3=81=AA=E3=82=8B=E3=83=90?= =?UTF-8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 72 ++++++++++++++++++++++------------------------ src/store/type.ts | 2 +- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index 99a5ca9364..f5fa43067f 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -2012,7 +2012,7 @@ export const audioCommandStore = transformCommandStore( COMMAND_MULTI_CHANGE_VOICE: { mutation( draft, - payload: { audioKeys: AudioKey[]; voice: Voice } & ( + payload: { audioKey: AudioKey; voice: Voice } & ( | { update: "RollbackStyleId" } | { update: "AccentPhrases"; @@ -2024,47 +2024,43 @@ export const audioCommandStore = transformCommandStore( } ) ) { - for (const audioKey of payload.audioKeys) { - audioStore.mutations.SET_AUDIO_VOICE(draft, { - audioKey, - voice: payload.voice, - }); - } + audioStore.mutations.SET_AUDIO_VOICE(draft, { + audioKey: payload.audioKey, + voice: payload.voice, + }); if (payload.update === "RollbackStyleId") return; - for (const audioKey of payload.audioKeys) { - const presetKey = draft.audioItems[audioKey].presetKey; + const presetKey = draft.audioItems[payload.audioKey].presetKey; - const { nextPresetKey, shouldApplyPreset } = determineNextPresetKey( - draft, - payload.voice, - presetKey, - "changeVoice" - ); + const { nextPresetKey, shouldApplyPreset } = determineNextPresetKey( + draft, + payload.voice, + presetKey, + "changeVoice" + ); - audioStore.mutations.SET_AUDIO_PRESET_KEY(draft, { - audioKey, - presetKey: nextPresetKey, - }); + audioStore.mutations.SET_AUDIO_PRESET_KEY(draft, { + audioKey: payload.audioKey, + presetKey: nextPresetKey, + }); - if (payload.update == "AccentPhrases") { - audioStore.mutations.SET_ACCENT_PHRASES(draft, { - audioKey, - accentPhrases: payload.accentPhrases, - }); - } else if (payload.update == "AudioQuery") { - audioStore.mutations.SET_AUDIO_QUERY(draft, { - audioKey, - audioQuery: payload.query, - }); - } + if (payload.update === "AccentPhrases") { + audioStore.mutations.SET_ACCENT_PHRASES(draft, { + audioKey: payload.audioKey, + accentPhrases: payload.accentPhrases, + }); + } else if (payload.update === "AudioQuery") { + audioStore.mutations.SET_AUDIO_QUERY(draft, { + audioKey: payload.audioKey, + audioQuery: payload.query, + }); + } - if (shouldApplyPreset) { - audioStore.mutations.APPLY_AUDIO_PRESET(draft, { - audioKey, - }); - } + if (shouldApplyPreset) { + audioStore.mutations.APPLY_AUDIO_PRESET(draft, { + audioKey: payload.audioKey, + }); } }, async action( @@ -2089,7 +2085,7 @@ export const audioCommandStore = transformCommandStore( } ); commit("COMMAND_MULTI_CHANGE_VOICE", { - audioKeys, + audioKey, voice, update: "AccentPhrases", accentPhrases: newAccentPhrases, @@ -2102,7 +2098,7 @@ export const audioCommandStore = transformCommandStore( styleId, }); commit("COMMAND_MULTI_CHANGE_VOICE", { - audioKeys, + audioKey, voice, update: "AudioQuery", query, @@ -2110,7 +2106,7 @@ export const audioCommandStore = transformCommandStore( } } catch (error) { commit("COMMAND_MULTI_CHANGE_VOICE", { - audioKeys, + audioKey, voice, update: "RollbackStyleId", }); diff --git a/src/store/type.ts b/src/store/type.ts index 218269ef22..838a4feea6 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -502,7 +502,7 @@ export type AudioCommandStoreTypes = { }; COMMAND_MULTI_CHANGE_VOICE: { - mutation: { audioKeys: AudioKey[]; voice: Voice } & ( + mutation: { audioKey: AudioKey; voice: Voice } & ( | { update: "RollbackStyleId" } | { update: "AccentPhrases"; From be53ab414d1b29a073be876a9832e1a7bbf77e00 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Mon, 4 Dec 2023 00:52:29 +0900 Subject: [PATCH 2/6] =?UTF-8?q?Fix:=20mutation=E3=82=92=E4=B8=80=E3=81=A4?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 176 +++++++++++++++++++++++---------------------- src/store/type.ts | 25 ++++--- 2 files changed, 103 insertions(+), 98 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index f5fa43067f..ef76b6b6f7 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -2011,109 +2011,111 @@ export const audioCommandStore = transformCommandStore( COMMAND_MULTI_CHANGE_VOICE: { mutation( - draft, - payload: { audioKey: AudioKey; voice: Voice } & ( - | { update: "RollbackStyleId" } - | { - update: "AccentPhrases"; - accentPhrases: AccentPhrase[]; - } - | { - update: "AudioQuery"; - query: AudioQuery; - } - ) - ) { - audioStore.mutations.SET_AUDIO_VOICE(draft, { - audioKey: payload.audioKey, - voice: payload.voice, - }); - - if (payload.update === "RollbackStyleId") return; - - const presetKey = draft.audioItems[payload.audioKey].presetKey; - - const { nextPresetKey, shouldApplyPreset } = determineNextPresetKey( - draft, - payload.voice, - presetKey, - "changeVoice" - ); - - audioStore.mutations.SET_AUDIO_PRESET_KEY(draft, { - audioKey: payload.audioKey, - presetKey: nextPresetKey, - }); - - if (payload.update === "AccentPhrases") { - audioStore.mutations.SET_ACCENT_PHRASES(draft, { - audioKey: payload.audioKey, - accentPhrases: payload.accentPhrases, - }); - } else if (payload.update === "AudioQuery") { - audioStore.mutations.SET_AUDIO_QUERY(draft, { - audioKey: payload.audioKey, - audioQuery: payload.query, - }); + state, + payload: { + voice: Voice; + changes: Record< + AudioKey, + | { + update: "AccentPhrases"; + accentPhrases: AccentPhrase[]; + } + | { + update: "AudioQuery"; + query: AudioQuery; + } + >; } + ) { + for (const [audioKey_, change] of Object.entries(payload.changes)) { + // TypeScriptは`Object.entries`のKeyの型を`string`としてしまうので、`as`で型を指定する + const audioKey = audioKey_ as AudioKey; - if (shouldApplyPreset) { - audioStore.mutations.APPLY_AUDIO_PRESET(draft, { - audioKey: payload.audioKey, + audioStore.mutations.SET_AUDIO_VOICE(state, { + audioKey, + voice: payload.voice, }); + if (change.update == "AccentPhrases") { + audioStore.mutations.SET_ACCENT_PHRASES(state, { + audioKey, + accentPhrases: change.accentPhrases, + }); + } else if (change.update == "AudioQuery") { + audioStore.mutations.SET_AUDIO_QUERY(state, { + audioKey, + audioQuery: change.query, + }); + } } }, async action( { state, dispatch, commit }, { audioKeys, voice }: { audioKeys: AudioKey[]; voice: Voice } ) { - const engineId = voice.engineId; - const styleId = voice.styleId; - await dispatch("SETUP_SPEAKER", { audioKeys, engineId, styleId }); - await Promise.all( - audioKeys.map(async (audioKey) => { - try { - const query = state.audioItems[audioKey].query; - if (query != undefined) { - const accentPhrases = query.accentPhrases; + const changes: Record< + AudioKey, + | { + update: "AccentPhrases"; + accentPhrases: AccentPhrase[]; + } + | { + update: "AudioQuery"; + query: AudioQuery; + } + > = Object.fromEntries( + await Promise.all( + audioKeys.map(async (audioKey) => { + try { + const audioItem = state.audioItems[audioKey]; + if (audioItem.query == undefined) { + const query: AudioQuery = await dispatch( + "FETCH_AUDIO_QUERY", + { + text: audioItem.text, + engineId: voice.engineId, + styleId: voice.styleId, + } + ); + return [ + [ + audioKey, + { + update: "AudioQuery", + query, + }, + ], + ]; + } const newAccentPhrases: AccentPhrase[] = await dispatch( "FETCH_MORA_DATA", { - accentPhrases, - engineId, - styleId, + accentPhrases: audioItem.query.accentPhrases, + engineId: voice.engineId, + styleId: voice.styleId, } ); - commit("COMMAND_MULTI_CHANGE_VOICE", { - audioKey, - voice, - update: "AccentPhrases", - accentPhrases: newAccentPhrases, - }); - } else { - const text = state.audioItems[audioKey].text; - const query: AudioQuery = await dispatch("FETCH_AUDIO_QUERY", { - text: text, - engineId, - styleId, - }); - commit("COMMAND_MULTI_CHANGE_VOICE", { - audioKey, - voice, - update: "AudioQuery", - query, - }); + + return [ + [ + audioKey, + { + update: "AccentPhrases", + accentPhrases: newAccentPhrases, + }, + ], + ]; + } catch (error) { + await dispatch("LOG_ERROR", error); + return []; } - } catch (error) { - commit("COMMAND_MULTI_CHANGE_VOICE", { - audioKey, - voice, - update: "RollbackStyleId", - }); - throw error; - } - }) + }) + ).then((entries) => entries.flat()) ); + + commit("COMMAND_MULTI_CHANGE_VOICE", { + voice, + changes, + }); }, }, diff --git a/src/store/type.ts b/src/store/type.ts index 838a4feea6..02926d96b3 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -502,17 +502,20 @@ export type AudioCommandStoreTypes = { }; COMMAND_MULTI_CHANGE_VOICE: { - mutation: { audioKey: AudioKey; voice: Voice } & ( - | { update: "RollbackStyleId" } - | { - update: "AccentPhrases"; - accentPhrases: AccentPhrase[]; - } - | { - update: "AudioQuery"; - query: AudioQuery; - } - ); + mutation: { + voice: Voice; + changes: Record< + AudioKey, + | { + update: "AccentPhrases"; + accentPhrases: AccentPhrase[]; + } + | { + update: "AudioQuery"; + query: AudioQuery; + } + >; + }; action(payload: { audioKeys: AudioKey[]; voice: Voice }): void; }; From 53d7d582be0847a694c0c97db2370e52cd5d6c37 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 5 Dec 2023 20:26:48 +0900 Subject: [PATCH 3/6] =?UTF-8?q?Change:=20=E3=83=AC=E3=83=93=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 100 ++++++++++++++++++++++++--------------------- src/store/type.ts | 3 ++ 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index ef76b6b6f7..70ad87388e 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -2024,6 +2024,9 @@ export const audioCommandStore = transformCommandStore( update: "AudioQuery"; query: AudioQuery; } + | { + update: "OnlyVoice"; + } >; } ) { @@ -2052,6 +2055,10 @@ export const audioCommandStore = transformCommandStore( { state, dispatch, commit }, { audioKeys, voice }: { audioKeys: AudioKey[]; voice: Voice } ) { + const engineId = voice.engineId; + const styleId = voice.styleId; + await dispatch("SETUP_SPEAKER", { audioKeys, engineId, styleId }); + const errors: Record = {}; const changes: Record< AudioKey, | { @@ -2062,60 +2069,59 @@ export const audioCommandStore = transformCommandStore( update: "AudioQuery"; query: AudioQuery; } - > = Object.fromEntries( - await Promise.all( - audioKeys.map(async (audioKey) => { - try { - const audioItem = state.audioItems[audioKey]; - if (audioItem.query == undefined) { - const query: AudioQuery = await dispatch( - "FETCH_AUDIO_QUERY", - { - text: audioItem.text, - engineId: voice.engineId, - styleId: voice.styleId, - } - ); - return [ - [ - audioKey, - { - update: "AudioQuery", - query, - }, - ], - ]; + | { + update: "OnlyVoice"; + } + > = {}; + + for (const audioKey of audioKeys) { + try { + const audioItem = state.audioItems[audioKey]; + if (audioItem.query == undefined) { + const query: AudioQuery = await dispatch("FETCH_AUDIO_QUERY", { + text: audioItem.text, + engineId: voice.engineId, + styleId: voice.styleId, + }); + changes[audioKey] = { + update: "AudioQuery", + query, + }; + } else { + const newAccentPhrases: AccentPhrase[] = await dispatch( + "FETCH_MORA_DATA", + { + accentPhrases: audioItem.query.accentPhrases, + engineId: voice.engineId, + styleId: voice.styleId, } - const newAccentPhrases: AccentPhrase[] = await dispatch( - "FETCH_MORA_DATA", - { - accentPhrases: audioItem.query.accentPhrases, - engineId: voice.engineId, - styleId: voice.styleId, - } - ); + ); - return [ - [ - audioKey, - { - update: "AccentPhrases", - accentPhrases: newAccentPhrases, - }, - ], - ]; - } catch (error) { - await dispatch("LOG_ERROR", error); - return []; - } - }) - ).then((entries) => entries.flat()) - ); + changes[audioKey] = { + update: "AccentPhrases", + accentPhrases: newAccentPhrases, + }; + } + } catch (error) { + errors[audioKey] = error; + changes[audioKey] = { + update: "OnlyVoice", + }; + } + } commit("COMMAND_MULTI_CHANGE_VOICE", { voice, changes, }); + + if (Object.keys(errors).length > 0) { + throw new Error( + `話者の変更に失敗しました:\n${Object.entries(errors) + .map(([audioKey, error]) => `${audioKey}: ${error}`) + .join("\n")}` + ); + } }, }, diff --git a/src/store/type.ts b/src/store/type.ts index 02926d96b3..b7006cda73 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -514,6 +514,9 @@ export type AudioCommandStoreTypes = { update: "AudioQuery"; query: AudioQuery; } + | { + update: "OnlyVoice"; + } >; }; action(payload: { audioKeys: AudioKey[]; voice: Voice }): void; From 8b40e920428dabaaae21db2859afdc45b3370aab Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 5 Dec 2023 20:29:49 +0900 Subject: [PATCH 4/6] =?UTF-8?q?Change:=20=E8=A8=98=E5=8F=B7=E3=82=92?= =?UTF-8?q?=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index 70ad87388e..75c5964268 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -2118,7 +2118,7 @@ export const audioCommandStore = transformCommandStore( if (Object.keys(errors).length > 0) { throw new Error( `話者の変更に失敗しました:\n${Object.entries(errors) - .map(([audioKey, error]) => `${audioKey}: ${error}`) + .map(([audioKey, error]) => `${audioKey}:${error}`) .join("\n")}` ); } From 85c8ab589a27b877630d86080f6532d1f2c0e5c0 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Wed, 13 Dec 2023 20:13:54 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Add:=20=E3=83=97=E3=83=AA=E3=82=BB=E3=83=83?= =?UTF-8?q?=E3=83=88=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/store/audio.ts b/src/store/audio.ts index 75c5964268..0af76ab809 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -2034,6 +2034,22 @@ export const audioCommandStore = transformCommandStore( // TypeScriptは`Object.entries`のKeyの型を`string`としてしまうので、`as`で型を指定する const audioKey = audioKey_ as AudioKey; + const presetKey = state.audioItems[audioKey].presetKey; + + const { nextPresetKey, shouldApplyPreset } = determineNextPresetKey( + state, + payload.voice, + presetKey, + "changeVoice" + ); + + if (shouldApplyPreset) { + audioStore.mutations.SET_AUDIO_PRESET_KEY(state, { + audioKey, + presetKey: nextPresetKey, + }); + } + audioStore.mutations.SET_AUDIO_VOICE(state, { audioKey, voice: payload.voice, @@ -2049,6 +2065,11 @@ export const audioCommandStore = transformCommandStore( audioQuery: change.query, }); } + if (shouldApplyPreset) { + audioStore.mutations.APPLY_AUDIO_PRESET(state, { + audioKey, + }); + } } }, async action( From 978affe4e7e3c8b5ac1016477727ab25b52f18e8 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 14 Dec 2023 06:21:20 +0900 Subject: [PATCH 6/6] =?UTF-8?q?Delete:=20=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=88=86=E5=B2=90=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index 0af76ab809..2af0fb0eaa 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -2043,12 +2043,10 @@ export const audioCommandStore = transformCommandStore( "changeVoice" ); - if (shouldApplyPreset) { - audioStore.mutations.SET_AUDIO_PRESET_KEY(state, { - audioKey, - presetKey: nextPresetKey, - }); - } + audioStore.mutations.SET_AUDIO_PRESET_KEY(state, { + audioKey, + presetKey: nextPresetKey, + }); audioStore.mutations.SET_AUDIO_VOICE(state, { audioKey,