shethjenil commited on
Commit
4df8631
·
verified ·
1 Parent(s): 093302e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -1,23 +1,19 @@
1
- import torch
2
- import torchaudio
3
- from pydub import AudioSegment
4
- import gradio as gr
5
- _original_load = torch.load
6
- def cpu_load(*args, **kwargs):
7
- kwargs["map_location"] = torch.device('cpu')
8
- return _original_load(*args, **kwargs)
9
- torch.load = cpu_load
10
-
11
- hubert = torch.hub.load("bshall/hubert:main", "hubert_soft", trust_repo=True).cpu()
12
- acoustic = torch.hub.load("bshall/acoustic-model:main", "hubert_soft", trust_repo=True).cpu()
13
- hifigan = torch.hub.load("bshall/hifigan:main", "hifigan_hubert_soft", trust_repo=True).cpu()
14
-
15
- def soft_vc(audio_path):
16
- AudioSegment.from_file(audio_path).set_frame_rate(16000).set_channels(1).export(audio_path, format="wav")
17
- source = torchaudio.load(audio_path)[0].unsqueeze(0).cpu()
18
- with torch.inference_mode():
19
- target = hifigan(acoustic.generate(hubert.units(source)).transpose(1, 2))
20
- torchaudio.save("output.wav", target.squeeze(0).cpu(), 16000)
21
- return "output.wav"
22
-
23
  gr.Interface(soft_vc,gr.Audio(label="Input Audio",type="filepath"),gr.Audio(label="Output Audio",type="filepath")).launch()
 
1
+ import torch
2
+ import torchaudio
3
+ import gradio as gr
4
+ from torchaudio.functional import resample
5
+ hubert = torch.hub.load("bshall/hubert:main", "hubert_soft", trust_repo=True)
6
+ acoustic = torch.hub.load("bshall/acoustic-model:main", "hubert_soft", trust_repo=True)
7
+ hifigan = torch.hub.load("bshall/hifigan:main", "hifigan_hubert_soft", trust_repo=True)
8
+
9
+ @torch.inference_mode()
10
+ def soft_vc(audio_path):
11
+ wav,sr = torchaudio.load(audio_path)
12
+ if sr != 16000:
13
+ resample(wav,sr,16000)
14
+ wav = wav.mean(0,True)
15
+ torchaudio.save("output.wav", hifigan(acoustic.generate(hubert.units(wav.unsqueeze(0))).transpose(1, 2)).squeeze(0), 16000)
16
+ return "output.wav"
17
+
18
+
 
 
 
 
19
  gr.Interface(soft_vc,gr.Audio(label="Input Audio",type="filepath"),gr.Audio(label="Output Audio",type="filepath")).launch()