Expose all available voices from both TTS engines via the /api/voices endpoint. AudioPlayer and profile voice-selector now group voices by engine and show a labelled optgroup. Voice type carries an engine field so the chapter-reader can route synthesis to the correct backend.
23 lines
614 B
TypeScript
23 lines
614 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { backendFetch } from '$lib/server/scraper';
|
|
import type { Voice } from '$lib/types';
|
|
|
|
/**
|
|
* GET /api/voices
|
|
* Proxies the voice list from the backend (Kokoro + pocket-tts).
|
|
* Returns { voices: Voice[] }
|
|
*/
|
|
export const GET: RequestHandler = async () => {
|
|
try {
|
|
const res = await backendFetch('/api/voices');
|
|
if (!res.ok) {
|
|
return json({ voices: [] });
|
|
}
|
|
const data = (await res.json()) as { voices: Voice[] };
|
|
return json({ voices: data.voices ?? [] });
|
|
} catch {
|
|
return json({ voices: [] });
|
|
}
|
|
};
|