Spaces:
Runtime error
Runtime error
Duplicate from Kevin676/ChatGPT-with-Voice-Cloning-for-All
Browse filesCo-authored-by: Kevin Wang <Kevin676@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +14 -0
- app.py +144 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: ChatGPT With Voice Cloning For All
|
3 |
+
emoji: 🌖
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.25.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: Kevin676/ChatGPT-with-Voice-Cloning-for-All
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from TTS.api import TTS
|
4 |
+
|
5 |
+
tts1 = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False, gpu=False)
|
6 |
+
|
7 |
+
tts2 = TTS("tts_models/zh-CN/baker/tacotron2-DDC-GST")
|
8 |
+
|
9 |
+
import os
|
10 |
+
|
11 |
+
import openai
|
12 |
+
|
13 |
+
import torch
|
14 |
+
import torchaudio
|
15 |
+
from speechbrain.pretrained import SpectralMaskEnhancement
|
16 |
+
|
17 |
+
enhance_model = SpectralMaskEnhancement.from_hparams(
|
18 |
+
source="speechbrain/metricgan-plus-voicebank",
|
19 |
+
savedir="pretrained_models/metricgan-plus-voicebank",
|
20 |
+
#run_opts={"device":"cuda"},
|
21 |
+
)
|
22 |
+
|
23 |
+
mes = [
|
24 |
+
{"role": "system", "content": "You are my personal assistant. Try to be helpful."}
|
25 |
+
]
|
26 |
+
|
27 |
+
def chatgpt(apikey, result):
|
28 |
+
|
29 |
+
openai.api_key = apikey
|
30 |
+
|
31 |
+
messages = mes
|
32 |
+
|
33 |
+
# chatgpt
|
34 |
+
content = result
|
35 |
+
messages.append({"role": "user", "content": content})
|
36 |
+
|
37 |
+
completion = openai.ChatCompletion.create(
|
38 |
+
model = "gpt-3.5-turbo",
|
39 |
+
messages = messages
|
40 |
+
)
|
41 |
+
|
42 |
+
chat_response = completion.choices[0].message.content
|
43 |
+
|
44 |
+
messages.append({"role": "assistant", "content": chat_response})
|
45 |
+
|
46 |
+
return chat_response
|
47 |
+
|
48 |
+
def english(text_en, upload, VoiceMicrophone):
|
49 |
+
if upload is not None:
|
50 |
+
tts1.tts_to_file(text_en, speaker_wav = upload, language="en", file_path="output.wav")
|
51 |
+
|
52 |
+
else:
|
53 |
+
tts1.tts_to_file(text_en, speaker_wav = VoiceMicrophone, language="en", file_path="output.wav")
|
54 |
+
|
55 |
+
noisy = enhance_model.load_audio(
|
56 |
+
"output.wav"
|
57 |
+
).unsqueeze(0)
|
58 |
+
|
59 |
+
enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
|
60 |
+
torchaudio.save("enhanced.wav", enhanced.cpu(), 16000)
|
61 |
+
|
62 |
+
return "enhanced.wav"
|
63 |
+
|
64 |
+
def chinese(text_cn, upload1, VoiceMicrophone1):
|
65 |
+
if upload1 is not None:
|
66 |
+
tts2.tts_with_vc_to_file(
|
67 |
+
text_cn + "。",
|
68 |
+
speaker_wav=upload1,
|
69 |
+
file_path="ouptut1.wav"
|
70 |
+
)
|
71 |
+
|
72 |
+
else:
|
73 |
+
tts2.tts_with_vc_to_file(
|
74 |
+
text_cn + "。",
|
75 |
+
speaker_wav=VoiceMicrophone1,
|
76 |
+
file_path="ouptut1.wav"
|
77 |
+
)
|
78 |
+
|
79 |
+
return "ouptut1.wav"
|
80 |
+
|
81 |
+
block = gr.Blocks()
|
82 |
+
|
83 |
+
with block:
|
84 |
+
with gr.Group():
|
85 |
+
gr.Markdown(
|
86 |
+
""" # <center>🥳💬💕 - TalktoAI,随时随地,谈天说地!</center>
|
87 |
+
|
88 |
+
## <center>🤖 - 让有人文关怀的AI造福每一个人!AI向善,文明璀璨!TalktoAI - Enable the future!</center>
|
89 |
+
|
90 |
+
"""
|
91 |
+
)
|
92 |
+
|
93 |
+
with gr.Box():
|
94 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
95 |
+
|
96 |
+
inp1 = gr.Textbox(label='请输入您的Openai-API-Key', type = "password")
|
97 |
+
inp2 = gr.Textbox(label='说点什么吧(中英皆可)')
|
98 |
+
|
99 |
+
btn = gr.Button("开始对话吧")
|
100 |
+
|
101 |
+
texts1 = gr.Textbox(lines=3, label="ChatGPT的回答")
|
102 |
+
|
103 |
+
btn.click(chatgpt, [inp1, inp2], [texts1])
|
104 |
+
|
105 |
+
with gr.Box():
|
106 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
107 |
+
inp3 = texts1
|
108 |
+
inp4 = gr.Audio(source="upload", label = "请上传您喜欢的声音(wav/mp3文件)", type="filepath")
|
109 |
+
inp5 = gr.Audio(source="microphone", type="filepath", label = '请用麦克风上传您喜欢的声音,与文件上传二选一即可')
|
110 |
+
|
111 |
+
btn1 = gr.Button("用喜欢的声音听一听吧(中文)")
|
112 |
+
|
113 |
+
out1 = gr.Audio(label="合成的专属声音(中文)")
|
114 |
+
|
115 |
+
btn1.click(chinese, [inp3, inp4, inp5], [out1])
|
116 |
+
|
117 |
+
with gr.Box():
|
118 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
119 |
+
|
120 |
+
btn2 = gr.Button("用喜欢的声音听一听吧(英文)")
|
121 |
+
|
122 |
+
out2 = gr.Audio(label="合成的专属声音(英文)")
|
123 |
+
|
124 |
+
btn2.click(english, [inp3, inp4, inp5], [out2])
|
125 |
+
|
126 |
+
gr.Markdown(
|
127 |
+
""" ### <center>注意❗:请不要输入或生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及娱乐使用。用户输入或生成的内容与程序开发者无关,请自觉合法合规使用,违反者一切后果自负。</center>
|
128 |
+
|
129 |
+
### <center>Powered by [ChatGPT](https://chat.openai.com/). Please follow me on [Bilibili](https://space.bilibili.com/501495851?spm_id_from=333.1007.0.0).</center>
|
130 |
+
|
131 |
+
"""
|
132 |
+
)
|
133 |
+
|
134 |
+
gr.HTML('''
|
135 |
+
<div class="footer">
|
136 |
+
<p>🎶🖼️🎡 - It’s the intersection of technology and liberal arts that makes our hearts sing. - Steve Jobs
|
137 |
+
</p>
|
138 |
+
<p>注:中文声音克隆实际上是由声音转换(Voice Conversion)实现,所以输出结果可能更像是一种新的声音,效果不一定很理想,希望大家理解(之后也会不断迭代的)!为了更好的效果,使用中文声音克隆时请尽量上传女声。
|
139 |
+
</p>
|
140 |
+
</div>
|
141 |
+
''')
|
142 |
+
|
143 |
+
block.launch(show_error=True)
|
144 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
TTS
|
3 |
+
torchaudio
|
4 |
+
speechbrain
|
5 |
+
gradio==3.25.0
|