35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { config as loadDotenv } from "dotenv";
|
|
import { z } from "zod";
|
|
|
|
loadDotenv();
|
|
|
|
const emptyToUndefined = z.preprocess((value) => {
|
|
if (typeof value !== "string") {
|
|
return value;
|
|
}
|
|
const trimmed = value.trim();
|
|
return trimmed.length === 0 ? undefined : trimmed;
|
|
}, z.string().min(1).optional());
|
|
|
|
const envSchema = z.object({
|
|
LOCAL_AI_VENV_PATH: z.string().min(1).default(".local-ai/.venv"),
|
|
LOCAL_AI_PYTHON: emptyToUndefined,
|
|
AUDIO_SOURCE: emptyToUndefined,
|
|
WHISPER_MODEL: z.string().min(1).default("large-v3-turbo"),
|
|
WHISPER_LANGUAGE: z.string().min(1).default("ko"),
|
|
WHISPER_DEVICE: z.enum(["auto", "cuda", "cpu"]).default("auto"),
|
|
WHISPER_COMPUTE_TYPE: z.string().min(1).default("auto"),
|
|
WHISPER_BEAM_SIZE: z.coerce.number().int().min(1).max(8).default(1),
|
|
DEBUG_TRANSCRIPTS: z
|
|
.string()
|
|
.optional()
|
|
.transform((value) => value === "true"),
|
|
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
|
});
|
|
|
|
export type AppConfig = z.infer<typeof envSchema>;
|
|
|
|
export function loadConfig(): AppConfig {
|
|
return envSchema.parse(process.env);
|
|
}
|