Skip to content

Commit

Permalink
選択した再生デバイスがソングでも適用されるようにする (VOICEVOX#2375)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
X-20A and Hiroshiba authored Nov 28, 2024
1 parent 98157ca commit e0d3869
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ watchEffect(() => {
setThemeToCss(theme);
});
// ソングの再生デバイスを同期
watchEffect(() => {
void store.actions.APPLY_DEVICE_ID_TO_AUDIO_CONTEXT({
device: store.state.savingSetting.audioOutputDevice,
});
});
// ソフトウェアを初期化
const { hotkeyManager } = useHotkeyManager();
const isEnginesReady = ref(false);
Expand Down
18 changes: 18 additions & 0 deletions src/store/singing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import { uuid4 } from "@/helpers/random";
import { convertToWavFileData } from "@/sing/convertToWavFileData";
import { generateWriteErrorMessage } from "@/helpers/fileHelper";
import path from "@/helpers/path";
import { showAlertDialog } from "@/components/Dialog/Dialog";

const logger = createLogger("store/singing");

Expand Down Expand Up @@ -1682,6 +1683,23 @@ export const singingStore = createPartialStore<SingingStoreTypes>({
},
},

APPLY_DEVICE_ID_TO_AUDIO_CONTEXT: {
action(_, { device }) {
if (!audioContext) {
throw new Error("audioContext is undefined.");
}
const sinkId = device === "default" ? "" : device;
audioContext.setSinkId(sinkId).catch((err: unknown) => {
void showAlertDialog({
type: "error",
title: "エラー",
message: "再生デバイスが見つかりません",
});
throw err;
});
},
},

/**
* レンダリングを行う。レンダリング中だった場合は停止して再レンダリングする。
*/
Expand Down
4 changes: 4 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,10 @@ export type SingingStoreTypes = {
SYNC_TRACKS_AND_TRACK_CHANNEL_STRIPS: {
action(): void;
};

APPLY_DEVICE_ID_TO_AUDIO_CONTEXT: {
action(payload: { device: string }): void;
};
};

export type SingingCommandStoreState = {
Expand Down
4 changes: 4 additions & 0 deletions src/type/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ declare global {
setSinkId(deviceID: string): Promise<undefined>; // setSinkIdを認識してくれないため
}

interface AudioContext {
setSinkId: (sinkId: string) => Promise<void>;
}

interface Window {
readonly [SandboxKey]: import("./preload").Sandbox;
}
Expand Down

0 comments on commit e0d3869

Please sign in to comment.