import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { TTS_FILE_BODY_KEYS, enqueueTtsFile, } from "yt-dlp-transcript-common/controller/ttsFile"; import { jobResponse, ops } from "../_lib"; export const dynamic = "force-dynamic"; // POST { text | file, voice?, engine?, speed?, out?, tuning?, reading? } -> { ok: true, jobId } // // Speak a line with a local text-to-speech engine and a STOCK voice, as a job on // /jobs (`tts-file`, the `tts` queue, one synthesis at a time) — narration is // never synthesized by hand. `text` is the words, or `file` an absolute path to // a UTF-8 text file holding them (at most 20,000 characters); `engine` // (`kokoro` | `orpheus` | `espeak-ng`), `voice` (one of the engine's stock // voices; Orpheus: zac by default, leah the female option) and `speed` (0.5-2; // Orpheus has none) default to settings.tts (kokoro · af_heart · 1); `out` is // an absolute .wav path the result is copied to. `tuning` ({temperature 0.1-1.5, // top_p 0.05-1, top_k 0-200, min_p 0-0.5, repeat_penalty 1-2, takes 1-6}, any // of them; the rest stay Orpheus's defaults) and `reading` (a whole number // 0-99999; 0 = the first) read the same words again differently, as a new // cached file; kokoro and espeak-ng ignore both and say so in the result's // `note` (common/lib/ttsTuning.mjs). The expressive tags // (``, ``, ... lib/ttsText.ts TTS_EXPRESSIVE_TAGS) are performed by // Orpheus and stripped for the others; any other `<...>` is refused. Orpheus // runs on the GPU, on a llama-server the editor starts for the batch and stops // once the `tts` queue is idle, and waits while a transcription holds the GPU. // // The job's log ends with the result as ONE line, `@@tts-result {json}`: // `{wav, seconds, engine, voice, cached, durationMs (the engine's time), waitedMs // (the wait on the queue), sha, sampleRate, speed, disclosure}`, plus for // Orpheus `{tuning, reading, seedBase}` -- every value it was made with, the // defaults included -- and `note` when a tuning was ignored. `wav` is an // absolute path this editor wrote: `out` when given, else the cache file // (`/.wav`, 48 kHz mono 16-bit, a `.json` sidecar // beside it). The same ask again is a `done` job with `cached: true` that runs // no engine. `pnpm ops tts --wait` prints that JSON on stdout. // // AN ADAPTER: every refusal is the controller's (controller/ttsFile.ts) — both // or neither of text and file, an unknown engine or voice, a speed out of // range, a tuning value or reading out of its range, an unknown tag, an engine not installed (`archilyzer tts setup`), an // `out` or a cache dir inside the corpus. export async function POST(request: Request) { return ops(request, TTS_FILE_BODY_KEYS, async (body) => jobResponse(await enqueueTtsFile(body, { paths: getPaths() })), ); }