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

#2352 の変更提案プルリクエスト #2

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions src/openapi/models/AudioQuery.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/openapi/models/Preset.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 18 additions & 11 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AudioCommandStoreTypes,
transformCommandStore,
FetchAudioResult,
EditorAudioQuery,
} from "./type";
import {
buildAudioFileNameFromRawData,
Expand All @@ -34,6 +35,7 @@ import {
isMorphable,
} from "./audioGenerate";
import { ContinuousPlayer } from "./audioContinuousPlayer";
import { convertAudioQueryFromEngineToEditor } from "./proxy";
import {
convertHiraToKana,
convertLongVowel,
Expand Down Expand Up @@ -968,13 +970,16 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
SET_AUDIO_QUERY: {
mutation(
state,
{ audioKey, audioQuery }: { audioKey: AudioKey; audioQuery: AudioQuery },
{
audioKey,
audioQuery,
}: { audioKey: AudioKey; audioQuery: EditorAudioQuery },
) {
state.audioItems[audioKey].query = audioQuery;
},
action(
{ mutations },
payload: { audioKey: AudioKey; audioQuery: AudioQuery },
payload: { audioKey: AudioKey; audioQuery: EditorAudioQuery },
) {
mutations.SET_AUDIO_QUERY(payload);
},
Expand All @@ -993,11 +998,13 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
.INSTANTIATE_ENGINE_CONNECTOR({
engineId,
})
.then((instance) =>
instance.invoke("audioQueryAudioQueryPost")({
text,
speaker: styleId,
}),
.then(async (instance) =>
convertAudioQueryFromEngineToEditor(
await instance.invoke("audioQueryAudioQueryPost")({
text,
speaker: styleId,
}),
),
)
.catch((error) => {
window.backend.logError(
Expand Down Expand Up @@ -1941,7 +1948,7 @@ export const audioCommandStore = transformCommandStore(
payload: { audioKey: AudioKey; text: string } & (
| { update: "Text" }
| { update: "AccentPhrases"; accentPhrases: AccentPhrase[] }
| { update: "AudioQuery"; query: AudioQuery }
| { update: "AudioQuery"; query: EditorAudioQuery }
),
) {
audioStore.mutations.SET_AUDIO_TEXT(draft, {
Expand Down Expand Up @@ -2047,7 +2054,7 @@ export const audioCommandStore = transformCommandStore(
}
| {
update: "AudioQuery";
query: AudioQuery;
query: EditorAudioQuery;
}
| {
update: "OnlyVoice";
Expand Down Expand Up @@ -2111,7 +2118,7 @@ export const audioCommandStore = transformCommandStore(
}
| {
update: "AudioQuery";
query: AudioQuery;
query: EditorAudioQuery;
}
| {
update: "OnlyVoice";
Expand All @@ -2122,7 +2129,7 @@ export const audioCommandStore = transformCommandStore(
try {
const audioItem = state.audioItems[audioKey];
if (audioItem.query == undefined) {
const query: AudioQuery = await actions.FETCH_AUDIO_QUERY({
const query = await actions.FETCH_AUDIO_QUERY({
text: audioItem.text,
engineId: voice.engineId,
styleId: voice.styleId,
Expand Down
11 changes: 11 additions & 0 deletions src/store/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const proxyStoreCreator = (_engineFactory: IEngineConnectorFactory) => {
return proxyStore;
};

/** AudioQueryをエンジン用に変換する */
export const convertAudioQueryFromEditorToEngine = (
editorAudioQuery: EditorAudioQuery,
defaultOutputSamplingRate: number,
Expand All @@ -56,4 +57,14 @@ export const convertAudioQueryFromEditorToEngine = (
};
};

/** AudioQueryをエディタ用に変換する */
export const convertAudioQueryFromEngineToEditor = (
engineAudioQuery: AudioQuery,
): EditorAudioQuery => {
return {
...engineAudioQuery,
pauseLengthScale: engineAudioQuery.pauseLengthScale ?? 1,
};
};

export const proxyStore = proxyStoreCreator(OpenAPIEngineConnectorFactory);
16 changes: 10 additions & 6 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ import {
/**
* エディタ用のAudioQuery
*/
export type EditorAudioQuery = Omit<AudioQuery, "outputSamplingRate"> & {
export type EditorAudioQuery = Omit<
AudioQuery,
"outputSamplingRate" | "pauseLengthScale"
> & {
outputSamplingRate: number | "engineDefault";
pauseLengthScale: number; // エンジンと違って必須
};

export type AudioItem = {
Expand Down Expand Up @@ -333,16 +337,16 @@ export type AudioStoreTypes = {
};

SET_AUDIO_QUERY: {
mutation: { audioKey: AudioKey; audioQuery: AudioQuery };
action(payload: { audioKey: AudioKey; audioQuery: AudioQuery }): void;
mutation: { audioKey: AudioKey; audioQuery: EditorAudioQuery };
action(payload: { audioKey: AudioKey; audioQuery: EditorAudioQuery }): void;
};

FETCH_AUDIO_QUERY: {
action(payload: {
text: string;
engineId: EngineId;
styleId: StyleId;
}): Promise<AudioQuery>;
}): Promise<EditorAudioQuery>;
};

SET_AUDIO_VOICE: {
Expand Down Expand Up @@ -510,7 +514,7 @@ export type AudioCommandStoreTypes = {
mutation: { audioKey: AudioKey; text: string } & (
| { update: "Text" }
| { update: "AccentPhrases"; accentPhrases: AccentPhrase[] }
| { update: "AudioQuery"; query: AudioQuery }
| { update: "AudioQuery"; query: EditorAudioQuery }
);
action(payload: { audioKey: AudioKey; text: string }): void;
};
Expand All @@ -526,7 +530,7 @@ export type AudioCommandStoreTypes = {
}
| {
update: "AudioQuery";
query: AudioQuery;
query: EditorAudioQuery;
}
| {
update: "OnlyVoice";
Expand Down
Loading