apple1413
commited on
Commit
·
ea509bc
1
Parent(s):
f626328
Initial model upload
Browse files- LICENSE +7 -0
- README.md +15 -0
- app.py +315 -0
- cached_outputs/0.wav +0 -0
- cached_outputs/1.wav +0 -0
- cached_outputs/2.wav +0 -0
- cached_outputs/3.wav +0 -0
- cached_outputs/4.wav +0 -0
- examples/speaker0.mp3 +0 -0
- examples/speaker1.mp3 +0 -0
- examples/speaker2.mp3 +0 -0
- examples/speaker3.mp3 +0 -0
- hash_code_for_cached_output.py +55 -0
- requirements.txt +1 -0
LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2024 MyShell.ai
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 4 |
+
|
| 5 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 6 |
+
|
| 7 |
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: OpenVoiceV2
|
| 3 |
+
emoji: 🤗
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.48.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
models:
|
| 12 |
+
- myshell-ai/OpenVoice-v2
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
import langid
|
| 5 |
+
import base64
|
| 6 |
+
import json
|
| 7 |
+
import time
|
| 8 |
+
import re
|
| 9 |
+
import hashlib
|
| 10 |
+
import hash_code_for_cached_output
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
API_URL = os.environ.get("API_URL")
|
| 14 |
+
supported_languages = ['zh', 'en', 'ja', 'ko', 'es', 'fr']
|
| 15 |
+
supported_styles = {
|
| 16 |
+
'zh': "zh_default",
|
| 17 |
+
'en': [
|
| 18 |
+
"en_default",
|
| 19 |
+
"en_us",
|
| 20 |
+
"en_br",
|
| 21 |
+
"en_au",
|
| 22 |
+
"en_in"
|
| 23 |
+
],
|
| 24 |
+
"es": "es_default",
|
| 25 |
+
"fr": "fr_default",
|
| 26 |
+
"ja": "jp_default",
|
| 27 |
+
"ko": "kr_default"
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
output_dir = 'outputs'
|
| 31 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 32 |
+
|
| 33 |
+
def audio_to_base64(audio_file):
|
| 34 |
+
with open(audio_file, "rb") as audio_file:
|
| 35 |
+
audio_data = audio_file.read()
|
| 36 |
+
base64_data = base64.b64encode(audio_data).decode("utf-8")
|
| 37 |
+
return base64_data
|
| 38 |
+
|
| 39 |
+
def count_chars_words(sentence):
|
| 40 |
+
segments = re.findall(r'[\u4e00-\u9fa5]+|\w+', sentence)
|
| 41 |
+
|
| 42 |
+
char_count = 0
|
| 43 |
+
word_count = 0
|
| 44 |
+
for segment in segments:
|
| 45 |
+
if re.match(r'[\u4e00-\u9fa5]+', segment):
|
| 46 |
+
char_count += len(segment)
|
| 47 |
+
else:
|
| 48 |
+
word_count += len(segment.split())
|
| 49 |
+
return char_count + word_count
|
| 50 |
+
|
| 51 |
+
def predict(prompt, style, audio_file_pth, speed, agree):
|
| 52 |
+
# initialize a empty info
|
| 53 |
+
text_hint = ''
|
| 54 |
+
# agree with the terms
|
| 55 |
+
if agree == False:
|
| 56 |
+
text_hint += '[ERROR] Please accept the Terms & Condition!\n'
|
| 57 |
+
gr.Warning("Please accept the Terms & Condition!")
|
| 58 |
+
return (
|
| 59 |
+
text_hint,
|
| 60 |
+
None,
|
| 61 |
+
None,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# Before we get into inference, we will detect if it is from example table or default value
|
| 65 |
+
# If so, we use a cached Audio. Noted that, it is just for demo efficiency.
|
| 66 |
+
# hash code were generated by `hash_code_for_cached_output.py`
|
| 67 |
+
# this hash get from gradio console
|
| 68 |
+
cached_outputs = {
|
| 69 |
+
"af39e1f1ff_60565a5c20_en_us" : "cached_outputs/0.wav",
|
| 70 |
+
"af39e1f1ff_420ab8211d_en_us" : "cached_outputs/1.wav",
|
| 71 |
+
"ced034cc22_0f96bf44f5_es_default" : "cached_outputs/2.wav",
|
| 72 |
+
"d3172b178d_3fef5adc6f_zh_default" : "cached_outputs/3.wav",
|
| 73 |
+
"cda6998e1a_9897b60a4e_jp_default" : "cached_outputs/4.wav"
|
| 74 |
+
}
|
| 75 |
+
unique_code = hash_code_for_cached_output.get_unique_code(audio_file_pth, prompt, style)
|
| 76 |
+
print("audio_file_pth is", audio_file_pth)
|
| 77 |
+
print("unique_code is", unique_code)
|
| 78 |
+
if unique_code in list(cached_outputs.keys()):
|
| 79 |
+
return (
|
| 80 |
+
'We get the cached output for you, since you are trying to generate an example cloning.',
|
| 81 |
+
cached_outputs[unique_code],
|
| 82 |
+
audio_file_pth,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
# first detect the input language
|
| 86 |
+
language_predicted = langid.classify(prompt)[0].strip()
|
| 87 |
+
print(f"Detected language:{language_predicted}")
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
if language_predicted not in supported_languages:
|
| 91 |
+
text_hint += f"[ERROR] The detected language {language_predicted} for your input text is not in our Supported Languages: {supported_languages}\n"
|
| 92 |
+
gr.Warning(
|
| 93 |
+
f"The detected language {language_predicted} for your input text is not in our Supported Languages: {supported_languages}"
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
return (
|
| 97 |
+
text_hint,
|
| 98 |
+
None,
|
| 99 |
+
None,
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
# check the style
|
| 103 |
+
if style not in supported_styles[language_predicted]:
|
| 104 |
+
text_hint += f"[Warming] The style {style} is not supported for detected language {language_predicted}. For language {language_predicted}, we support styles: {supported_styles[language_predicted]}. Using the wrong style may result in unexpected behavior.\n"
|
| 105 |
+
gr.Warning(f"[Warming] The style {style} is not supported for detected language {language_predicted}. For language {language_predicted}, we support styles: {supported_styles[language_predicted]}. Using the wrong style may result in unexpected behavior.")
|
| 106 |
+
|
| 107 |
+
prompt_length = count_chars_words(prompt)
|
| 108 |
+
|
| 109 |
+
speaker_wav = audio_file_pth
|
| 110 |
+
|
| 111 |
+
if prompt_length < 2:
|
| 112 |
+
text_hint += f"[ERROR] Please give a longer prompt text \n"
|
| 113 |
+
gr.Warning("Please give a longer prompt text")
|
| 114 |
+
return (
|
| 115 |
+
text_hint,
|
| 116 |
+
None,
|
| 117 |
+
None,
|
| 118 |
+
)
|
| 119 |
+
if prompt_length > 50:
|
| 120 |
+
text_hint += f"[ERROR] Text length limited to 50 words for this demo, please try shorter text. You can clone our open-source repo or try it on our website https://app.myshell.ai/robot-workshop/widget/174760057433406749 \n"
|
| 121 |
+
gr.Warning(
|
| 122 |
+
"Text length limited to 50 words for this demo, please try shorter text. You can clone our open-source repo or try it on our website https://app.myshell.ai/robot-workshop/widget/174760057433406749"
|
| 123 |
+
)
|
| 124 |
+
return (
|
| 125 |
+
text_hint,
|
| 126 |
+
None,
|
| 127 |
+
None,
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
save_path = f'{output_dir}/output.wav'
|
| 131 |
+
speaker_audio_base64 = audio_to_base64(speaker_wav)
|
| 132 |
+
if style == 'en_us': # we update us accent
|
| 133 |
+
style = 'en_newest'
|
| 134 |
+
data = {
|
| 135 |
+
"text": prompt,
|
| 136 |
+
"reference_speaker": speaker_audio_base64,
|
| 137 |
+
"language": style,
|
| 138 |
+
"speed": speed
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
start = time.time()
|
| 142 |
+
# Send the data as a POST request
|
| 143 |
+
response = requests.post(API_URL, json=data, timeout=60)
|
| 144 |
+
print(f'Get response successfully within {time.time() - start}')
|
| 145 |
+
|
| 146 |
+
# Check the response
|
| 147 |
+
if response.status_code == 200:
|
| 148 |
+
try:
|
| 149 |
+
json_data = json.loads(response.content)
|
| 150 |
+
text_hint += f"[ERROR] {json_data['error']} \n"
|
| 151 |
+
gr.Warning(
|
| 152 |
+
f"[ERROR] {json_data['error']} \n"
|
| 153 |
+
)
|
| 154 |
+
return (
|
| 155 |
+
text_hint,
|
| 156 |
+
None,
|
| 157 |
+
None,
|
| 158 |
+
)
|
| 159 |
+
except:
|
| 160 |
+
with open(save_path, 'wb') as f:
|
| 161 |
+
f.write(response.content)
|
| 162 |
+
else:
|
| 163 |
+
text_hint += f"[HTTP ERROR] {response.status_code} - {response.text} \n"
|
| 164 |
+
gr.Warning(
|
| 165 |
+
f"[HTTP ERROR] {response.status_code} - {response.text} \n"
|
| 166 |
+
)
|
| 167 |
+
return (
|
| 168 |
+
text_hint,
|
| 169 |
+
None,
|
| 170 |
+
None,
|
| 171 |
+
)
|
| 172 |
+
text_hint += f'''Get response successfully \n'''
|
| 173 |
+
return (
|
| 174 |
+
text_hint,
|
| 175 |
+
save_path,
|
| 176 |
+
speaker_wav,
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
title = "MyShell OpenVoice V2"
|
| 181 |
+
|
| 182 |
+
description = """
|
| 183 |
+
In December 2023, we released [OpenVoice V1](https://huggingface.co/spaces/myshell-ai/OpenVoice), an instant voice cloning approach that replicates a speaker's voice and generates speech in multiple languages using only a short audio clip. OpenVoice V1 enables granular control over voice styles, replicates the tone color of the reference speaker and achieves zero-shot cross-lingual voice cloning.
|
| 184 |
+
"""
|
| 185 |
+
|
| 186 |
+
description_v2 = """
|
| 187 |
+
In April 2024, we released **OpenVoice V2**, which includes all features in V1 and has:
|
| 188 |
+
- **Better Audio Quality**. OpenVoice V2 adopts a different training strategy that delivers better audio quality.
|
| 189 |
+
- **Native Multi-lingual Support**. English, Spanish, French, Chinese, Japanese and Korean are natively supported in OpenVoice V2.
|
| 190 |
+
- **Free Commercial Use**. Starting from April 2024, both V2 and V1 are released under MIT License. Free for commercial use.
|
| 191 |
+
"""
|
| 192 |
+
|
| 193 |
+
markdown_table = """
|
| 194 |
+
<div align="center" style="margin-bottom: 10px;">
|
| 195 |
+
|
| 196 |
+
| | | |
|
| 197 |
+
| :-----------: | :-----------: | :-----------: |
|
| 198 |
+
| **OpenSource Repo** | **Project Page** | **Join the Community** |
|
| 199 |
+
| <div style='text-align: center;'><a style="display:inline-block,align:center" href='https://github.com/myshell-ai/OpenVoice'><img src='https://img.shields.io/github/stars/myshell-ai/OpenVoice?style=social' /></a></div> | [OpenVoice](https://research.myshell.ai/open-voice) | [](https://discord.gg/myshell) |
|
| 200 |
+
|
| 201 |
+
</div>
|
| 202 |
+
"""
|
| 203 |
+
|
| 204 |
+
markdown_table_v2 = """
|
| 205 |
+
<div align="center" style="margin-bottom: 2px;">
|
| 206 |
+
|
| 207 |
+
| | | | |
|
| 208 |
+
| :-----------: | :-----------: | :-----------: | :-----------: |
|
| 209 |
+
| **Github Repo** | <div style='text-align: center;'><a style="display:inline-block,align:center" href='https://github.com/myshell-ai/OpenVoice'><img src='https://img.shields.io/github/stars/myshell-ai/OpenVoice?style=social' /></a></div> | **Project Page** | [OpenVoice](https://research.myshell.ai/open-voice) |
|
| 210 |
+
|
| 211 |
+
| | |
|
| 212 |
+
| :-----------: | :-----------: |
|
| 213 |
+
**Join the Community** | [](https://discord.gg/myshell) |
|
| 214 |
+
|
| 215 |
+
</div>
|
| 216 |
+
"""
|
| 217 |
+
content = """
|
| 218 |
+
<div>
|
| 219 |
+
<strong>If the generated voice does not sound like the reference voice, please refer to <a href='https://github.com/myshell-ai/OpenVoice/blob/main/docs/QA.md'>this QnA</a>.</strong> <strong>If you want to deploy the model by yourself and perform inference, please refer to <a href='https://github.com/myshell-ai/OpenVoice/blob/main/demo_part3.ipynb'>this jupyter notebook</a>.</strong>
|
| 220 |
+
</div>
|
| 221 |
+
"""
|
| 222 |
+
wrapped_markdown_content = f"<div style='border: 1px solid #000; padding: 10px;'>{content}</div>"
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
examples = [
|
| 226 |
+
[
|
| 227 |
+
"Did you ever hear a folk tale about a giant turtle?",
|
| 228 |
+
'en_us',
|
| 229 |
+
"examples/speaker0.mp3",
|
| 230 |
+
True,
|
| 231 |
+
],[
|
| 232 |
+
"El resplandor del sol acaricia las olas, pintando el cielo con una paleta deslumbrante.",
|
| 233 |
+
'es_default',
|
| 234 |
+
"examples/speaker1.mp3",
|
| 235 |
+
True,
|
| 236 |
+
],[
|
| 237 |
+
"我最近在学习machine learning,希望能够在未来的artificial intelligence领域有所建树。",
|
| 238 |
+
'zh_default',
|
| 239 |
+
"examples/speaker2.mp3",
|
| 240 |
+
True,
|
| 241 |
+
],[
|
| 242 |
+
"彼は毎朝ジョギングをして体を健康に保っています。",
|
| 243 |
+
'jp_default',
|
| 244 |
+
"examples/speaker3.mp3",
|
| 245 |
+
True,
|
| 246 |
+
],
|
| 247 |
+
]
|
| 248 |
+
|
| 249 |
+
with gr.Blocks(analytics_enabled=False) as demo:
|
| 250 |
+
|
| 251 |
+
with gr.Row():
|
| 252 |
+
with gr.Column():
|
| 253 |
+
with gr.Row():
|
| 254 |
+
gr.Markdown(
|
| 255 |
+
"""
|
| 256 |
+
## <img src="https://huggingface.co/spaces/myshell-ai/OpenVoice/raw/main/logo.jpg" height="40"/>
|
| 257 |
+
"""
|
| 258 |
+
)
|
| 259 |
+
with gr.Row():
|
| 260 |
+
gr.Markdown(markdown_table_v2)
|
| 261 |
+
with gr.Row():
|
| 262 |
+
gr.Markdown(description)
|
| 263 |
+
with gr.Column():
|
| 264 |
+
gr.Video('./openvoicev2.mp4', autoplay=True)
|
| 265 |
+
|
| 266 |
+
with gr.Row():
|
| 267 |
+
gr.Markdown(description_v2)
|
| 268 |
+
|
| 269 |
+
with gr.Row():
|
| 270 |
+
gr.HTML(wrapped_markdown_content)
|
| 271 |
+
|
| 272 |
+
with gr.Row():
|
| 273 |
+
with gr.Column():
|
| 274 |
+
input_text_gr = gr.Textbox(
|
| 275 |
+
label="Text Prompt",
|
| 276 |
+
info="One or two sentences at a time is better. Up to 200 text characters.",
|
| 277 |
+
value="The bustling city square bustled with street performers, tourists, and local vendors.",
|
| 278 |
+
)
|
| 279 |
+
style_gr = gr.Dropdown(
|
| 280 |
+
label="Style",
|
| 281 |
+
info="Select a style of output audio for the synthesised speech. (Chinese only support 'default' now)",
|
| 282 |
+
choices=["en_default", "en_us", "en_br", "en_au", "en_in", "es_default", "fr_default", "jp_default", "zh_default", "kr_default",],
|
| 283 |
+
max_choices=1,
|
| 284 |
+
value="en_us",
|
| 285 |
+
)
|
| 286 |
+
ref_gr = gr.Audio(
|
| 287 |
+
label="Reference Audio",
|
| 288 |
+
info="Click on the ✎ button to upload your own target speaker audio",
|
| 289 |
+
type="filepath",
|
| 290 |
+
value="examples/speaker0.mp3",
|
| 291 |
+
)
|
| 292 |
+
tos_gr = gr.Checkbox(
|
| 293 |
+
label="Agree",
|
| 294 |
+
value=False,
|
| 295 |
+
info="I agree to the terms of the MIT license-: https://github.com/myshell-ai/OpenVoice/blob/main/LICENSE",
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
tts_button = gr.Button("Send", elem_id="send-btn", visible=True)
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
with gr.Column():
|
| 302 |
+
out_text_gr = gr.Text(label="Info")
|
| 303 |
+
audio_gr = gr.Audio(label="Synthesised Audio", autoplay=True)
|
| 304 |
+
ref_audio_gr = gr.Audio(label="Reference Audio Used")
|
| 305 |
+
|
| 306 |
+
gr.Examples(examples,
|
| 307 |
+
label="Examples",
|
| 308 |
+
inputs=[input_text_gr, style_gr, ref_gr, tos_gr],
|
| 309 |
+
outputs=[out_text_gr, audio_gr, ref_audio_gr],
|
| 310 |
+
fn=predict,
|
| 311 |
+
cache_examples=False,)
|
| 312 |
+
tts_button.click(predict, [input_text_gr, style_gr, ref_gr, tos_gr], outputs=[out_text_gr, audio_gr, ref_audio_gr])
|
| 313 |
+
|
| 314 |
+
demo.queue(concurrency_count=6)
|
| 315 |
+
demo.launch(debug=True, show_api=True)
|
cached_outputs/0.wav
ADDED
|
Binary file (36.9 kB). View file
|
|
|
cached_outputs/1.wav
ADDED
|
Binary file (20.4 kB). View file
|
|
|
cached_outputs/2.wav
ADDED
|
Binary file (37.5 kB). View file
|
|
|
cached_outputs/3.wav
ADDED
|
Binary file (41.3 kB). View file
|
|
|
cached_outputs/4.wav
ADDED
|
Binary file (40.1 kB). View file
|
|
|
examples/speaker0.mp3
ADDED
|
Binary file (961 kB). View file
|
|
|
examples/speaker1.mp3
ADDED
|
Binary file (309 kB). View file
|
|
|
examples/speaker2.mp3
ADDED
|
Binary file (117 kB). View file
|
|
|
examples/speaker3.mp3
ADDED
|
Binary file (472 kB). View file
|
|
|
hash_code_for_cached_output.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
|
| 3 |
+
def audio_hash(audio_path):
|
| 4 |
+
with open(audio_path, "rb") as f:
|
| 5 |
+
audio_data = f.read()
|
| 6 |
+
hash_object = hashlib.sha256()
|
| 7 |
+
hash_object.update(audio_data)
|
| 8 |
+
audio_hash = hash_object.hexdigest()
|
| 9 |
+
|
| 10 |
+
return audio_hash[:10]
|
| 11 |
+
|
| 12 |
+
def str_to_hash(input_str):
|
| 13 |
+
input_bytes = input_str.encode('utf-8')
|
| 14 |
+
hash_object = hashlib.sha256()
|
| 15 |
+
hash_object.update(input_bytes)
|
| 16 |
+
hash_code = hash_object.hexdigest()
|
| 17 |
+
|
| 18 |
+
return hash_code[:10]
|
| 19 |
+
|
| 20 |
+
def get_unique_code(reference_speaker, text, language):
|
| 21 |
+
return f"{audio_hash(reference_speaker)}_{str_to_hash(text)}_{language}"
|
| 22 |
+
|
| 23 |
+
if __name__ == '__main__':
|
| 24 |
+
|
| 25 |
+
example_inputs = [
|
| 26 |
+
{
|
| 27 |
+
"text": "The bustling city square bustled with street performers, tourists, and local vendors.",
|
| 28 |
+
"language": 'en_us',
|
| 29 |
+
"reference_speaker": "/tmp/gradio/971e5614c2398ed64e7c476251ec42cdb699d033/speaker0-0-100.wav"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"text": "Did you ever hear a folk tale about a giant turtle?",
|
| 33 |
+
"language": 'en_us',
|
| 34 |
+
"reference_speaker": "/tmp/gradio/971e5614c2398ed64e7c476251ec42cdb699d033/speaker0-0-100.wav"
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"text": "El resplandor del sol acaricia las olas, pintando el cielo con una paleta deslumbrante.",
|
| 38 |
+
"language": 'es_default',
|
| 39 |
+
"reference_speaker": "/tmp/gradio/aee184926eca7bb464419ac1e8052907928c68fa/speaker1-0-100.wav",
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"text": "我最近在学习machine learning,希望能够在未来的artificial intelligence领域有所建树。",
|
| 43 |
+
"language": 'zh_default',
|
| 44 |
+
"reference_speaker": "/tmp/gradio/8373380c451c716ded54e6d1de959cc7c5fc4d72/speaker2-0-100.wav",
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"text": "彼は毎朝ジョギングをして体を健康に保っています。",
|
| 48 |
+
"language": 'jp_default',
|
| 49 |
+
"reference_speaker": "/tmp/gradio/5faad1507b5d6bc61a39ca3184db5a7b554a7479/speaker3-0-100.wav",
|
| 50 |
+
}
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
for example_input in example_inputs:
|
| 54 |
+
print(get_unique_code(example_input['reference_speaker'], example_input['text'], example_input['language']))
|
| 55 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
langid
|