Spaces:
Paused
Paused
zxsipola123456
commited on
Commit
•
6a0a2ac
1
Parent(s):
6c18768
Update app.py
Browse files
app.py
CHANGED
@@ -28,17 +28,39 @@ async def text_to_speech_edge(text, language_code):
|
|
28 |
return "语音合成完成:{}".format(text), tmp_path
|
29 |
|
30 |
# 声音更改函数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def voice_change(audio_in, audio_ref):
|
32 |
samplerate1, data1 = wavfile.read(audio_in)
|
33 |
samplerate2, data2 = wavfile.read(audio_ref)
|
34 |
-
write("./audio_in.wav", samplerate1, data1)
|
35 |
-
write("./audio_ref.wav", samplerate2, data2)
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
out_wav = knn_vc.match(query_seq, matching_set, topk=4)
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# 文字转语音(OpenAI)
|
44 |
def tts(text, model, voice, api_key):
|
@@ -66,11 +88,11 @@ def tts(text, model, voice, api_key):
|
|
66 |
app = gr.Blocks()
|
67 |
|
68 |
with app:
|
69 |
-
gr.Markdown("# <center
|
70 |
-
gr.Markdown("### <center
|
71 |
-
with gr.Tab("
|
72 |
with gr.Row(variant='panel'):
|
73 |
-
api_key = gr.Textbox(type='password', label='
|
74 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='请选择模型(tts-1推理更快,tts-1-hd音质更好)', value='tts-1')
|
75 |
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='请选择一个说话人', value='alloy')
|
76 |
with gr.Row():
|
@@ -102,7 +124,7 @@ with app:
|
|
102 |
btn_edge.click(lambda text, lang: anyio.run(text_to_speech_edge, text, lang), [input_text, language], [output_text, output_audio])
|
103 |
btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
|
104 |
|
105 |
-
gr.Markdown("### <center
|
106 |
gr.HTML('''
|
107 |
<div class="footer">
|
108 |
<p>Power by sipola </p>
|
|
|
28 |
return "语音合成完成:{}".format(text), tmp_path
|
29 |
|
30 |
# 声音更改函数
|
31 |
+
#def voice_change(audio_in, audio_ref):
|
32 |
+
#samplerate1, data1 = wavfile.read(audio_in)
|
33 |
+
#samplerate2, data2 = wavfile.read(audio_ref)
|
34 |
+
#write("./audio_in.wav", samplerate1, data1)
|
35 |
+
#write("./audio_ref.wav", samplerate2, data2)
|
36 |
+
|
37 |
+
#query_seq = knn_vc.get_features("./audio_in.wav")
|
38 |
+
#matching_set = knn_vc.get_matching_set(["./audio_ref.wav"])
|
39 |
+
#out_wav = knn_vc.match(query_seq, matching_set, topk=4)
|
40 |
+
#torchaudio.save('output.wav', out_wav[None], 16000)
|
41 |
+
#return 'output.wav'
|
42 |
def voice_change(audio_in, audio_ref):
|
43 |
samplerate1, data1 = wavfile.read(audio_in)
|
44 |
samplerate2, data2 = wavfile.read(audio_ref)
|
|
|
|
|
45 |
|
46 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_in, \
|
47 |
+
tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_audio_ref:
|
48 |
+
audio_in_path = tmp_audio_in.name
|
49 |
+
audio_ref_path = tmp_audio_ref.name
|
50 |
+
write(audio_in_path, samplerate1, data1)
|
51 |
+
write(audio_ref_path, samplerate2, data2)
|
52 |
+
|
53 |
+
query_seq = knn_vc.get_features(audio_in_path)
|
54 |
+
matching_set = knn_vc.get_matching_set([audio_ref_path])
|
55 |
out_wav = knn_vc.match(query_seq, matching_set, topk=4)
|
56 |
+
|
57 |
+
# 确保 out_wav 是二维张量
|
58 |
+
if len(out_wav.shape) == 1:
|
59 |
+
out_wav = out_wav.unsqueeze(0)
|
60 |
+
|
61 |
+
output_path = 'output.wav'
|
62 |
+
torchaudio.save(output_path, out_wav, 16000)
|
63 |
+
return output_path
|
64 |
|
65 |
# 文字转语音(OpenAI)
|
66 |
def tts(text, model, voice, api_key):
|
|
|
88 |
app = gr.Blocks()
|
89 |
|
90 |
with app:
|
91 |
+
gr.Markdown("# <center>OpenAI TTS + 3秒实时AI变声+需要使用中转key</center>")
|
92 |
+
gr.Markdown("### <center>中转key购买地址https://buy.sipola.cn</center>")
|
93 |
+
with gr.Tab("TTS"):
|
94 |
with gr.Row(variant='panel'):
|
95 |
+
api_key = gr.Textbox(type='password', label='API Key', placeholder='请在此填写您的API Key')
|
96 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='请选择模型(tts-1推理更快,tts-1-hd音质更好)', value='tts-1')
|
97 |
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='请选择一个说话人', value='alloy')
|
98 |
with gr.Row():
|
|
|
124 |
btn_edge.click(lambda text, lang: anyio.run(text_to_speech_edge, text, lang), [input_text, language], [output_text, output_audio])
|
125 |
btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
|
126 |
|
127 |
+
gr.Markdown("### <center>注意获取中转API Key [here](https://buy.sipola.cn).</center>")
|
128 |
gr.HTML('''
|
129 |
<div class="footer">
|
130 |
<p>Power by sipola </p>
|