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

アクセントからイントネーションを再設定する機能 #776

4 changes: 4 additions & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ const defaultHotkeySettings: HotkeySetting[] = [
action: "テキスト読み込む",
combination: "",
},
{
action: "イントネーションをリセット",
combination: "R",
},
];

const defaultToolbarButtonSetting: ToolbarSetting = [
Expand Down
10 changes: 10 additions & 0 deletions src/components/AudioDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ export default defineComponent({
}
},
],
[
"イントネーションをリセット",
() => {
if (!uiLocked.value && store.getters.ACTIVE_AUDIO_KEY) {
store.dispatch("COMMAND_RESET_MORA_PITCH_AND_LENGTH", {
audioKey: store.getters.ACTIVE_AUDIO_KEY,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ショートカットの定義位置はMenuBarかAudioDetailで悩みましたが、操作する対象的にこっちかなぁと判断しました

});
}
},
],
]);
// このコンポーネントは遅延評価なので手動でバインディングを行う
setHotkeyFunctions(hotkeyMap, true);
Expand Down
27 changes: 27 additions & 0 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,33 @@ export const audioCommandStore: VoiceVoxStoreOptions<
});
}
},
async COMMAND_RESET_MORA_PITCH_AND_LENGTH(
{ state, dispatch, commit },
{ audioKey }
) {
const styleId = state.audioItems[audioKey].styleId;
if (styleId == undefined) throw new Error("styleId == undefined");

const query = state.audioItems[audioKey].query;
if (query == undefined) throw new Error("query == undefined");

try {
const newAccentPhases = await dispatch("FETCH_MORA_DATA", {
accentPhrases: query.accentPhrases,
styleId,
});

commit("COMMAND_CHANGE_ACCENT", {
audioKey,
accentPhrases: newAccentPhases,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

やることが全く同じだったため COMMAND_CHANGE_ACCENT のmutationを流用しています。
使いまわすなら SAVE_ACCENT_PHRASES にでも名前を変えるべきか悩みましたが、そうすると変更箇所が増えてしまうのでいったんそのままにしています。

この場合、中身の実装が同じでもactionの対として COMMAND_RESET_MORA_PITCH のmutationを定義すべきだったでしょうか?方針に問題あれば教えてください。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえずそのまま流用でもいいのかなと思いました。
COMMAND実装的に不都合あったりしそうでしょうか👀 @Segu-g

});
} catch (error) {
commit("COMMAND_CHANGE_ACCENT", {
audioKey,
accentPhrases: query.accentPhrases,
});
}
},
COMMAND_SET_AUDIO_MORA_DATA(
{ commit },
payload: {
Expand Down
4 changes: 4 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ type AudioCommandStoreTypes = {
}): void;
};

COMMAND_RESET_MORA_PITCH_AND_LENGTH: {
action(payload: { audioKey: string }): void;
};

COMMAND_SET_AUDIO_MORA_DATA: {
mutation: {
audioKey: string;
Expand Down
3 changes: 2 additions & 1 deletion src/type/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export type HotkeyAction =
| "プロジェクトを名前を付けて保存"
| "プロジェクトを上書き保存"
| "プロジェクト読み込み"
| "テキスト読み込む";
| "テキスト読み込む"
| "イントネーションをリセット";

export type HotkeyCombo = string;

Expand Down