Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -142,18 +142,18 @@ def generate_speech(text, voice1, voice2, temperature, top_p, repetition_penalty
|
|
142 |
|
143 |
try:
|
144 |
progress(0.1, "Processing text...")
|
145 |
-
|
146 |
audio_samples = []
|
147 |
|
148 |
-
for i,
|
149 |
-
if not
|
150 |
continue
|
151 |
|
152 |
voice = voice1 if num_hosts == "1" or i % 2 == 0 else voice2
|
153 |
|
154 |
-
input_ids, attention_mask = process_prompt(
|
155 |
|
156 |
-
progress(0.3, f"Generating speech tokens for
|
157 |
with torch.no_grad():
|
158 |
generated_ids = model.generate(
|
159 |
input_ids,
|
@@ -167,12 +167,12 @@ def generate_speech(text, voice1, voice2, temperature, top_p, repetition_penalty
|
|
167 |
eos_token_id=128258,
|
168 |
)
|
169 |
|
170 |
-
progress(0.6, f"Processing speech tokens for
|
171 |
code_list = parse_output(generated_ids)
|
172 |
|
173 |
-
progress(0.8, f"Converting
|
174 |
-
|
175 |
-
audio_samples.append(
|
176 |
|
177 |
final_audio = np.concatenate(audio_samples)
|
178 |
|
|
|
142 |
|
143 |
try:
|
144 |
progress(0.1, "Processing text...")
|
145 |
+
paragraphs = text.split('\n\n') # Split by double newline
|
146 |
audio_samples = []
|
147 |
|
148 |
+
for i, paragraph in enumerate(paragraphs):
|
149 |
+
if not paragraph.strip():
|
150 |
continue
|
151 |
|
152 |
voice = voice1 if num_hosts == "1" or i % 2 == 0 else voice2
|
153 |
|
154 |
+
input_ids, attention_mask = process_prompt(paragraph, voice, tokenizer, device)
|
155 |
|
156 |
+
progress(0.3, f"Generating speech tokens for paragraph {i+1}...")
|
157 |
with torch.no_grad():
|
158 |
generated_ids = model.generate(
|
159 |
input_ids,
|
|
|
167 |
eos_token_id=128258,
|
168 |
)
|
169 |
|
170 |
+
progress(0.6, f"Processing speech tokens for paragraph {i+1}...")
|
171 |
code_list = parse_output(generated_ids)
|
172 |
|
173 |
+
progress(0.8, f"Converting paragraph {i+1} to audio...")
|
174 |
+
paragraph_audio = redistribute_codes(code_list, snac_model)
|
175 |
+
audio_samples.append(paragraph_audio)
|
176 |
|
177 |
final_audio = np.concatenate(audio_samples)
|
178 |
|