From d95d4992fe691b6ae414190b44e454c401613aab Mon Sep 17 00:00:00 2001 From: Lukas Schaefer Date: Tue, 28 Oct 2025 03:49:18 -0400 Subject: [PATCH] feat: return complete audio for kokoro (#6842) Signed-off-by: Lukas Schaefer --- backend/python/kokoro/backend.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/python/kokoro/backend.py b/backend/python/kokoro/backend.py index 32aefa558..43d22238f 100644 --- a/backend/python/kokoro/backend.py +++ b/backend/python/kokoro/backend.py @@ -64,15 +64,15 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): # Generate audio using Kokoro pipeline generator = self.pipeline(request.text, voice=voice) - # Get the first (and typically only) audio segment + speechs = [] + # Get all the audio segment for i, (gs, ps, audio) in enumerate(generator): - # Save audio to the destination file - sf.write(request.dst, audio, 24000) + speechs.append(audio) print(f"Generated audio segment {i}: gs={gs}, ps={ps}", file=sys.stderr) - # For now, we only process the first segment - # If you need to handle multiple segments, you might want to modify this - break - + # Merges the audio segments and writes them to the destination + speech = torch.cat(speechs, dim=0) + sf.write(request.dst, speech, 24000) + except Exception as err: return backend_pb2.Result(success=False, message=f"Unexpected {err=}, {type(err)=}")