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
Merged
1 change: 1 addition & 0 deletions public/howtouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Apple Silicon搭載のMacとRosettaの詳しい情報はこちらのリソース
- スライダーの値を変更します
- Ctrl キーを押しながらマウスホイールを使うと更に細かく調整できます
- スライダー →<img src="res/image16.png" style="max-height: 1rem" alt="スライダー、緑色の棒。" />
- Alt キーを押しながらイントネーションや長さを調整することで、同じアクセント区間内を同時に調整できます



Expand Down
67 changes: 43 additions & 24 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
:accentPhraseIndex="accentPhraseIndex"
:value="mora.pitch"
:uiLocked="uiLocked"
:min="3"
:max="6.5"
:min="minPitch"
:max="maxPitch"
:disable="mora.pitch == 0.0"
:type="'pitch'"
:clip="false"
Expand All @@ -84,8 +84,8 @@
:accentPhraseIndex="accentPhraseIndex"
:value="mora.consonantLength"
:uiLocked="uiLocked"
:min="0"
:max="0.3"
:min="minMoraLength"
:max="maxMoraLength"
:step="0.001"
:type="'consonant'"
:clip="true"
Expand All @@ -99,8 +99,8 @@
:accentPhraseIndex="accentPhraseIndex"
:value="mora.vowelLength"
:uiLocked="uiLocked"
:min="0"
:max="0.3"
:min="minMoraLength"
:max="maxMoraLength"
:step="0.001"
:type="'vowel'"
:clip="mora.consonant ? true : false"
Expand Down Expand Up @@ -323,22 +323,39 @@ export default defineComponent({
});
};

const maxPitch = 6.5;
const minPitch = 3;
const maxMoraLength = 0.3;
const minMoraLength = 0;
const changeMoraData = (
accentPhraseIndex: number,
moraIndex: number,
data: number,
type: MoraDataType
) => {
if (type == "pitch") {
lastPitches.value[accentPhraseIndex][moraIndex] = data;
if (!altKeyFlag.value) {
if (type == "pitch") {
lastPitches.value[accentPhraseIndex][moraIndex] = data;
}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data,
type,
});
} else {
if (accentPhrases.value === undefined) {
throw Error("accentPhrases.value === undefined");
}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data,
type,
});
}
store.dispatch("COMMAND_SET_AUDIO_MORA_DATA", {
audioKey: props.activeAudioKey,
accentPhraseIndex,
moraIndex,
data,
type,
});
};

// audio play
Expand Down Expand Up @@ -524,15 +541,13 @@ export default defineComponent({
};

const shiftKeyFlag = ref(false);
const altKeyFlag = ref(false);

const setShiftKeyFlag = (event: KeyboardEvent) => {
const keyEventListter = (event: KeyboardEvent) => {
shiftKeyFlag.value = event.shiftKey;
altKeyFlag.value = event.altKey;
};

function resetShiftKeyFlag(event: KeyboardEvent) {
if (event.key === "Shift") shiftKeyFlag.value = false;
}

Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
const handleChangeVoicing = (
mora: Mora,
accentPhraseIndex: number,
Expand All @@ -558,16 +573,20 @@ export default defineComponent({
};

onMounted(() => {
window.addEventListener("keyup", resetShiftKeyFlag);
document.addEventListener("keydown", setShiftKeyFlag);
window.addEventListener("keyup", keyEventListter);
document.addEventListener("keydown", keyEventListter);
});

onUnmounted(() => {
window.removeEventListener("keyup", resetShiftKeyFlag);
document.removeEventListener("keydown", setShiftKeyFlag);
window.removeEventListener("keyup", keyEventListter);
document.removeEventListener("keydown", keyEventListter);
});

return {
maxPitch,
minPitch,
maxMoraLength,
minMoraLength,
selectDetail,
selectedDetail,
uiLocked,
Expand Down
94 changes: 94 additions & 0 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,18 @@ export const audioCommandStore: VoiceVoxStoreOptions<
) {
commit("COMMAND_SET_AUDIO_MORA_DATA", payload);
},
COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE(
{ commit },
payload: {
audioKey: string;
accentPhraseIndex: number;
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 +1965,88 @@ 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;
moraIndex: number;
data: number;
type: MoraDataType;
}
) {
const maxPitch = 6.5;
const minPitch = 3;
const maxMoraLength = 0.3;
const minMoraLength = 0;
const { audioKey, accentPhraseIndex, moraIndex, data, type } = payload;
const audioItem = draft.audioItems[audioKey];
if (audioItem.query === undefined) {
throw Error("draft.audioItems[audioKey].query === undefined");
}
const accentPhrase = audioItem.query.accentPhrases[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)
);
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: "consonant",
});
}
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
17 changes: 17 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,23 @@ type AudioCommandStoreTypes = {
}): void;
};

COMMAND_SET_AUDIO_MORA_DATA_ACCENT_PHRASE: {
mutation: {
audioKey: string;
accentPhraseIndex: number;
moraIndex: number;
data: number;
type: MoraDataType;
};
action(payload: {
audioKey: string;
accentPhraseIndex: number;
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