feat: add local audio test mode
This commit is contained in:
75
src/local-main.ts
Normal file
75
src/local-main.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import process from "node:process";
|
||||
|
||||
import type { AssistantRuntimeConfig } from "./config.js";
|
||||
import { Logger } from "./logger.js";
|
||||
import { LocalVoiceSession } from "./audio/local-voice-session.js";
|
||||
import { ElevenLabsSttService } from "./services/elevenlabs-stt.js";
|
||||
import { ElevenLabsTtsService } from "./services/elevenlabs-tts.js";
|
||||
import { OpenAiLlmService } from "./services/openai-llm.js";
|
||||
|
||||
export async function printLocalAudioDevices(): Promise<void> {
|
||||
const runs = [
|
||||
{
|
||||
label: "wpctl status",
|
||||
args: ["status"],
|
||||
},
|
||||
{
|
||||
label: "wpctl status -n",
|
||||
args: ["status", "-n"],
|
||||
},
|
||||
] as const;
|
||||
|
||||
for (const run of runs) {
|
||||
console.log(`\n=== ${run.label} ===`);
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const child = spawn("wpctl", run.args, {
|
||||
stdio: ["ignore", "inherit", "inherit"],
|
||||
});
|
||||
child.on("exit", (code) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
reject(new Error(`wpctl exited with code ${code ?? "null"}`));
|
||||
});
|
||||
child.on("error", reject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function runLocalAssistant(config: AssistantRuntimeConfig, logger: Logger): Promise<void> {
|
||||
const stt = new ElevenLabsSttService(config);
|
||||
const tts = new ElevenLabsTtsService(config);
|
||||
const llm = new OpenAiLlmService(config);
|
||||
const session = new LocalVoiceSession({
|
||||
config,
|
||||
logger,
|
||||
stt,
|
||||
tts,
|
||||
llm,
|
||||
});
|
||||
|
||||
console.log(session.statusSummary());
|
||||
console.log("로컬 음성 테스트를 시작합니다. Ctrl+C 로 종료합니다.");
|
||||
if (config.DEBUG_TEXT_EVENTS) {
|
||||
console.log("텍스트 로그 출력이 켜져 있습니다.");
|
||||
}
|
||||
|
||||
const shutdown = async (exitCode = 0) => {
|
||||
await session.destroy().catch((error) => {
|
||||
logger.warn("Local session shutdown failed", error);
|
||||
});
|
||||
process.exit(exitCode);
|
||||
};
|
||||
|
||||
process.on("SIGINT", () => {
|
||||
void shutdown(0);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", () => {
|
||||
void shutdown(0);
|
||||
});
|
||||
|
||||
await session.start();
|
||||
}
|
||||
Reference in New Issue
Block a user