73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
/**
|
|
* TTS 语音合成 API 函数
|
|
*/
|
|
import apiClient from "../client"
|
|
import type {
|
|
TTSSynthesizeRequest,
|
|
TTSSynthesizeResponse,
|
|
TTSJob,
|
|
TTSJobStatus,
|
|
TTSJobListResponse,
|
|
TTSJobListParams,
|
|
SaveTtsToLibraryRequest,
|
|
TTSVoice,
|
|
TTSPreviewRequest,
|
|
TTSPreviewResponse,
|
|
} from "./types"
|
|
|
|
/** 创建 TTS 合成任务 */
|
|
export const synthesizeSpeech = async (
|
|
data: TTSSynthesizeRequest,
|
|
): Promise<TTSSynthesizeResponse> => {
|
|
const response = await apiClient.post<TTSSynthesizeResponse>("/tts/synthesize", data)
|
|
return response.data
|
|
}
|
|
|
|
/** 获取 TTS 任务详情 */
|
|
export const getTTSJob = async (jobId: string): Promise<TTSJob> => {
|
|
const response = await apiClient.get<TTSJob>(`/tts/jobs/${jobId}`)
|
|
return response.data
|
|
}
|
|
|
|
/** 获取 TTS 任务状态(轻量轮询) */
|
|
export const getTTSJobStatus = async (jobId: string): Promise<TTSJobStatus> => {
|
|
const response = await apiClient.get<TTSJobStatus>(`/tts/jobs/${jobId}/status`)
|
|
return response.data
|
|
}
|
|
|
|
/** 获取 TTS 任务列表 */
|
|
export const getTTSJobs = async (params?: TTSJobListParams): Promise<TTSJobListResponse> => {
|
|
const searchParams = new URLSearchParams()
|
|
if (params?.status) searchParams.set("status", params.status)
|
|
if (params?.skip !== undefined) searchParams.set("skip", String(params.skip))
|
|
if (params?.limit !== undefined) searchParams.set("limit", String(params.limit))
|
|
const qs = searchParams.toString()
|
|
const response = await apiClient.get<TTSJobListResponse>(`/tts/jobs${qs ? `?${qs}` : ""}`)
|
|
return response.data
|
|
}
|
|
|
|
/** 将 TTS 合成结果保存到配音库 */
|
|
export const saveTtsToLibrary = async (
|
|
jobId: string,
|
|
data?: SaveTtsToLibraryRequest,
|
|
): Promise<void> => {
|
|
await apiClient.post(`/tts/jobs/${jobId}/save-to-library`, data ?? {})
|
|
}
|
|
|
|
/** 删除 TTS 任务 */
|
|
export const deleteTTSJob = async (jobId: string): Promise<void> => {
|
|
await apiClient.delete(`/tts/jobs/${jobId}`)
|
|
}
|
|
|
|
/** 获取 TTS 音色列表 */
|
|
export const getTtsVoices = async (): Promise<TTSVoice[]> => {
|
|
const response = await apiClient.get<TTSVoice[]>("/tts/voices")
|
|
return response.data
|
|
}
|
|
|
|
/** TTS 试听 */
|
|
export const previewTts = async (data: TTSPreviewRequest): Promise<TTSPreviewResponse> => {
|
|
const response = await apiClient.post<TTSPreviewResponse>("/tts/preview", data)
|
|
return response.data
|
|
}
|