feat: add script tts backend
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user