add hermes tts playback (#541)

This commit is contained in:
ekko
2026-05-08 15:34:11 +08:00
committed by GitHub
parent 10d2f892ff
commit d54f9479b9
8 changed files with 218 additions and 144 deletions
@@ -0,0 +1,28 @@
import type { Context } from 'koa'
import { textToSpeech } from '../../services/hermes/tts'
export async function generate(ctx: Context) {
const { text, lang } = ctx.request.body as {
text?: string
lang?: string
}
if (!text || typeof text !== 'string') {
ctx.status = 400
ctx.body = { error: 'text is required' }
return
}
if (text.length > 5000) {
ctx.status = 400
ctx.body = { error: 'text is too long (max 5000 characters)' }
return
}
const { audio, engine } = await textToSpeech({ text, lang })
ctx.set('Content-Type', 'audio/mpeg')
ctx.set('Content-Length', String(audio.length))
ctx.set('X-TTS-Engine', engine)
ctx.body = audio
}