mrfakename commited on
Commit
1dda0cc
1 Parent(s): f6a409f

Sync from GitHub repo

Browse files

This Space is synced from the GitHub repo: https://github.com/SWivid/F5-TTS. Please submit contributions to the Space there

Files changed (1) hide show
  1. src/f5_tts/socket_server.py +9 -13
src/f5_tts/socket_server.py CHANGED
@@ -74,6 +74,11 @@ class TTSStreamingProcessor:
74
  # Break the generated audio into chunks and send them
75
  chunk_size = int(final_sample_rate * play_steps_in_s)
76
 
 
 
 
 
 
77
  for i in range(0, len(audio_chunk), chunk_size):
78
  chunk = audio_chunk[i : i + chunk_size]
79
 
@@ -81,19 +86,10 @@ class TTSStreamingProcessor:
81
  if i + chunk_size >= len(audio_chunk):
82
  chunk = audio_chunk[i:]
83
 
84
- # Avoid sending empty or repeated chunks
85
- if len(chunk) == 0:
86
- break
87
-
88
- # Pack and send the audio chunk
89
- packed_audio = struct.pack(f"{len(chunk)}f", *chunk)
90
- yield packed_audio
91
-
92
- # Ensure that no final word is repeated by not resending partial chunks
93
- if len(audio_chunk) % chunk_size != 0:
94
- remaining_chunk = audio_chunk[-(len(audio_chunk) % chunk_size) :]
95
- packed_audio = struct.pack(f"{len(remaining_chunk)}f", *remaining_chunk)
96
- yield packed_audio
97
 
98
 
99
  def handle_client(client_socket, processor):
 
74
  # Break the generated audio into chunks and send them
75
  chunk_size = int(final_sample_rate * play_steps_in_s)
76
 
77
+ if len(audio_chunk) < chunk_size:
78
+ packed_audio = struct.pack(f"{len(audio_chunk)}f", *audio_chunk)
79
+ yield packed_audio
80
+ return
81
+
82
  for i in range(0, len(audio_chunk), chunk_size):
83
  chunk = audio_chunk[i : i + chunk_size]
84
 
 
86
  if i + chunk_size >= len(audio_chunk):
87
  chunk = audio_chunk[i:]
88
 
89
+ # Send the chunk if it is not empty
90
+ if len(chunk) > 0:
91
+ packed_audio = struct.pack(f"{len(chunk)}f", *chunk)
92
+ yield packed_audio
 
 
 
 
 
 
 
 
 
93
 
94
 
95
  def handle_client(client_socket, processor):