ylacombe commited on
Commit
4dbd274
·
1 Parent(s): e6caac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -42,15 +42,21 @@ def generate_audio(text, model_id):
42
  num_speakers = pipe_dict["pipe"].model.config.num_speakers
43
 
44
  out = []
45
- for i in range(min(num_speakers, max_speakers)):
46
- forward_params = {"speaker_id": i}
47
- output = pipe_dict["pipe"](text, forward_params=forward_params)
48
-
49
- output = gr.Audio(value = (output["sampling_rate"], output["audio"].squeeze()), type="numpy", autoplay=False, label=f"Generated Audio - speaker {i}", show_label=True,
50
- visible=True)
 
 
 
 
 
 
 
51
  out.append(output)
52
-
53
- out.extend([gr.Audio(visible=False)]*(max_speakers-num_speakers))
54
  return out
55
 
56
 
 
42
  num_speakers = pipe_dict["pipe"].model.config.num_speakers
43
 
44
  out = []
45
+ if num_speakers>1:
46
+ for i in range(min(num_speakers, max_speakers)):
47
+ forward_params = {"speaker_id": i}
48
+ output = pipe_dict["pipe"](text, forward_params=forward_params)
49
+
50
+ output = gr.Audio(value = (output["sampling_rate"], output["audio"].squeeze()), type="numpy", autoplay=False, label=f"Generated Audio - speaker {i}", show_label=True,
51
+ visible=True)
52
+ out.append(output)
53
+ out.extend([gr.Audio(visible=False)]*(max_speakers-num_speakers))
54
+ else:
55
+ output = pipe_dict["pipe"](text)
56
+ output = gr.Audio(value = (output["sampling_rate"], output["audio"].squeeze()), type="numpy", autoplay=False, label="Generated Audio - Mono speaker", show_label=True,
57
+ visible=True)
58
  out.append(output)
59
+ out.extend([gr.Audio(visible=False)]*(max_speakers-1))
 
60
  return out
61
 
62