Spaces:
Runtime error
Runtime error
kevinwang676
commited on
Commit
•
8b0db71
1
Parent(s):
253074a
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,27 @@ os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY')
|
|
8 |
|
9 |
client = OpenAI() # add api_key
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def tts(text, model, voice):
|
12 |
response = client.audio.speech.create(
|
13 |
model=model, #"tts-1","tts-1-hd"
|
@@ -25,18 +46,34 @@ def tts(text, model, voice):
|
|
25 |
return temp_file_path
|
26 |
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
with gr.Row():
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
btn = gr.Button("Text-To-Speech")
|
37 |
-
output_audio = gr.Audio(label="Speech Output")
|
38 |
-
|
39 |
-
text.submit(fn=tts, inputs=[text, model, voice], outputs=output_audio, api_name="tts", concurrency_limit=None)
|
40 |
-
btn.click(fn=tts, inputs=[text, model, voice], outputs=output_audio, api_name="tts", concurrency_limit=None)
|
41 |
|
42 |
-
demo.launch()
|
|
|
8 |
|
9 |
client = OpenAI() # add api_key
|
10 |
|
11 |
+
import torch
|
12 |
+
import torchaudio
|
13 |
+
import gradio as gr
|
14 |
+
from scipy.io import wavfile
|
15 |
+
from scipy.io.wavfile import write
|
16 |
+
|
17 |
+
knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')
|
18 |
+
|
19 |
+
def voice_change(audio_in, audio_ref):
|
20 |
+
samplerate1, data1 = wavfile.read(audio_in)
|
21 |
+
samplerate2, data2 = wavfile.read(audio_ref)
|
22 |
+
write("./audio_in.wav", samplerate1, data1)
|
23 |
+
write("./audio_ref.wav", samplerate2, data2)
|
24 |
+
|
25 |
+
query_seq = knn_vc.get_features("./audio_in.wav")
|
26 |
+
matching_set = knn_vc.get_matching_set(["./audio_ref.wav"])
|
27 |
+
out_wav = knn_vc.match(query_seq, matching_set, topk=4)
|
28 |
+
torchaudio.save('output.wav', out_wav[None], 16000)
|
29 |
+
return 'output.wav'
|
30 |
+
|
31 |
+
|
32 |
def tts(text, model, voice):
|
33 |
response = client.audio.speech.create(
|
34 |
model=model, #"tts-1","tts-1-hd"
|
|
|
46 |
return temp_file_path
|
47 |
|
48 |
|
49 |
+
app = gr.Blocks()
|
50 |
+
|
51 |
+
with app:
|
52 |
+
gr.Markdown("# <center>🥳🎶🎡 - KNN-VC AI变声</center>")
|
53 |
+
gr.Markdown("### <center>🌟 - 3秒实时AI变声,支持中日英在内的所有语言!无需训练、一键变声!🍻 </center>")
|
54 |
+
gr.Markdown("### <center>🌊 - 更多精彩应用,敬请关注[滔滔AI](http://www.talktalkai.com);滔滔AI,为爱滔滔!💕</center>")
|
55 |
+
|
56 |
with gr.Row():
|
57 |
+
with gr.Column():
|
58 |
+
inp_text = gr.Textbox(label="请填写您想生成的文本(中英文皆可)", placeholder="想说却还没说的 还很多 攒着是因为想写成歌")
|
59 |
+
btn_text = gr.Button("一键开启真实拟声吧", variant="primary")
|
60 |
+
|
61 |
+
with gr.Column():
|
62 |
+
inp1 = gr.Audio(type="filepath", label="请上传AI变声的原音频(决定变声后的语音内容)")
|
63 |
+
inp2 = gr.Audio(type="filepath", label="请上传AI变声的参照音频(决定变声后的语音音色)")
|
64 |
+
btn1 = gr.Button("一键开启AI变声吧", variant="primary")
|
65 |
+
with gr.Column():
|
66 |
+
out1 = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
67 |
+
btn_text.click(tts, inp_text, inp1)
|
68 |
+
btn1.click(voice_change, [inp1, inp2], out1)
|
69 |
+
|
70 |
+
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。</center>")
|
71 |
+
gr.HTML('''
|
72 |
+
<div class="footer">
|
73 |
+
<p>🌊🏞️🎶 - 江水东流急,滔滔无尽声。 明·顾璘
|
74 |
+
</p>
|
75 |
+
</div>
|
76 |
+
''')
|
77 |
|
78 |
+
app.launch(show_error=True)
|
|
|
|
|
|
|
|
|
|
|
79 |
|
|