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

feat: アクセント句単位でまとめてモーラ設定値を変更できるようにした #623

Merged
68 changes: 7 additions & 61 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -349,67 +349,13 @@ export default defineComponent({
throw Error("accentPhrases.value === undefined");
}
const accentPhrase = accentPhrases.value[accentPhraseIndex];
const targetMora = accentPhrase.moras[moraIndex];

let diffData = data;
switch (type) {
case "pitch":
diffData -= targetMora.pitch;
break;
case "consonant":
if (targetMora.consonantLength !== undefined) {
diffData -= targetMora.consonantLength;
}
break;
case "vowel":
diffData -= targetMora.vowelLength;
break;
}

accentPhrase.moras.forEach((mora, moraIndex) => {
switch (type) {
case "pitch":
if (mora.pitch > 0) {
const newData = Math.max(
minPitch,
Math.min(maxPitch, mora.pitch + diffData)
);
lastPitches.value[accentPhraseIndex][moraIndex] = newData;
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data: newData,
type,
});
}
break;
case "consonant":
case "vowel":
if (mora.consonantLength !== undefined) {
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data: Math.max(
minMoraLength,
Math.min(maxMoraLength, mora.consonantLength + diffData)
),
type: "consonant",
});
}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data: Math.max(
minMoraLength,
Math.min(maxMoraLength, mora.vowelLength + diffData)
),
type: "vowel",
});
break;
}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
accentPhrase,
moraIndex,
data,
type,
});
}
};
Expand Down
98 changes: 98 additions & 0 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,19 @@ export const audioCommandStore: VoiceVoxStoreOptions<
) {
commit("COMMAND_SET_AUDIO_MORA_DATA", payload);
},
COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE(
{ commit },
payload: {
audioKey: string;
accentPhraseIndex: number;
accentPhrase: AccentPhrase;
moraIndex: number;
data: number;
type: MoraDataType;
}
) {
commit("COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE", payload);
},
COMMAND_SET_AUDIO_SPEED_SCALE(
{ commit },
payload: { audioKey: string; speedScale: number }
Expand Down Expand Up @@ -1953,6 +1966,91 @@ export const audioCommandStore: VoiceVoxStoreOptions<
) {
audioStore.mutations.SET_AUDIO_MORA_DATA(draft, payload);
},
COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE(
draft,
payload: {
audioKey: string;
accentPhraseIndex: number;
accentPhrase: AccentPhrase;
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
moraIndex: number;
data: number;
type: MoraDataType;
}
) {
const maxPitch = 6.5;
const minPitch = 3;
const maxMoraLength = 0.3;
const minMoraLength = 0;
const {
audioKey,
accentPhraseIndex,
accentPhrase,
moraIndex,
data,
type,
} = payload;
const targetMora = accentPhrase.moras[moraIndex];

let diffData = data;
switch (type) {
case "pitch":
diffData -= targetMora.pitch;
break;
case "consonant":
if (targetMora.consonantLength !== undefined) {
diffData -= targetMora.consonantLength;
}
break;
case "vowel":
diffData -= targetMora.vowelLength;
break;
}

accentPhrase.moras.forEach((mora, moraIndex) => {
switch (type) {
case "pitch":
if (mora.pitch > 0) {
const newData = Math.max(
minPitch,
Math.min(maxPitch, mora.pitch + diffData)
);
audioStore.mutations.SET_AUDIO_MORA_DATA(draft, {
audioKey,
accentPhraseIndex,
moraIndex,
data: newData,
type,
});
}
break;
case "consonant":
case "vowel":
if (mora.consonantLength !== undefined) {
audioStore.mutations.SET_AUDIO_MORA_DATA(draft, {
audioKey,
accentPhraseIndex,
moraIndex,
data: Math.max(
minMoraLength,
Math.min(maxMoraLength, mora.consonantLength + diffData)
),
type,
});
}
audioStore.mutations.SET_AUDIO_MORA_DATA(draft, {
audioKey,
accentPhraseIndex,
moraIndex,
data: Math.max(
minMoraLength,
Math.min(maxMoraLength, mora.vowelLength + diffData)
),
type: "vowel",
});
break;
}
});
},
COMMAND_SET_AUDIO_SPEED_SCALE(
draft,
payload: { audioKey: string; speedScale: number }
Expand Down
19 changes: 19 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,25 @@ type AudioCommandStoreTypes = {
}): void;
};

COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE: {
mutation: {
audioKey: string;
accentPhraseIndex: number;
accentPhrase: AccentPhrase;
moraIndex: number;
data: number;
type: MoraDataType;
};
action(payload: {
audioKey: string;
accentPhraseIndex: number;
accentPhrase: AccentPhrase;
moraIndex: number;
data: number;
type: MoraDataType;
}): void;
};

COMMAND_SET_AUDIO_SPEED_SCALE: {
mutation: { audioKey: string; speedScale: number };
action(payload: { audioKey: string; speedScale: number }): void;
Expand Down