Add realtime loopback STT prototype

This commit is contained in:
2026-05-02 20:20:54 +09:00
parent 10e0dd75db
commit 5775c4809a
17 changed files with 1034 additions and 0 deletions

63
src/python-runtime.ts Normal file
View File

@@ -0,0 +1,63 @@
import { constants as fsConstants } from "node:fs";
import { access } from "node:fs/promises";
import path from "node:path";
import process from "node:process";
import type { AppConfig } from "./config.js";
function splitCommand(command: string): string[] {
const parts = command.match(/(?:[^\s"]+|"[^"]*")+/g) ?? [];
return parts.map((part) => part.replace(/^"(.*)"$/, "$1"));
}
async function fileExists(target: string): Promise<boolean> {
try {
await access(target, fsConstants.X_OK);
return true;
} catch {
return false;
}
}
export async function resolvePythonCommand(config: AppConfig): Promise<{ command: string; args: string[] }> {
return await resolveWorkerPythonCommand(config);
}
export async function resolveBasePythonCommand(config: AppConfig): Promise<{ command: string; args: string[] }> {
const configured = config.LOCAL_AI_PYTHON?.trim();
if (configured) {
const [command, ...args] = splitCommand(configured);
if (!command) {
throw new Error("LOCAL_AI_PYTHON 값이 비어 있습니다.");
}
return { command, args };
}
const venvPath = resolveVenvPythonPath(config);
if (await fileExists(venvPath)) {
return { command: venvPath, args: [] };
}
return await resolveBasePythonCommand(config);
}
export async function resolveWorkerPythonCommand(config: AppConfig): Promise<{ command: string; args: string[] }> {
const venvPath = resolveVenvPythonPath(config);
if (await fileExists(venvPath)) {
return { command: venvPath, args: [] };
}
return await resolveBasePythonCommand(config);
}
export function resolveVenvPythonPath(config: AppConfig): string {
const root = path.resolve(process.cwd(), config.LOCAL_AI_VENV_PATH);
if (process.platform === "win32") {
return path.join(root, "Scripts", "python.exe");
}
return path.join(root, "bin", "python");
}
export function resolveWorkerScript(name: string): string {
return path.resolve(process.cwd(), "python", name);
}