Spaces:
Sleeping
Sleeping
nam pham
commited on
Commit
·
6394a29
1
Parent(s):
2438f4f
fix: change local variable
Browse files- app/server.py +9 -3
app/server.py
CHANGED
@@ -105,18 +105,24 @@ class KokoroAPI(ls.LitAPI):
|
|
105 |
try:
|
106 |
# Generate audio files
|
107 |
generator = self.pipeline(text, voice=voice, speed=1, split_pattern=r"\n+")
|
108 |
-
|
109 |
# Create the output directory if it does not exist
|
110 |
output_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'output')
|
111 |
os.makedirs(output_dir, exist_ok=True)
|
112 |
-
|
113 |
# Save each audio file
|
|
|
114 |
for i, (gs, ps, audio) in enumerate(generator):
|
115 |
file_path = f"{output_dir}/{i}.wav"
|
116 |
sf.write(file_path, audio, 24000)
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
# Combine all audio files
|
119 |
-
final_audio, samplerate = combine_audio_files(output_dir,
|
120 |
|
121 |
# Save the final audio to a buffer
|
122 |
audio_buffer = io.BytesIO()
|
|
|
105 |
try:
|
106 |
# Generate audio files
|
107 |
generator = self.pipeline(text, voice=voice, speed=1, split_pattern=r"\n+")
|
108 |
+
|
109 |
# Create the output directory if it does not exist
|
110 |
output_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'output')
|
111 |
os.makedirs(output_dir, exist_ok=True)
|
112 |
+
|
113 |
# Save each audio file
|
114 |
+
file_count = 0
|
115 |
for i, (gs, ps, audio) in enumerate(generator):
|
116 |
file_path = f"{output_dir}/{i}.wav"
|
117 |
sf.write(file_path, audio, 24000)
|
118 |
+
file_count = i + 1 # Keep track of number of files
|
119 |
+
|
120 |
+
if file_count == 0:
|
121 |
+
# Handle case where no audio was generated
|
122 |
+
return None
|
123 |
|
124 |
# Combine all audio files
|
125 |
+
final_audio, samplerate = combine_audio_files(output_dir, file_count - 1)
|
126 |
|
127 |
# Save the final audio to a buffer
|
128 |
audio_buffer = io.BytesIO()
|