Add separate STT and LLM test commands
This commit is contained in:
82
src/index.ts
82
src/index.ts
@@ -1,14 +1,16 @@
|
||||
import process from "node:process";
|
||||
import { createInterface } from "node:readline";
|
||||
|
||||
import { loadConfig } from "./config.js";
|
||||
import { Logger } from "./logger.js";
|
||||
import { printAudioDevices, spawnLoopbackCapture } from "./audio/capture.js";
|
||||
import { RealtimeSegmenter } from "./audio/realtime-segmenter.js";
|
||||
import { FasterWhisperSttService } from "./services/faster-whisper-stt.js";
|
||||
import { OllamaLlmService } from "./services/ollama-llm.js";
|
||||
|
||||
const mode = process.argv[2] ?? "loopback";
|
||||
const mode = process.argv[2] ?? "test-stt";
|
||||
|
||||
async function runLoopback(): Promise<void> {
|
||||
async function runSttTest(): Promise<void> {
|
||||
const config = loadConfig();
|
||||
const logger = new Logger(config.DEBUG ? config.LOG_LEVEL : "error");
|
||||
const stt = new FasterWhisperSttService(config, logger);
|
||||
@@ -104,7 +106,7 @@ async function runLoopback(): Promise<void> {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn("STT failed", error);
|
||||
logger.error("STT failed", error);
|
||||
} finally {
|
||||
transcribing = false;
|
||||
void runNext();
|
||||
@@ -146,7 +148,11 @@ async function runLoopback(): Promise<void> {
|
||||
},
|
||||
onSpeechReady: (samples) => {
|
||||
emittedSegmentCount += 1;
|
||||
logger.info("Speech segment ready", { index: emittedSegmentCount, samples, ms: Math.round((samples / 16000) * 1000) });
|
||||
logger.info("Speech segment ready", {
|
||||
index: emittedSegmentCount,
|
||||
samples,
|
||||
ms: Math.round((samples / 16000) * 1000),
|
||||
});
|
||||
},
|
||||
onSegment: (pcm16) => {
|
||||
const index = nextSegmentIndex++;
|
||||
@@ -188,7 +194,7 @@ async function runLoopback(): Promise<void> {
|
||||
});
|
||||
|
||||
if (config.DEBUG) {
|
||||
console.log("실시간 출력장치 STT를 시작합니다. Ctrl+C 로 종료합니다.");
|
||||
console.log("실시간 출력장치 STT 테스트를 시작합니다. Ctrl+C 로 종료합니다.");
|
||||
console.log(`source: ${config.AUDIO_SOURCE ?? "unset"}`);
|
||||
console.log(`model: ${config.WHISPER_MODEL}`);
|
||||
console.log(`language: ${config.WHISPER_LANGUAGE}`);
|
||||
@@ -208,16 +214,76 @@ async function runLoopback(): Promise<void> {
|
||||
}, 5000).unref();
|
||||
}
|
||||
|
||||
async function runLlmCli(): Promise<void> {
|
||||
const config = loadConfig();
|
||||
const logger = new Logger(config.DEBUG ? config.LOG_LEVEL : "error");
|
||||
const llm = new OllamaLlmService(config, logger);
|
||||
|
||||
await llm.warmup();
|
||||
|
||||
console.log(`LLM CLI 테스트를 시작합니다. model=${config.OLLAMA_MODEL}`);
|
||||
console.log("/exit 로 종료, /reset 으로 대화 초기화");
|
||||
|
||||
const rl = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
prompt: "you> ",
|
||||
});
|
||||
|
||||
rl.prompt();
|
||||
|
||||
rl.on("line", async (line) => {
|
||||
const text = line.trim();
|
||||
|
||||
if (!text) {
|
||||
rl.prompt();
|
||||
return;
|
||||
}
|
||||
|
||||
if (text === "/exit") {
|
||||
rl.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (text === "/reset") {
|
||||
llm.resetConversation();
|
||||
console.log("assistant> 대화 문맥을 초기화했습니다.");
|
||||
rl.prompt();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const startedAt = Date.now();
|
||||
const reply = await llm.generateReply(text);
|
||||
logger.info("LLM latency", {
|
||||
llm_ms: Date.now() - startedAt,
|
||||
});
|
||||
console.log(`assistant> ${reply}`);
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
|
||||
rl.prompt();
|
||||
});
|
||||
|
||||
rl.on("close", () => {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
switch (mode) {
|
||||
case "devices":
|
||||
await printAudioDevices();
|
||||
return;
|
||||
case "loopback":
|
||||
await runLoopback();
|
||||
case "test-stt":
|
||||
await runSttTest();
|
||||
return;
|
||||
case "test-llm":
|
||||
await runLlmCli();
|
||||
return;
|
||||
default:
|
||||
throw new Error(`알 수 없는 실행 모드입니다: ${mode}. 사용 가능: loopback, devices`);
|
||||
throw new Error(`알 수 없는 실행 모드입니다: ${mode}. 사용 가능: test-stt, test-llm, devices`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user