mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { API_BASE_URL } from '@/config'
|
|
import { fetchWrapper, fetchWrapperBlob } from './fetchWrapper'
|
|
|
|
export interface TTSModelsResponse {
|
|
models: string[]
|
|
cached: boolean
|
|
}
|
|
|
|
export interface TTSVoicesResponse {
|
|
voices: string[]
|
|
cached: boolean
|
|
}
|
|
|
|
export interface TTSStatusResponse {
|
|
enabled: boolean
|
|
configured: boolean
|
|
cache: {
|
|
count: number
|
|
sizeBytes: number
|
|
sizeMB: number
|
|
maxSizeMB: number
|
|
ttlHours: number
|
|
}
|
|
}
|
|
|
|
export const ttsApi = {
|
|
getModels: async (userId = 'default', forceRefresh = false): Promise<TTSModelsResponse> => {
|
|
return fetchWrapper(`${API_BASE_URL}/api/tts/models`, {
|
|
params: { userId, ...(forceRefresh && { refresh: 'true' }) },
|
|
})
|
|
},
|
|
|
|
getVoices: async (userId = 'default', forceRefresh = false): Promise<TTSVoicesResponse> => {
|
|
return fetchWrapper(`${API_BASE_URL}/api/tts/voices`, {
|
|
params: { userId, ...(forceRefresh && { refresh: 'true' }) },
|
|
})
|
|
},
|
|
|
|
getStatus: async (userId = 'default'): Promise<TTSStatusResponse> => {
|
|
return fetchWrapper(`${API_BASE_URL}/api/tts/status`, {
|
|
params: { userId },
|
|
})
|
|
},
|
|
|
|
synthesize: async (text: string, userId = 'default', signal?: AbortSignal): Promise<Blob> => {
|
|
return fetchWrapperBlob(`${API_BASE_URL}/api/tts/synthesize`, {
|
|
method: 'POST',
|
|
params: { userId },
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ text }),
|
|
signal,
|
|
})
|
|
},
|
|
}
|