Skip to content

Commit

Permalink
feat: speaker_infoをURLで受け取るようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
sabonerune committed Jun 24, 2024
1 parent 8438cc5 commit 93d7429
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
const instance = await dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
});
const isReturnUrl =
state.engineManifests[engineId].supportedFeatures.returnResourceUrl ??
false;
const getStyles = async function (
speaker: Speaker,
speakerInfo: SpeakerInfo,
Expand All @@ -302,20 +305,25 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
throw new Error(
`Not found the style id "${style.id}" of "${speaker.name}". `,
);
const voiceSamples = await Promise.all(
styleInfo.voiceSamples.map((voiceSample) => {
return base64ToUri(voiceSample, "audio/wav");
}),
);
const voiceSamples = isReturnUrl
? styleInfo.voiceSamples
: await Promise.all(
styleInfo.voiceSamples.map((voiceSample) => {
return base64ToUri(voiceSample, "audio/wav");
}),
);
styles[i] = {
styleName: style.name,
styleId: StyleId(style.id),
styleType: style.type,
engineId,
iconPath: await base64ImageToUri(styleInfo.icon),
iconPath: isReturnUrl
? styleInfo.icon
: await base64ImageToUri(styleInfo.icon),
portraitPath:
styleInfo.portrait &&
(await base64ImageToUri(styleInfo.portrait)),
isReturnUrl || styleInfo.portrait == undefined
? styleInfo.portrait
: await base64ImageToUri(styleInfo.portrait),
voiceSamplePaths: voiceSamples,
};
}
Expand All @@ -328,10 +336,12 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
// 同じIDの歌手がいる場合は歌手情報を取得し、スタイルをマージする
let speakerInfoPromise: Promise<SpeakerInfo> | undefined = undefined;
let speakerStylePromise: Promise<StyleInfo[]> | undefined = undefined;
const resourceFormat = isReturnUrl ? "url" : undefined;
if (speaker != undefined) {
speakerInfoPromise = instance
.invoke("speakerInfoSpeakerInfoGet")({
speakerUuid: speaker.speakerUuid,
resourceFormat,
})
.catch((error) => {
window.backend.logError(error, `Failed to get speakerInfo.`);
Expand All @@ -348,6 +358,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
singerInfoPromise = instance
.invoke("singerInfoSingerInfoGet")({
speakerUuid: singer.speakerUuid,
resourceFormat,
})
.catch((error) => {
window.backend.logError(error, `Failed to get singerInfo.`);
Expand All @@ -374,7 +385,9 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
]).then((styles) => styles.flat());

const characterInfo: CharacterInfo = {
portraitPath: await base64ImageToUri(baseCharacterInfo.portrait),
portraitPath: isReturnUrl
? baseCharacterInfo.portrait
: await base64ImageToUri(baseCharacterInfo.portrait),
metas: {
speakerUuid: SpeakerId(baseSpeaker.speakerUuid),
speakerName: baseSpeaker.name,
Expand Down

0 comments on commit 93d7429

Please sign in to comment.