You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat(tts): add support for streaming mode
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Send first audio, make sure it's 16
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
---------
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
tts_request=backend_pb2.TTSRequest(text="VoxCPM is an innovative end-to-end TTS model from ModelBest. This is a streaming test.", dst="test_stream.wav")
69
+
chunks_received=0
70
+
total_audio_bytes=0
71
+
72
+
forreplyinstub.TTSStream(tts_request):
73
+
# Verify that we receive audio chunks
74
+
ifreply.audio:
75
+
chunks_received+=1
76
+
total_audio_bytes+=len(reply.audio)
77
+
self.assertGreater(len(reply.audio), 0, "Audio chunk should not be empty")
78
+
79
+
# Verify that we received multiple chunks
80
+
self.assertGreater(chunks_received, 0, "Should receive at least one audio chunk")
81
+
self.assertGreater(total_audio_bytes, 0, "Total audio bytes should be greater than 0")
82
+
print(f"Received {chunks_received} chunks with {total_audio_bytes} total bytes")
LocalAI supports streaming TTS generation, allowing audio to be played as it's generated. This is useful for real-time applications and reduces latency.
35
+
36
+
To enable streaming, add `"stream": true` to your request:
The audio will be streamed chunk-by-chunk as it's generated, allowing playback to start before generation completes. This is particularly useful for long texts or when you want to minimize perceived latency.
47
+
48
+
You can also pipe the streamed audio directly to audio players like `aplay` (Linux) or save it to a file:
0 commit comments