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:
@@ -389,7 +389,7 @@
|
|||||||
- Test segment speaker assignments are respected
|
- Test segment speaker assignments are respected
|
||||||
- _Requirements: 15.7_
|
- _Requirements: 15.7_
|
||||||
|
|
||||||
- [ ] 20. Implement script generation API client function
|
- [x] 20. Implement script generation API client function
|
||||||
- Add generateScript() function to src/api/tts.ts
|
- Add generateScript() function to src/api/tts.ts
|
||||||
- Define ScriptSegment, ScriptRequest, and ScriptResponse TypeScript interfaces
|
- Define ScriptSegment, ScriptRequest, and ScriptResponse TypeScript interfaces
|
||||||
- Implement error handling for script generation
|
- Implement error handling for script generation
|
||||||
|
|||||||
@@ -29,11 +29,36 @@ export interface RolesResponse {
|
|||||||
roles: Role[];
|
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
|
* Request payload for audiobook generation
|
||||||
*/
|
*/
|
||||||
export interface GenerateRequest {
|
export interface GenerateRequest {
|
||||||
text: string;
|
segments?: ScriptSegment[];
|
||||||
|
text?: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
roles: { id: string; voice: string }[];
|
roles: { id: string; voice: string }[];
|
||||||
speed?: number;
|
speed?: number;
|
||||||
@@ -188,6 +213,27 @@ export async function detectRoles(text: string): Promise<RolesResponse> {
|
|||||||
return await response.json();
|
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
|
* Generate an audiobook from text with assigned voices
|
||||||
* @param payload - Generation request with text, language, roles, and speed
|
* @param payload - Generation request with text, language, roles, and speed
|
||||||
|
|||||||
Reference in New Issue
Block a user