Nunchakuka commited on
Commit
fe33723
·
1 Parent(s): c805553

Update app.py

Browse files

add app changes to choose random voices references

Files changed (1) hide show
  1. app.py +31 -7
app.py CHANGED
@@ -73,8 +73,24 @@ _ = utils.load_checkpoint("checkpoints/freevc-mls.pth", freevc_mls, None)
73
 
74
  print("Loading WavLM for content...")
75
  cmodel = WavLMModel.from_pretrained("microsoft/wavlm-large").to(device)
76
-
77
- def convert(model, src_mic,src_file, tgt):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  """
79
  helper function which checks where source come from
80
  """
@@ -91,9 +107,16 @@ def convert(model, src_mic,src_file, tgt):
91
  logging.error("Source audio not provided")
92
  return
93
 
94
- #if not tgt:
95
- # tgt="52_4703_000002.wav"
96
-
 
 
 
 
 
 
 
97
  with torch.no_grad():
98
  # tgt
99
  wav_tgt, _ = librosa.load(tgt, sr=hps.data.sampling_rate)
@@ -139,8 +162,9 @@ def convert(model, src_mic,src_file, tgt):
139
  model = gr.Dropdown(choices=["FreeVC MLS","FreeVC (24kHz)"], value="FreeVC MLS",type="value", label="Model")
140
  audio1_mic=gr.Audio(source="microphone", type="filepath", label='record your voice', optional=True)
141
  audio1_file = gr.inputs.Audio(type='filepath', label='or upload an audio file', optional=True)
142
- audio2 = gr.inputs.Audio(label="Reference Audio", type='filepath', optional=True)
143
- inputs = [model, audio1_mic, audio1_file, audio2]
 
144
  outputs = gr.outputs.Audio(label="Output Audio", type='filepath')
145
 
146
  title = "Démonstration d'Anonymisation de Voix"
 
73
 
74
  print("Loading WavLM for content...")
75
  cmodel = WavLMModel.from_pretrained("microsoft/wavlm-large").to(device)
76
+
77
+ def get_random_wav_from_directory(directory, gender=None):
78
+ """
79
+ Get a random WAV file from a directory.
80
+ If gender is specified, it fetches a male or female WAV accordingly.
81
+ """
82
+ all_files = [f for f in os.listdir(directory) if f.endswith('.wav')]
83
+
84
+ if gender == "male":
85
+ all_files = [f for f in all_files if "male" in f and "female" not in f]
86
+ elif gender == "female":
87
+ all_files = [f for f in all_files if "female" in f]
88
+
89
+ return random.choice(all_files)
90
+
91
+
92
+
93
+ def convert(model, src_mic,src_file, reference_option):
94
  """
95
  helper function which checks where source come from
96
  """
 
107
  logging.error("Source audio not provided")
108
  return
109
 
110
+ if reference_option == "aléatoire":
111
+ tgt = get_random_wav_from_directory("mls_samples")
112
+ elif reference_option == "aléatoire (homme)":
113
+ tgt = get_random_wav_from_directory("mls_samples", "male")
114
+ elif reference_option == "aléatoire (femme)":
115
+ tgt = get_random_wav_from_directory("mls_samples", "female")
116
+ else:
117
+ logging.error("Option de référence non reconnue")
118
+ return
119
+
120
  with torch.no_grad():
121
  # tgt
122
  wav_tgt, _ = librosa.load(tgt, sr=hps.data.sampling_rate)
 
162
  model = gr.Dropdown(choices=["FreeVC MLS","FreeVC (24kHz)"], value="FreeVC MLS",type="value", label="Model")
163
  audio1_mic=gr.Audio(source="microphone", type="filepath", label='record your voice', optional=True)
164
  audio1_file = gr.inputs.Audio(type='filepath', label='or upload an audio file', optional=True)
165
+ #audio2 = gr.inputs.Audio(label="Reference Audio", type='filepath', optional=True)
166
+ reference_dropdown = gr.Dropdown(choices=["aléatoire", "aléatoire (homme)", "aléatoire (femme)"], value="aléatoire",label="Voix de référence")
167
+ inputs = [model, audio1_mic, audio1_file, reference_dropdown]
168
  outputs = gr.outputs.Audio(label="Output Audio", type='filepath')
169
 
170
  title = "Démonstration d'Anonymisation de Voix"