Mira1sen commited on
Commit
9f18b09
1 Parent(s): fbed6c4

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +2 -8
  2. tts_gradio.py +255 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Grd
3
- emoji: 🌖
4
- colorFrom: green
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 4.36.1
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: grd
3
+ app_file: tts_gradio.py
 
 
4
  sdk: gradio
5
  sdk_version: 4.36.1
 
 
6
  ---
 
 
tts_gradio.py ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import warnings
2
+ warnings.filterwarnings("ignore")
3
+
4
+ # 外部库
5
+ import re
6
+ import requests
7
+ import argparse
8
+ import json
9
+ import os
10
+ import re
11
+ import tempfile
12
+ # import librosa
13
+ # import numpy as np
14
+ # import torch
15
+ # from torch import no_grad, LongTensor
16
+ # import commons
17
+ import gradio as gr
18
+ # import gradio.utils as gr_utils
19
+ # import gradio.processing_utils as gr_processing_utils
20
+
21
+ all_example = "my voice is my passport verify me."
22
+
23
+ microsoft_model_list = [
24
+ "en-US-AvaMultilingualNeural"
25
+ ]
26
+
27
+ openai_model_list = [
28
+ "alloy",
29
+ "echo",
30
+ "fable",
31
+ "onyx",
32
+ "nova",
33
+ "shimmer"
34
+ ]
35
+
36
+ eleven_voice_id = [
37
+ "21m00Tcm4TlvDq8ikWAM",
38
+ "29vD33N1CtxCmqQRPOHJ",
39
+ "2EiwWnXFnvU5JabPnv8n",
40
+ "5Q0t7uMcjvnagumLfvZi",
41
+ "AZnzlk1XvdvUeBnXmlld",
42
+ "CYw3kZ02Hs0563khs1Fj",
43
+ "D38z5RcWu1voky8WS1ja",
44
+ "EXAVITQu4vr4xnSDxMaL",
45
+ "ErXwobaYiN019PkySvjV",
46
+ "GBv7mTt0atIp3Br8iCZE",
47
+ "IKne3meq5aSn9XLyUdCD",
48
+ "JBFqnCBsd6RMkjVDRZzb",
49
+ "LcfcDJNUP1GQjkzn1xUU",
50
+ "MF3mGyEYCl7XYWbV9V6O",
51
+ "N2lVS1w4EtoT3dr4eOWO",
52
+ "ODq5zmih8GrVes37Dizd",
53
+ "SOYHLrjzK2X1ezoPC6cr",
54
+ "TX3LPaxmHKxFdv7VOQHJ",
55
+ "ThT5KcBeYPX3keUQqHPh",
56
+ "TxGEqnHWrfWFTfGW9XjX",
57
+ "VR6AewLTigWG4xSOukaG",
58
+ "XB0fDUnXU5powFXDhCwa",
59
+ "Xb7hH8MSUJpSbSDYk0k2",
60
+ "XrExE9yKIg1WjnnlVkGX",
61
+ "ZQe5CZNOzWyzPSCn5a3c",
62
+ "Zlb1dXrM653N07WRdFW3",
63
+ "bVMeCyTHy58xNoL34h3p",
64
+ "flq6f7yk4E4fJM5XTYuZ",
65
+ "g5CIjZEefAph4nQFvHAz",
66
+ "iP95p4xoKVk53GoZ742B",
67
+ "jBpfuIE2acCO8z3wKNLl",
68
+ "jsCqWAovK2LkecY7zXl4",
69
+ "nPczCjzI2devNBz1zQrb",
70
+ "oWAxZDx7w5VEj9dCyTzz",
71
+ "onwK4e9ZLuTAKqWW03F9",
72
+ "pFZP5JQG7iQjIQuC4Bku",
73
+ "pMsXgVXv3BLzUgSXRplE",
74
+ "pNInz6obpgDQGcFmaJgB",
75
+ "piTKgcLEGmPE4e6mEKli",
76
+ "pqHfZKP75CvOlQylNhV4",
77
+ "t0jbNlBVZ17f02VDIeMI",
78
+ "yoZ06aMxZJJ28mfd3POQ",
79
+ "z9fAnlkpzviPz146aGWa",
80
+ "zcAOhNBS3c14rBihAFp1",
81
+ "zrHiDhphv9ZnVXBqCLjz",
82
+ ]
83
+
84
+ eleven_name = [
85
+ "Rachel",
86
+ "Drew",
87
+ "Clyde",
88
+ "Paul",
89
+ "Domi",
90
+ "Dave",
91
+ "Fin",
92
+ "Sarah",
93
+ "Antoni",
94
+ "Thomas",
95
+ "Charlie",
96
+ "George",
97
+ "Emily",
98
+ "Elli",
99
+ "Callum",
100
+ "Patrick",
101
+ "Harry",
102
+ "Liam",
103
+ "Dorothy",
104
+ "Josh",
105
+ "Arnold",
106
+ "Charlotte",
107
+ "Alice",
108
+ "Matilda",
109
+ "James",
110
+ "Joseph",
111
+ "Jeremy",
112
+ "Michael",
113
+ "Ethan",
114
+ "Chris",
115
+ "Gigi",
116
+ "Freya",
117
+ "Brian",
118
+ "Grace",
119
+ "Daniel",
120
+ "Lily",
121
+ "Serena",
122
+ "Adam",
123
+ "Nicole",
124
+ "Bill",
125
+ "Jessie",
126
+ "Sam",
127
+ "Glinda",
128
+ "Giovanni",
129
+ "Mimi",
130
+ ]
131
+ eleven_id_model_name_dict = dict(zip(eleven_name, eleven_voice_id))
132
+
133
+ def openai(text, name):
134
+
135
+ headers = {
136
+ 'Authorization': 'Bearer ' + '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',
137
+ 'Content-Type': 'application/json',
138
+ }
139
+
140
+ json_data = {
141
+ 'model': 'tts-1-hd',
142
+ 'input': f'{text}',
143
+ 'voice': f'{name}',
144
+ }
145
+
146
+ response = requests.post('https://api.openai.com/v1/audio/speech', headers=headers, json=json_data)
147
+
148
+ # Note: json_data will not be serialized by requests
149
+ # exactly as it was in the original request.
150
+ #data = '{\n "model": "tts-1",\n "input": "The quick brown fox jumped over the lazy dog.",\n "voice": "alloy"\n }'
151
+ #response = requests.post('https://api.openai.com/v1/audio/speech', headers=headers, data=data)
152
+
153
+ return "Success", response
154
+
155
+ def elevenlabs(text,name):
156
+ url = f"https://api.elevenlabs.io/v1/text-to-speech/{eleven_id_model_name_dict[name]}"
157
+ CHUNK_SIZE = 1024
158
+ #url = "https://api.elevenlabs.io/v1/text-to-speech/<voice-id>"
159
+
160
+ headers = {
161
+ "Accept": "audio/mpeg",
162
+ "Content-Type": "application/json",
163
+ "xi-api-key": "a3391f0e3ff8472b61978dbb70ccc6fe"
164
+ }
165
+
166
+ data = {
167
+ "text": f"{text}",
168
+ "model_id": "eleven_monolingual_v1",
169
+ "voice_settings": {
170
+ "stability": 0.5,
171
+ "similarity_boost": 0.5
172
+ }
173
+ }
174
+
175
+ response = requests.post(url, json=data, headers=headers)
176
+ # with open('output.mp3', 'wb') as f:
177
+ # for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
178
+ # if chunk:
179
+ # f.write(chunk)
180
+ return "Success", response
181
+
182
+ def microsoft(text, name, style="Neural"):
183
+ """
184
+ :param text:
185
+ :param name:
186
+ :param style:
187
+ :return:
188
+ """
189
+ headers = {
190
+ 'Ocp-Apim-Subscription-Key': '1f1ef0ce53b84261be94fab81df7e628',
191
+ 'Content-Type': 'application/ssml+xml',
192
+ 'X-Microsoft-OutputFormat': 'audio-16khz-128kbitrate-mono-mp3',
193
+ 'User-Agent': 'curl',
194
+ }
195
+
196
+ data = ("<speak version='1.0' xml:lang='en-US'>"
197
+ f"<voice xml:lang='en-US' name='{name}'>" # xml:gender='Female'
198
+ f"{text}"
199
+ "</voice>"
200
+ "</speak>")
201
+
202
+ response = requests.post(
203
+ 'https://japaneast.tts.speech.microsoft.com/cognitiveservices/v1',
204
+ headers=headers,
205
+ data=data,
206
+ )
207
+ return "Success", "sss"
208
+
209
+ if __name__ == '__main__':
210
+ parser = argparse.ArgumentParser()
211
+ parser.add_argument('--device', type=str, default='cuda')
212
+ parser.add_argument("--share", action="store_true", default=True, help="share gradio app")
213
+ parser.add_argument("--port", type=int, default=8081, help="port")
214
+ parser.add_argument('--model_info_path', type=str, default='/gluster/speech_data/info.json')
215
+ args = parser.parse_args()
216
+
217
+ app = gr.Blocks()
218
+ with app:
219
+ gr.Markdown("## Japanese TTS Demo")
220
+ with gr.Tabs():
221
+
222
+ with gr.TabItem("11Labs"):
223
+ tts_input1 = gr.TextArea(label="Text", value=all_example)
224
+ tts_input2 = gr.Dropdown(eleven_name, label="name")
225
+ tts_submit = gr.Button("Generate", variant="primary")
226
+ tts_output1 = gr.Textbox(label="Output Message")
227
+ tts_output2 = gr.Audio(label="Output Audio")
228
+ tts_submit.click(elevenlabs, [tts_input1, tts_input2],
229
+ [tts_output1, tts_output2])
230
+
231
+ with gr.TabItem("微软"):
232
+ tts_input1 = gr.TextArea(label="Text", value=all_example)
233
+ tts_input2 = gr.Dropdown(microsoft_model_list, label="name")
234
+ tts_submit = gr.Button("Generate", variant="primary")
235
+ tts_output1 = gr.Textbox(label="Output Message")
236
+ tts_output2 = gr.Audio(label="Output Audio")
237
+ tts_submit.click(microsoft, [tts_input1, tts_input2],
238
+ [tts_output1, tts_output2])
239
+
240
+ with gr.TabItem("openai"):
241
+ tts_input1 = gr.TextArea(label="Text", value=all_example)
242
+ tts_input2 = gr.Dropdown(openai_model_list, label="name")
243
+ tts_submit = gr.Button("Generate", variant="primary")
244
+ tts_output1 = gr.Textbox(label="Output Message")
245
+ tts_output2 = gr.Audio(label="Output Audio")
246
+ tts_submit.click(openai, [tts_input1, tts_input2],
247
+ [tts_output1, tts_output2])
248
+
249
+ app.queue(max_size=10)
250
+ app.launch(share=True)
251
+ # _, audio = openai(all_example,'alloy')
252
+ # print(audio)
253
+ # with open("test99.mp3", "wb") as f:
254
+ # f.write(audio.content)
255
+