fffiloni commited on
Commit
5f924a4
1 Parent(s): 3c31edb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
-
 
3
 
4
 
5
  from huggingface_hub import snapshot_download
@@ -26,7 +27,26 @@ config = BarkConfig()
26
  model = Bark.init_from_config(config)
27
  model.load_checkpoint(config, checkpoint_dir="checkpoints/bark", eval=True)
28
 
29
- def infer(prompt):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  text = "Hello, my name is Manmay , how are you?"
32
 
@@ -35,7 +55,7 @@ def infer(prompt):
35
 
36
  # cloning a speaker.
37
  # It assumes that you have a speaker file in `bark_voices/speaker_n/speaker.wav` or `bark_voices/speaker_n/speaker.npz`
38
- output_dict = model.synthesize(text, config, speaker_id="speaker", voice_dirs="bark_voices/")
39
  print(output_dict)
40
 
41
  sample_rate = 24000 # Replace with the actual sample rate
@@ -45,4 +65,4 @@ def infer(prompt):
45
 
46
  return "output.wav"
47
 
48
- gr.Interface(fn=infer, inputs=[gr.Textbox()], outputs=[gr.Audio()]).launch()
 
1
  import gradio as gr
2
+ import os
3
+ import shutil
4
 
5
 
6
  from huggingface_hub import snapshot_download
 
27
  model = Bark.init_from_config(config)
28
  model.load_checkpoint(config, checkpoint_dir="checkpoints/bark", eval=True)
29
 
30
+ def infer(prompt, input_wav_file):
31
+
32
+ # Path to your WAV file
33
+ source_path = input_wav_file
34
+
35
+ # Destination directory
36
+ destination_directory = "bark_voices"
37
+
38
+ # Extract the file name without the extension
39
+ file_name = os.path.splitext(os.path.basename(source_path))[0]
40
+
41
+ # Construct the full destination directory path
42
+ destination_path = os.path.join(destination_directory, file_name)
43
+
44
+ # Create the new directory
45
+ os.makedirs(destination_path, exist_ok=True)
46
+
47
+ # Move the WAV file to the new directory
48
+ shutil.move(source_path, os.path.join(destination_path, f"{file_name}.wav"))
49
+
50
 
51
  text = "Hello, my name is Manmay , how are you?"
52
 
 
55
 
56
  # cloning a speaker.
57
  # It assumes that you have a speaker file in `bark_voices/speaker_n/speaker.wav` or `bark_voices/speaker_n/speaker.npz`
58
+ output_dict = model.synthesize(text, config, speaker_id=f"{file_name}", voice_dirs="bark_voices/")
59
  print(output_dict)
60
 
61
  sample_rate = 24000 # Replace with the actual sample rate
 
65
 
66
  return "output.wav"
67
 
68
+ gr.Interface(fn=infer, inputs=[gr.Textbox(), gr.Audio(type="filepath", source="upload")], outputs=[gr.Audio()]).launch()