LuisAVasquez commited on
Commit
4a33c20
·
verified ·
1 Parent(s): 2ad0ccc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -1,9 +1,53 @@
1
  import gradio as gr
2
  import os
3
  import bark
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def greet(name):
6
- if os.paht.isfile("pm_voice.npz"):
7
  preffix = "Found the voice file"
8
  else:
9
  preffix = "Voice file not found"
 
1
  import gradio as gr
2
  import os
3
  import bark
4
+ from bark import generate_audio, preload_models, SAMPLE_RATE
5
+ import time
6
+ import scipy
7
+ import noisereduce as nr
8
+
9
+ ########################
10
+ # Voice cloning functions
11
+
12
+ # make sure to only use CPU
13
+ os.environ["CUDA_VISIBLE_DEVICES"] = ""
14
+ os.environ["SUNO_USE_SMALL_MODELS"] = "1"
15
+
16
+ preload_models()
17
+
18
+
19
+ def generate_cloned_voice_audio(text_prompt, history_prompt):
20
+
21
+
22
+ # keep track of duration
23
+ t0 = time.time()
24
+
25
+ # generate cloned voice audio
26
+ audio_array = generate_audio(
27
+ text_prompt,
28
+ history_prompt = history_prompt
29
+ )
30
+
31
+ # keep track of duration
32
+ generation_duration_s = time.time() - t0
33
+ audio_duration_s = audio_array.shape[0] / SAMPLE_RATE
34
+ print(f"took {generation_duration_s:.0f}s to generate {audio_duration_s:.0f}s of audio")
35
+
36
+ # reduce noise
37
+ reduced_noise_audio_array = nr.reduce_noise(y=audio_array, sr=SAMPLE_RATE)
38
+
39
+ # write to file
40
+ audio_output_path = "output_audio.wav"
41
+ noisereduced_audio_output_path = "output_noisereduced_audio.wav"
42
+ scipy.io.wavfile.write(audio_output_path, rate=SAMPLE_RATE, data=audio_array)
43
+ scipy.io.wavfile.write(noisereduced_audio_output_path, rate=SAMPLE_RATE, data=reduced_noise_audio_array)
44
+
45
+ return audio_output_path
46
+
47
+ ########################
48
 
49
  def greet(name):
50
+ if os.path.isfile("pm_voice.npz"):
51
  preffix = "Found the voice file"
52
  else:
53
  preffix = "Voice file not found"