feat: add script tts backend

This commit is contained in:
2026-05-17 16:36:06 +08:00
parent 1016111d19
commit 6b426c2b68
21 changed files with 808 additions and 5 deletions
+22 -3
View File
@@ -1,18 +1,37 @@
import { get, post } from './request.js'
import { getEnvValue } from '../config/env.js'
const DEFAULT_SOURCE_TYPE = 'epic_script'
const DEFAULT_VOICE = 'default_zh_female'
const normalizeAudioUrl = (task) => {
if (!task?.audioUrl || /^https?:\/\//.test(task.audioUrl)) {
return task
}
return {
...task,
audioUrl: `${getEnvValue('API_BASE_URL')}${task.audioUrl.startsWith('/') ? task.audioUrl : `/${task.audioUrl}`}`
}
}
const normalizeResponse = (response) => {
if (!response?.data) return response
return {
...response,
data: normalizeAudioUrl(response.data)
}
}
export const createTtsTask = ({
sourceType = DEFAULT_SOURCE_TYPE,
sourceId,
voice = DEFAULT_VOICE
}) => {
return post('/tts/tasks', { sourceType, sourceId, voice })
return post('/tts/tasks', { sourceType, sourceId, voice }).then(normalizeResponse)
}
export const getTtsTask = (id) => {
return get(`/tts/tasks/${id}`)
return get(`/tts/tasks/${id}`).then(normalizeResponse)
}
export const getTtsTaskBySource = ({
@@ -20,7 +39,7 @@ export const getTtsTaskBySource = ({
sourceId,
voice = DEFAULT_VOICE
}) => {
return get('/tts/tasks/by-source', { sourceType, sourceId, voice })
return get('/tts/tasks/by-source', { sourceType, sourceId, voice }).then(normalizeResponse)
}
export default {