Implement audio generation endpoint
- Add POST /api/tts endpoint with full request validation - Validate text, language code, speed range, and roles list - Integrate TTSService to generate multi-voice audiobooks - Fix Kokoro pipeline generator handling to properly collect audio - Stream audio response with correct Content-Type (audio/wav) - Add Content-Disposition header with filename (audiobook.wav) - Handle errors gracefully with appropriate HTTP status codes - Add comprehensive test suite for endpoint validation Requirements: 6.1, 6.7, 6.8, 9.5
This commit is contained in:
@@ -185,8 +185,19 @@ class TTSService:
|
||||
for chunk in chunks:
|
||||
try:
|
||||
# Generate audio for chunk
|
||||
audio, _ = pipeline(chunk, voice=voice, speed=speed)
|
||||
audio_chunks.append(audio)
|
||||
result = pipeline(chunk, voice=voice, speed=speed)
|
||||
# Kokoro returns a generator that yields audio arrays
|
||||
# Collect all arrays and concatenate them
|
||||
audio_parts = []
|
||||
for part in result:
|
||||
if isinstance(part, np.ndarray):
|
||||
# Flatten to 1D if needed
|
||||
audio_parts.append(part.flatten())
|
||||
|
||||
# Concatenate all parts
|
||||
if audio_parts:
|
||||
audio = np.concatenate(audio_parts)
|
||||
audio_chunks.append(audio)
|
||||
except Exception as e:
|
||||
logger.error(f"Error synthesizing chunk with voice {voice}: {e}")
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user