Skip to content

Commit

Permalink
サンプリングレートに「エンジンのデフォルト」を追加 (#973)
Browse files Browse the repository at this point in the history
close #925
  • Loading branch information
Hiroshiba authored Nov 29, 2022
1 parent 49b8159 commit 65ad413
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 37 deletions.
15 changes: 12 additions & 3 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ 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: {
oneOf: [{ type: "number" }, { const: "default" }],
default: "default",
},
audioOutputDevice: { type: "string", default: "default" },
},
default: {
Expand All @@ -358,7 +361,7 @@ const store = new Store<ElectronStoreType>({
exportLab: false,
exportText: false,
outputStereo: false,
outputSamplingRate: 24000,
outputSamplingRate: "default",
audioOutputDevice: "default",
splitTextWhenPaste: "PERIOD_AND_NEW_LINE",
},
Expand Down Expand Up @@ -496,7 +499,7 @@ const store = new Store<ElectronStoreType>({
},
},
migrations: {
"0.13": (store) => {
">=0.13": (store) => {
// acceptTems -> acceptTerms
const prevIdentifier = "acceptTems";
const prevValue = store.get(prevIdentifier, undefined) as
Expand All @@ -508,6 +511,12 @@ const store = new Store<ElectronStoreType>({
store.set("acceptTerms", prevValue);
}
},
">=0.14": (store) => {
// 24000 Hz -> "default"
if (store.get("savingSetting").outputSamplingRate == 24000) {
store.set("savingSetting.outputSamplingRate", "default");
}
},
},
});

Expand Down
26 changes: 9 additions & 17 deletions src/components/DictionaryManageDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,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 @@ -461,25 +460,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", {
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
8 changes: 3 additions & 5 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 @@ -818,7 +816,7 @@ export default defineComponent({
data: { ...savingSetting.value, [key]: data },
});
};
if (key === "outputSamplingRate" && data !== 24000) {
if (key === "outputSamplingRate" && data !== "default") {
$q.dialog({
title: "出力サンプリングレートを変更します",
message:
Expand Down
6 changes: 6 additions & 0 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,19 @@ const api: Sandbox = {
ipcRenderer.invoke("ON_VUEX_READY");
},

/**
* 設定情報を取得する
*/
getSetting: async (key) => {
return (await ipcRendererInvoke(
"GET_SETTING",
key
)) as ElectronStoreType[typeof key];
},

/**
* 設定情報を保存する
*/
setSetting: async (key, newValue) => {
return (await ipcRendererInvoke(
"SET_SETTING",
Expand Down
13 changes: 9 additions & 4 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
State,
AudioStoreState,
AudioCommandStoreState,
EditorAudioQuery,
AudioStoreTypes,
AudioCommandStoreTypes,
transformCommandStore,
Expand All @@ -29,13 +30,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 @@ -1052,7 +1054,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 @@ -1777,7 +1782,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 @@ -1983,7 +1988,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);
2 changes: 1 addition & 1 deletion src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const settingStoreState: SettingStoreState = {
exportLab: false,
exportText: false,
outputStereo: false,
outputSamplingRate: 24000,
outputSamplingRate: "default",
audioOutputDevice: "default",
},
hotkeySettings: [],
Expand Down
9 changes: 8 additions & 1 deletion src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,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
10 changes: 6 additions & 4 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,17 @@ export type IpcIHData = {
return: void;
};

// TODO: genericsが使用できないため、unknownで型宣言して実装時に型を付ける
GET_SETTING: {
args: [key: keyof ElectronStoreType];
return: unknown;
return: ElectronStoreType[keyof ElectronStoreType];
};

SET_SETTING: {
args: [key: keyof ElectronStoreType, newValue: unknown];
return: unknown;
args: [
key: keyof ElectronStoreType,
newValue: ElectronStoreType[keyof ElectronStoreType]
];
return: ElectronStoreType[keyof ElectronStoreType];
};

VALIDATE_ENGINE_DIR: {
Expand Down
2 changes: 1 addition & 1 deletion src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export type SavingSetting = {
avoidOverwrite: boolean;
exportText: boolean;
outputStereo: boolean;
outputSamplingRate: number;
outputSamplingRate: number | "default";
audioOutputDevice: string;
};

Expand Down

0 comments on commit 65ad413

Please sign in to comment.