Update api.py
Browse files
api.py
CHANGED
|
@@ -158,6 +158,26 @@ class ToneColorConverter(OpenVoiceBaseClass):
|
|
| 158 |
return audio
|
| 159 |
else:
|
| 160 |
soundfile.write(output_path, audio, hps.data.sampling_rate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
def add_watermark(self, audio, message):
|
| 163 |
if self.watermark_model is None:
|
|
|
|
| 158 |
return audio
|
| 159 |
else:
|
| 160 |
soundfile.write(output_path, audio, hps.data.sampling_rate)
|
| 161 |
+
|
| 162 |
+
def convert_data(self, audio, sample_rate, src_se, tgt_se, output_path=None, tau=0.3, message="default"):
|
| 163 |
+
hps = self.hps
|
| 164 |
+
# load audio
|
| 165 |
+
audio = torch.tensor(audio).float()
|
| 166 |
+
|
| 167 |
+
with torch.no_grad():
|
| 168 |
+
y = torch.FloatTensor(audio).to(self.device)
|
| 169 |
+
y = y.unsqueeze(0)
|
| 170 |
+
spec = spectrogram_torch(y, hps.data.filter_length,
|
| 171 |
+
hps.data.sampling_rate, hps.data.hop_length, hps.data.win_length,
|
| 172 |
+
center=False).to(self.device)
|
| 173 |
+
spec_lengths = torch.LongTensor([spec.size(-1)]).to(self.device)
|
| 174 |
+
audio = self.model.voice_conversion(spec, spec_lengths, sid_src=src_se, sid_tgt=tgt_se, tau=tau)[0][
|
| 175 |
+
0, 0].data.cpu().float().numpy()
|
| 176 |
+
audio = self.add_watermark(audio, message)
|
| 177 |
+
if output_path is None:
|
| 178 |
+
return audio
|
| 179 |
+
else:
|
| 180 |
+
soundfile.write(output_path, audio, hps.data.sampling_rate)
|
| 181 |
|
| 182 |
def add_watermark(self, audio, message):
|
| 183 |
if self.watermark_model is None:
|