WeVi commited on
Commit
dfd2b84
·
verified ·
1 Parent(s): 8ad01f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -24
app.py CHANGED
@@ -1,26 +1,31 @@
1
- Bark-based Real Voice Cloning Space - Fixed for PyTorch 2.6+ on Hugging Face
2
-
3
- import os import torch import gradio as gr import numpy as np import numpy.core
4
-
5
- 🛠 Fix for PyTorch 2.6+ pickle loading
6
-
 
 
 
7
  import torch.serialization
8
 
9
- torch.serialization._legacy_pickle_load = True if not hasattr(torch.serialization, 'pickle'): torch.serialization.pickle = import('pickle') torch.serialization.pickle.loads = torch.serialization.pickle.loads torch.serialization.pickle.load = torch.serialization.pickle.load torch.serialization.legacy_load = torch.load torch.serialization._load = lambda *args, **kwargs: torch.serialization.legacy_load(*args, **kwargs) torch.serialization.add_safe_globals({ 'numpy.core.multiarray.scalar': np.core.multiarray.scalar })
10
-
11
- 🧠 Bark Imports
12
-
13
- from bark import generate_audio, preload_models from bark.api import SAMPLE_RATE
14
-
15
- Load models once
16
-
17
- preload_models()
18
-
19
- def bark_speak(text): audio_array = generate_audio(text) out_path = "bark_voice.wav" from scipy.io.wavfile import write as write_wav write_wav(out_path, SAMPLE_RATE, audio_array) return out_path
20
-
21
- 🎛️ Gradio Interface
22
-
23
- interface = gr.Interface( fn=bark_speak, inputs=gr.Textbox(label="🎙️ Enter your text"), outputs=gr.Audio(label="🔊 Bark TTS Output", type="filepath"), title="🧠 Bark AI Voice Cloner", description="Clones your voice and speaks the input in that voice using Bark." )
24
-
25
- interface.launch()
26
-
 
 
 
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()