Skip to content

Commit

Permalink
ENH: audioStoreにモーフィング適用するための操作を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
sabonerune committed Dec 1, 2022
1 parent 65ad413 commit d5a6d91
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
66 changes: 62 additions & 4 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
DefaultStyleId,
Encoding as EncodingType,
MoraDataType,
MorphingInfo,
StyleInfo,
WriteFileErrorResult,
} from "@/type/preload";
Expand Down Expand Up @@ -51,6 +52,7 @@ async function generateUniqueIdAndQuery(
audioQuery,
audioItem.engineId,
audioItem.styleId,
audioItem.morphingInfo,
state.experimentalSetting.enableInterrogativeUpspeak, // このフラグが違うと、同じAudioQueryで違う音声が生成されるので追加
])
);
Expand Down Expand Up @@ -477,6 +479,12 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
baseAudioItem.query.outputSamplingRate;
audioItem.query.outputStereo = baseAudioItem.query.outputStereo;
}
if (
baseAudioItem &&
audioItem.engineId === baseAudioItem.morphingInfo?.targetEngineId
) {
audioItem.morphingInfo = baseAudioItem.morphingInfo;
}
return audioItem;
},
},
Expand Down Expand Up @@ -670,6 +678,19 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
},
},

SET_MORPHING_INFO: {
mutation(
state,
{
audioKey,
morphingInfo,
}: { audioKey: string; morphingInfo: MorphingInfo }
) {
const item = state.audioItems[audioKey];
item.morphingInfo = morphingInfo;
},
},

SET_AUDIO_QUERY: {
mutation(
state,
Expand Down Expand Up @@ -721,6 +742,11 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
) {
state.audioItems[audioKey].engineId = engineId;
state.audioItems[audioKey].styleId = styleId;
if (
state.audioItems[audioKey].morphingInfo?.targetEngineId !== engineId
) {
state.audioItems[audioKey].morphingInfo = undefined;
}
},
},

Expand Down Expand Up @@ -1052,17 +1078,28 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
return dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
})
.then((instance) =>
instance.invoke("synthesisSynthesisPost")({
.then((instance) => {
if (audioItem.morphingInfo) {
return instance.invoke("synthesisMorphingSynthesisMorphingPost")({
audioQuery: convertAudioQueryFromEditorToEngine(
audioQuery,
state.engineManifests[engineId].defaultSamplingRate
),
baseSpeaker: speaker,
targetSpeaker: audioItem.morphingInfo.targetStyleId,
morphRate: audioItem.morphingInfo.rate,
});
}
return instance.invoke("synthesisSynthesisPost")({
audioQuery: convertAudioQueryFromEditorToEngine(
audioQuery,
state.engineManifests[engineId].defaultSamplingRate
),
speaker,
enableInterrogativeUpspeak:
state.experimentalSetting.enableInterrogativeUpspeak,
})
)
});
})
.then(async (blob) => {
audioBlobCache[id] = blob;
return blob;
Expand Down Expand Up @@ -2463,6 +2500,27 @@ export const audioCommandStore = transformCommandStore(
},
},

COMMAND_SET_MORPHING_INFO: {
mutation(
draft,
payload: {
audioKey: string;
morphingInfo: MorphingInfo;
}
) {
audioStore.mutations.SET_MORPHING_INFO(draft, payload);
},
action(
{ commit },
payload: {
audioKey: string;
morphingInfo: MorphingInfo;
}
) {
commit("COMMAND_SET_MORPHING_INFO", payload);
},
},

COMMAND_SET_AUDIO_PRESET: {
mutation(
draft,
Expand Down
17 changes: 17 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ToolbarSetting,
UpdateInfo,
Preset,
MorphingInfo,
ActivePointScrollMode,
EngineInfo,
SplitTextWhenPasteType,
Expand All @@ -53,6 +54,7 @@ export type AudioItem = {
styleId?: number;
query?: EditorAudioQuery;
presetKey?: string;
morphingInfo?: MorphingInfo;
};

export type AudioState = {
Expand Down Expand Up @@ -264,6 +266,13 @@ export type AudioStoreTypes = {
mutation: { audioKey: string; postPhonemeLength: number };
};

SET_MORPHING_INFO: {
mutation: {
audioKey: string;
morphingInfo: MorphingInfo;
};
};

SET_AUDIO_QUERY: {
mutation: { audioKey: string; audioQuery: AudioQuery };
action(payload: { audioKey: string; audioQuery: AudioQuery }): void;
Expand Down Expand Up @@ -576,6 +585,14 @@ export type AudioCommandStoreTypes = {
action(payload: { audioKey: string; postPhonemeLength: number }): void;
};

COMMAND_SET_MORPHING_INFO: {
mutation: {
audioKey: string;
morphingInfo: MorphingInfo;
};
action(payload: { audioKey: string; morphingInfo: MorphingInfo }): void;
};

COMMAND_SET_AUDIO_PRESET: {
mutation: {
audioKey: string;
Expand Down
9 changes: 9 additions & 0 deletions src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ export type Preset = {
postPhonemeLength: number;
};

export type MorphingInfo =
| {
rate: number;
targetEngineId: string;
targetSpeakerId: string;
targetStyleId: number;
}
| undefined;

export type PresetConfig = {
items: Record<string, Preset>;
keys: string[];
Expand Down

0 comments on commit d5a6d91

Please sign in to comment.