WeVi commited on
Commit
80ee679
·
verified ·
1 Parent(s): 6494153

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -1,31 +1,37 @@
1
  import torch
 
2
  import gradio as gr
3
  from bark import generate_audio, SAMPLE_RATE
4
  from scipy.io.wavfile import write as write_wav
5
- import numpy as np
6
- import os
7
 
8
- # Fix for PyTorch 2.6+ loading bug
9
- import numpy.core.multiarray
10
- import torch.serialization
11
 
12
- torch.serialization._use_new_zipfile_serialization = False
 
13
 
14
- def synthesize(text_prompt, history_prompt=None):
15
- audio_array = generate_audio(text_prompt, history_prompt=history_prompt)
16
- output_path = "output.wav"
17
- write_wav(output_path, SAMPLE_RATE, audio_array)
18
- return output_path
19
 
20
- demo = gr.Interface(
 
 
 
 
 
 
 
 
21
  fn=synthesize,
22
  inputs=[
23
- gr.Textbox(label="Enter Text to Speak"),
24
- gr.Textbox(label="History Prompt Name (optional, e.g. v2/en_speaker_6)")
25
  ],
26
- outputs=gr.Audio(label="Generated Voice", type="filepath"),
27
- title="CloneVoicetts - Real Voice Cloning (Bark)",
28
- description="Upload a demo voice to train as history prompt (optional), then enter any text to generate speech in that style.",
29
- )
30
-
31
- demo.launch()
 
1
  import torch
2
+ import os
3
  import gradio as gr
4
  from bark import generate_audio, SAMPLE_RATE
5
  from scipy.io.wavfile import write as write_wav
6
+ import shutil
 
7
 
8
+ # Make sure history_prompts directory exists
9
+ os.makedirs("history_prompts", exist_ok=True)
 
10
 
11
+ def synthesize(text_prompt, demo_voice=None):
12
+ history_prompt = None
13
 
14
+ # If user uploads a demo voice, save it and use as history prompt
15
+ if demo_voice is not None:
16
+ uploaded_path = "history_prompts/user_prompt.wav"
17
+ shutil.copyfile(demo_voice, uploaded_path)
18
+ history_prompt = uploaded_path
19
 
20
+ try:
21
+ audio_array = generate_audio(text_prompt, history_prompt=history_prompt)
22
+ output_path = "output.wav"
23
+ write_wav(output_path, SAMPLE_RATE, audio_array)
24
+ return output_path
25
+ except Exception as e:
26
+ return f"Error: {e}"
27
+
28
+ gr.Interface(
29
  fn=synthesize,
30
  inputs=[
31
+ gr.Textbox(label="💬 Enter Text to Speak"),
32
+ gr.Audio(source="upload", type="filepath", label="📤 Upload Real Voice (optional)", optional=True)
33
  ],
34
+ outputs=gr.Audio(type="filepath", label="🔊 Cloned Voice Output"),
35
+ title="🧬 CloneVoiceTTS - Real Voice Cloning (Bark)",
36
+ description="Upload a short real voice (.wav), then type any text. Bark will try to clone the uploaded voice tone."
37
+ ).launch()