Skip to content

Commit

Permalink
エンジンから取得したキャラクター情報でデフォルトスタイルを設定する
Browse files Browse the repository at this point in the history
  • Loading branch information
shirowanisan committed Nov 28, 2021
1 parent aef5092 commit fc5e638
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 56 deletions.
99 changes: 49 additions & 50 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AudioQuery, AccentPhrase } from "@/openapi";
import { AudioQuery, AccentPhrase, Speaker, SpeakerInfo } from "@/openapi";
import path from "path";
import { v4 as uuidv4 } from "uuid";
import {
Expand Down Expand Up @@ -407,60 +407,59 @@ export const audioStore: VoiceVoxStoreOptions<
}
}
),
LOAD_CHARACTER: createUILockAction(async ({ rootState, commit }) => {
const characterInfos = await window.electron.getCharacterInfos();

_engineFactory
.instance(rootState.engineHost)
.speakersSpeakersGet()
LOAD_CHARACTER: createUILockAction(async ({ commit, dispatch }) => {
const speakers = await dispatch("INVOKE_ENGINE_CONNECTOR", {
action: "speakersSpeakersGet",
payload: [],
})
.then(toDispatchResponse("speakersSpeakersGet"))
.catch((error) => {
window.electron.logError(error, `Failed to get speakers.`);
throw error;
});
const getStyles = function (speaker: Speaker, speakerInfo: SpeakerInfo) {
const styles: StyleInfo[] = new Array(speaker.styles.length);
speaker.styles.forEach((style, i) => {
for (const styleInfo of speakerInfo.styleInfos) {
if (style.id === styleInfo.id) {
styles[i] = {
styleName: style.name,
styleId: style.id,
iconBase64: styleInfo.icon,
voiceSampleBase64s: styleInfo.voiceSamples,
};
}
}
});
return styles;
};
const getSpeakerInfo = async function (speaker: Speaker) {
const speakerInfo = await dispatch("INVOKE_ENGINE_CONNECTOR", {
action: "speakerInfoSpeakerInfoGet",
payload: [{ speakerUuid: speaker.speakerUuid }],
})
.then((speakers) => {
const tmpCharacterInfos: CharacterInfo[] = new Array(
speakers.length
);
speakers.forEach((speaker, speaker_index) => {
_engineFactory
.instance(rootState.engineHost)
.speakerInfoSpeakerInfoGet({
speakerUuid: speaker.speakerUuid,
})
.catch((error) => {
window.electron.logError(
error,
`Failed to get speaker info.`
);
throw error;
})
.then((speakerInfo) => {
const styles: StyleInfo[] = new Array(speaker.styles.length);
speaker.styles.forEach((style, i) => {
for (const styleInfo of speakerInfo.styleInfos) {
if (style.id === styleInfo.id) {
styles[i] = {
styleName: style.name,
styleId: style.id,
iconBase64: styleInfo.icon,
voiceSampleBase64s: styleInfo.voiceSamples,
};
}
}
});
tmpCharacterInfos[speaker_index] = {
portraitBase64: speakerInfo.portrait,
metas: {
speakerUuid: speaker.speakerUuid,
speakerName: speaker.name,
styles: styles,
policy: speakerInfo.policy,
},
};
});
.then(toDispatchResponse("speakerInfoSpeakerInfoGet"))
.catch((error) => {
window.electron.logError(error, `Failed to get speakers.`);
throw error;
});
console.log(tmpCharacterInfos);
});
const styles = getStyles(speaker, speakerInfo);
const characterInfo: CharacterInfo = {
portraitBase64: speakerInfo.portrait,
metas: {
speakerUuid: speaker.speakerUuid,
speakerName: speaker.name,
styles: styles,
policy: speakerInfo.policy,
},
};
return characterInfo;
};
const characterInfos: CharacterInfo[] = await Promise.all(
speakers.map(async (speaker) => {
return await getSpeakerInfo(speaker);
})
);

commit("SET_CHARACTER_INFOS", { characterInfos });
}),
Expand Down
11 changes: 9 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { projectStoreState, projectStore } from "./project";
import { uiStoreState, uiStore } from "./ui";
import { settingStoreState, settingStore } from "./setting";
import { proxyStore, proxyStoreState } from "./proxy";
import { DefaultStyleId } from "@/type/preload";

const isDevelopment = process.env.NODE_ENV == "development";

Expand Down Expand Up @@ -95,8 +96,14 @@ export const indexStore: VoiceVoxStoreOptions<
async IS_UNSET_DEFAULT_STYLE_IDS() {
return await window.electron.isUnsetDefaultStyleIds();
},
async LOAD_DEFAULT_STYLE_IDS({ commit }) {
const defaultStyleIds = await window.electron.getDefaultStyleIds();
async LOAD_DEFAULT_STYLE_IDS({ commit, state }) {
const characterInfos = await state.characterInfos;
if (characterInfos == undefined)
throw new Error("state.characterInfos == undefined");
const defaultStyleIds = characterInfos.map<DefaultStyleId>((info) => ({
speakerUuid: info.metas.speakerUuid,
defaultStyleId: info.metas.styles[0].styleId,
}));
commit("SET_DEFAULT_STYLE_IDS", { defaultStyleIds });
},
async SET_DEFAULT_STYLE_IDS({ commit }, defaultStyleIds) {
Expand Down
7 changes: 3 additions & 4 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,9 @@ export default defineComponent({
// プロジェクトを初期化
onMounted(async () => {
await Promise.all([
store.dispatch("LOAD_CHARACTER"),
store.dispatch("LOAD_DEFAULT_STYLE_IDS"),
]);
await store.dispatch("LOAD_CHARACTER").then(async () => {
await store.dispatch("LOAD_DEFAULT_STYLE_IDS");
});
if (await store.dispatch("IS_UNSET_DEFAULT_STYLE_IDS")) {
isDefaultStyleSelectDialogOpenComputed.value = true;
}
Expand Down

0 comments on commit fc5e638

Please sign in to comment.