feat: implement script generation API client function
- Add ScriptSegment, ScriptRequest, and ScriptResponse TypeScript interfaces - Implement generateScript() function to call /api/tts/script endpoint - Update GenerateRequest interface to support optional segments array - Add comprehensive error handling for script generation - Validates Requirements 15.1, 15.2
This commit is contained in:
@@ -29,11 +29,36 @@ export interface RolesResponse {
|
||||
roles: Role[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a script segment with speaker assignment
|
||||
*/
|
||||
export interface ScriptSegment {
|
||||
id: string;
|
||||
speaker: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request payload for script generation
|
||||
*/
|
||||
export interface ScriptRequest {
|
||||
text: string;
|
||||
roles: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from the script generation endpoint
|
||||
*/
|
||||
export interface ScriptResponse {
|
||||
segments: ScriptSegment[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Request payload for audiobook generation
|
||||
*/
|
||||
export interface GenerateRequest {
|
||||
text: string;
|
||||
segments?: ScriptSegment[];
|
||||
text?: string;
|
||||
lang: string;
|
||||
roles: { id: string; voice: string }[];
|
||||
speed?: number;
|
||||
@@ -188,6 +213,27 @@ export async function detectRoles(text: string): Promise<RolesResponse> {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a script preview with AI-segmented text and speaker assignments
|
||||
* @param request - Script request with text and detected roles
|
||||
* @returns Promise resolving to script segments
|
||||
* @throws ApiError if the request fails
|
||||
*/
|
||||
export async function generateScript(request: ScriptRequest): Promise<ScriptResponse> {
|
||||
const baseUrl = getApiBaseUrl();
|
||||
const url = `${baseUrl}/api/tts/script`;
|
||||
|
||||
const response = await fetchWithErrorHandling(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an audiobook from text with assigned voices
|
||||
* @param payload - Generation request with text, language, roles, and speed
|
||||
|
||||
Reference in New Issue
Block a user