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

サンプリングレートに「エンジンのデフォルト」を追加 #973

Merged
Show file tree
Hide file tree
Changes from 10 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
8 changes: 4 additions & 4 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
AcceptTermsStatus,
ToolbarSetting,
EngineInfo,
ElectronStoreType,
MainElectronStoreType,
} from "./type/preload";

import log from "electron-log";
Expand Down Expand Up @@ -258,7 +258,7 @@ const defaultToolbarButtonSetting: ToolbarSetting = [
];

// 設定ファイル
const store = new Store<ElectronStoreType>({
const store = new Store<MainElectronStoreType>({
schema: {
useGpu: {
type: "boolean",
Expand Down Expand Up @@ -291,7 +291,7 @@ const store = new Store<ElectronStoreType>({
exportLab: { type: "boolean", default: false },
exportText: { type: "boolean", default: false },
outputStereo: { type: "boolean", default: false },
outputSamplingRate: { type: "number", default: 24000 },
outputSamplingRate: { type: "number", default: 0 }, // 0 のときはエンジンのデフォルトサンプリングレートを使う
audioOutputDevice: { type: "string", default: "default" },
},
default: {
Expand All @@ -303,7 +303,7 @@ const store = new Store<ElectronStoreType>({
exportLab: false,
exportText: false,
outputStereo: false,
outputSamplingRate: 24000,
outputSamplingRate: 0,
audioOutputDevice: "default",
splitTextWhenPaste: "PERIOD_AND_NEW_LINE",
},
Expand Down
26 changes: 9 additions & 17 deletions src/components/DictionaryManageDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,14 @@
<script lang="ts">
import { computed, defineComponent, ref, watch } from "vue";
import { useStore } from "@/store";
import { AccentPhrase, AudioQuery, UserDictWord } from "@/openapi";
import { AccentPhrase, UserDictWord } from "@/openapi";
import {
convertHiraToKana,
convertLongVowel,
createKanaRegex,
} from "@/store/utility";
import AudioAccent from "@/components/AudioAccent.vue";
import { QInput, useQuasar } from "quasar";
import { AudioItem } from "@/store/type";

const defaultDictPriority = 5;

Expand Down Expand Up @@ -436,25 +435,18 @@ export default defineComponent({
throw new Error(`assert engineId !== undefined`);

if (!accentPhrase.value) return;

nowGenerating.value = true;
const query: AudioQuery = {
accentPhrases: [accentPhrase.value],
speedScale: 1.0,
pitchScale: 0,
intonationScale: 1.0,
volumeScale: 1.0,
prePhonemeLength: 0.1,
postPhonemeLength: 0.1,
outputSamplingRate: store.state.savingSetting.outputSamplingRate,
outputStereo: store.state.savingSetting.outputStereo,
};

const audioItem: AudioItem = {
const audioItem = await store.dispatch("GENERATE_AUDIO_ITEM", {
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
text: yomi.value,
engineId,
styleId: styleId.value,
query,
};
});

if (audioItem.query == undefined)
throw new Error(`assert audioItem.query !== undefined`);

audioItem.query.accentPhrases = [accentPhrase.value];

let blob = await store.dispatch("GET_AUDIO_CACHE_FROM_AUDIO_ITEM", {
audioItem,
Expand Down
10 changes: 4 additions & 6 deletions src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,10 @@
borderless
name="samplingRate"
:model-value="savingSetting.outputSamplingRate"
:options="[24000, 44100, 48000, 88200, 96000]"
:options="['default', 24000, 44100, 48000, 88200, 96000]"
:option-label="
(item) =>
`${item / 1000} kHz${
item === 24000 ? '(デフォルト)' : ''
}`
item === 'default' ? 'デフォルト' : `${item / 1000} kHz`
"
@update:model-value="
handleSavingSettingChange('outputSamplingRate', $event)
Expand Down Expand Up @@ -622,7 +620,7 @@ import { defineComponent, computed, ref } from "vue";
import { useStore } from "@/store";
import { useQuasar } from "quasar";
import {
SavingSetting,
RendererSavingSetting,
ExperimentalSetting,
ActivePointScrollMode,
SplitTextWhenPasteType,
Expand Down Expand Up @@ -810,7 +808,7 @@ export default defineComponent({
const savingSetting = computed(() => store.state.savingSetting);

const handleSavingSettingChange = (
key: keyof SavingSetting,
key: keyof RendererSavingSetting,
data: string | boolean | number
) => {
const storeDispatch = (): void => {
Expand Down
52 changes: 46 additions & 6 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {
import fs from "fs";
import path from "path";

import { Sandbox, SystemError, ElectronStoreType } from "@/type/preload";
import {
Sandbox,
SystemError,
RendererElectronStoreType,
MainElectronStoreType,
RendererSavingSetting,
MainSavingSetting,
} from "@/type/preload";
import { IpcIHData, IpcSOData } from "@/type/ipc";

function ipcRendererInvoke<T extends keyof IpcIHData>(
Expand Down Expand Up @@ -230,19 +237,52 @@ const api: Sandbox = {
ipcRenderer.invoke("ON_VUEX_READY");
},

/**
* 設定情報を取得する。保存用とRenderer用で型が異なるので変換する
*/
getSetting: async (key) => {
return (await ipcRendererInvoke(
const value = (await ipcRendererInvoke(
"GET_SETTING",
key
)) as ElectronStoreType[typeof key];
)) as MainElectronStoreType[typeof key];

let rendererValue: unknown = value;
if (key === "savingSetting") {
const mainValue = value as MainSavingSetting;
rendererValue = {
...mainValue,
outputSamplingRate:
mainValue.outputSamplingRate == 0
? "default"
: mainValue.outputSamplingRate,
} as RendererSavingSetting;
}
return rendererValue as RendererElectronStoreType[typeof key];
},
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved

/**
* 設定情報を保存する。保存用とRenderer用で型が異なるので変換する。
* 返り値はRenderer用の型
*/
setSetting: async (key, newValue) => {
return (await ipcRendererInvoke(
let mainValue: unknown = newValue;
if (key === "savingSetting") {
const rendererValue = newValue as RendererSavingSetting;
mainValue = {
...rendererValue,
outputSamplingRate:
rendererValue.outputSamplingRate === "default"
? 0
: rendererValue.outputSamplingRate,
} as MainSavingSetting;
}

await ipcRendererInvoke(
"SET_SETTING",
key,
newValue
)) as typeof newValue;
mainValue as MainElectronStoreType[typeof key]
);
return newValue;
},
};

Expand Down
13 changes: 9 additions & 4 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
State,
AudioStoreState,
AudioCommandStoreState,
EditorAudioQuery,
AudioStoreTypes,
AudioCommandStoreTypes,
transformCommandStore,
Expand All @@ -30,13 +31,14 @@ import {
createKanaRegex,
currentDateString,
} from "./utility";
import { convertAudioQueryFromEditorToEngine } from "./proxy";
import { createPartialStore } from "./vuex";
import { base64ImageToUri } from "@/helpers/imageHelper";

async function generateUniqueIdAndQuery(
state: State,
audioItem: AudioItem
): Promise<[string, AudioQuery | undefined]> {
): Promise<[string, EditorAudioQuery | undefined]> {
audioItem = JSON.parse(JSON.stringify(audioItem)) as AudioItem;
const audioQuery = audioItem.query;
if (audioQuery != undefined) {
Expand Down Expand Up @@ -1258,7 +1260,10 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
})
.then((instance) =>
instance.invoke("synthesisSynthesisPost")({
audioQuery,
audioQuery: convertAudioQueryFromEditorToEngine(
audioQuery,
state.engineManifests[engineId].defaultSamplingRate
),
speaker,
enableInterrogativeUpspeak:
state.experimentalSetting.enableInterrogativeUpspeak,
Expand Down Expand Up @@ -1977,7 +1982,7 @@ export const audioCommandStore = transformCommandStore(
if (styleId === undefined)
throw new Error("assert styleId !== undefined");

const query: AudioQuery | undefined = state.audioItems[audioKey].query;
const query = state.audioItems[audioKey].query;
try {
if (query !== undefined) {
const accentPhrases: AccentPhrase[] = await dispatch(
Expand Down Expand Up @@ -2183,7 +2188,7 @@ export const audioCommandStore = transformCommandStore(
} & ({ isPause: false; moraIndex: number } | { isPause: true })
) {
const { audioKey, accentPhraseIndex } = payload;
const query: AudioQuery | undefined = state.audioItems[audioKey].query;
const query = state.audioItems[audioKey].query;

const engineId = state.audioItems[audioKey].engineId;
if (engineId === undefined)
Expand Down
16 changes: 15 additions & 1 deletion src/store/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
IEngineConnectorFactory,
OpenAPIEngineConnectorFactory,
} from "@/infrastructures/EngineConnector";
import { AudioQuery } from "@/openapi";
import { EngineInfo } from "@/type/preload";
import { ProxyStoreState, ProxyStoreTypes } from "./type";
import { ProxyStoreState, ProxyStoreTypes, EditorAudioQuery } from "./type";
import { createPartialStore } from "./vuex";

export const proxyStoreState: ProxyStoreState = {};
Expand Down Expand Up @@ -32,4 +33,17 @@ const proxyStoreCreator = (_engineFactory: IEngineConnectorFactory) => {
return proxyStore;
};

export const convertAudioQueryFromEditorToEngine = (
editorAudioQuery: EditorAudioQuery,
defaultOutputSamplingRate: number
): AudioQuery => {
return {
...editorAudioQuery,
outputSamplingRate:
editorAudioQuery.outputSamplingRate == "default"
? defaultOutputSamplingRate
: editorAudioQuery.outputSamplingRate,
};
};

export const proxyStore = proxyStoreCreator(OpenAPIEngineConnectorFactory);
11 changes: 7 additions & 4 deletions src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
HotkeyAction,
HotkeyReturnType,
HotkeySetting,
SavingSetting,
RendererSavingSetting,
ExperimentalSetting,
ThemeColorType,
ThemeConf,
Expand All @@ -27,7 +27,7 @@ export const settingStoreState: SettingStoreState = {
exportLab: false,
exportText: false,
outputStereo: false,
outputSamplingRate: 24000,
outputSamplingRate: "default",
audioOutputDevice: "default",
},
hotkeySettings: [],
Expand Down Expand Up @@ -118,10 +118,13 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
},

SET_SAVING_SETTING: {
mutation(state, { savingSetting }: { savingSetting: SavingSetting }) {
mutation(
state,
{ savingSetting }: { savingSetting: RendererSavingSetting }
) {
state.savingSetting = savingSetting;
},
action({ commit }, { data }: { data: SavingSetting }) {
action({ commit }, { data }: { data: RendererSavingSetting }) {
const newData = window.electron.setSetting("savingSetting", data);
newData.then((savingSetting) => {
commit("SET_SAVING_SETTING", { savingSetting });
Expand Down
17 changes: 12 additions & 5 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
AcceptTermsStatus,
HotkeySetting,
MoraDataType,
SavingSetting,
RendererSavingSetting,
ThemeConf,
ThemeSetting,
ExperimentalSetting,
Expand All @@ -38,12 +38,19 @@ import {
import { IEngineConnectorFactory } from "@/infrastructures/EngineConnector";
import { QVueGlobals } from "quasar";

/**
* エディタ用のAudioQuery
*/
export type EditorAudioQuery = Omit<AudioQuery, "outputSamplingRate"> & {
outputSamplingRate: number | "default";
};

// FIXME: SpeakerIdを追加する
export type AudioItem = {
text: string;
engineId?: string;
styleId?: number;
query?: AudioQuery;
query?: EditorAudioQuery;
presetKey?: string;
};

Expand Down Expand Up @@ -825,7 +832,7 @@ export type ProjectStoreTypes = {
*/

export type SettingStoreState = {
savingSetting: SavingSetting;
savingSetting: RendererSavingSetting;
hotkeySettings: HotkeySetting[];
toolbarSetting: ToolbarSetting;
engineIds: string[];
Expand All @@ -845,8 +852,8 @@ export type SettingStoreTypes = {
};

SET_SAVING_SETTING: {
mutation: { savingSetting: SavingSetting };
action(payload: { data: SavingSetting }): void;
mutation: { savingSetting: RendererSavingSetting };
action(payload: { data: RendererSavingSetting }): void;
};

SET_HOTKEY_SETTINGS: {
Expand Down
6 changes: 3 additions & 3 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
AppInfos,
ElectronStoreType,
RendererElectronStoreType,
EngineInfo,
HotkeySetting,
ThemeSetting,
Expand Down Expand Up @@ -233,12 +233,12 @@ export type IpcIHData = {

// TODO: genericsが使用できないため、unknownで型宣言して実装時に型を付ける
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
GET_SETTING: {
args: [key: keyof ElectronStoreType];
args: [key: keyof RendererElectronStoreType];
return: unknown;
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
};

SET_SETTING: {
args: [key: keyof ElectronStoreType, newValue: unknown];
args: [key: keyof RendererElectronStoreType, newValue: unknown];
return: unknown;
};
};
Expand Down
Loading