add hermes tts playback (#541)
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user