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 14 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
15 changes: 12 additions & 3 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,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 @@ -303,7 +306,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 @@ -434,7 +437,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 @@ -446,6 +449,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 @@ -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
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 @@ -230,13 +230,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 @@ -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);
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 @@ -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
9 changes: 6 additions & 3 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,15 @@ export type IpcIHData = {
// TODO: genericsが使用できないため、unknownで型宣言して実装時に型を付ける
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
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];
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export type SavingSetting = {
avoidOverwrite: boolean;
exportText: boolean;
outputStereo: boolean;
outputSamplingRate: number;
outputSamplingRate: number | "default";
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
audioOutputDevice: string;
};

Expand Down