Spaces:
Sleeping
Sleeping
File size: 12,155 Bytes
a31f9ef cf910aa 3899cce a31f9ef 0bdc801 a31f9ef 0bdc801 a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 3899cce a31f9ef 0bdc801 a31f9ef cf910aa a31f9ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
import shutil
import sys
import zipfile
from datetime import datetime
from functools import partial
from pathlib import Path
from tempfile import gettempdir
from typing import Dict
import gradio as gr
from scipy.io.wavfile import read
from en_tts_app import (get_log_path, get_work_dir, initialize_app, load_models_to_cache, run_main,
synthesize_english)
def run():
exit_code = initialize_app()
if exit_code > 0:
sys.exit(exit_code)
exit_code = run_main(launch_interface)
sys.exit(exit_code)
def launch_interface():
cache = load_models_to_cache()
fn = partial(synt, cache=cache)
# iface = gr.Interface(
# fn=fn,
# inputs=[gr.Textbox(example_text, label="Text")],
# outputs=[gr.Audio(type="numpy", label="Speech", autoplay=True)],
# )
with gr.Blocks(
title="en-tts"
) as demo:
gr.Markdown(
"""
# English Speech Synthesis
Enter or paste your text into the provided text box and click the **Synthesize** button to convert it into speech. You can adjust settings as desired before synthesizing.
"""
)
with gr.Tab("Synthesis"):
with gr.Row():
with gr.Column():
with gr.Group():
input_txt_box = gr.Textbox(
None,
label="Input",
placeholder="Enter the text you want to synthesize (or load an example from below).",
lines=10,
max_lines=5000,
)
with gr.Accordion("Settings", open=False):
sent_norm_check_box = gr.Checkbox(
False,
label="Skip normalization",
info="Skip normalization of numbers, units and abbreviations."
)
sent_sep_check_box = gr.Checkbox(
False,
label="Skip sentence separation",
info="Skip sentence separation after these characters: .?!"
)
sil_sent_txt_box = gr.Number(
0.4,
minimum=0.0,
maximum=60,
step=0.1,
label="Silence between sentences (s)",
info="Insert silence between each sentence."
)
sil_para_txt_box = gr.Number(
1.0,
minimum=0.0,
maximum=60,
step=0.1,
label="Silence between paragraphs (s)",
info="Insert silence between each paragraph."
)
seed_txt_box = gr.Number(
0,
minimum=0,
maximum=999999,
label="Seed",
info="Seed used for inference in order to be able to reproduce the results."
)
sigma_txt_box = gr.Number(
1.0,
minimum=0.0,
maximum=1.0,
step=0.001,
label="Sigma",
info="Sigma used for inference in WaveGlow."
)
max_decoder_steps_txt_box = gr.Number(
5000,
minimum=1,
step=500,
label="Maximum decoder steps",
info="Stop the synthesis after this number of decoder steps at the latest."
)
denoiser_txt_box = gr.Number(
0.005,
minimum=0.0,
maximum=1.0,
step=0.001,
label="Denoiser strength",
info="Level of noise reduction used to remove the noise bias from WaveGlow."
)
synt_btn = gr.Button("Synthesize", variant="primary")
with gr.Column():
with gr.Group():
with gr.Row():
with gr.Column():
out_audio = gr.Audio(
type="numpy",
label="Output",
autoplay=True,
)
with gr.Accordion(
"Log",
open=False,
):
out_md = gr.Textbox(
interactive=False,
show_copy_button=True,
lines=15,
max_lines=10000,
placeholder="Log will be displayed here.",
show_label=False,
)
dl_btn = gr.DownloadButton(
"Download working directory",
variant="secondary",
)
with gr.Row():
gr.Examples(
examples=[
[
"When the sunlight strikes raindrops in the air, they act as a prism and form a rainbow.",
5000, 1.0, 0.0005, 0, 0.4, 1.0, False, False
],
[
"Please call Stella. Ask her to bring these things with her from the store: six spoons of fresh snow peas, five thick slabs of blue cheese, and maybe a snack for her brother Bob.\n\nWe also need a small plastic snake and a big toy frog for the kids. She can scoop these things into three red bags, and we will go meet her Wednesday at the train station.",
5000, 1.0, 0.0005, 0, 0.4, 1.0, False, False
],
# [
# "The North Wind and the Sun were disputing which was the stronger, when a traveler came along wrapped in a warm cloak. They agreed that the one who first succeeded in making the traveler take his cloak off should be considered stronger than the other. Then the North Wind blew as hard as he could, but the more he blew the more closely did the traveler fold his cloak around him; and at last the North Wind gave up the attempt. Then the Sun shined out warmly, and immediately the traveler took off his cloak. And so the North Wind was obliged to confess that the Sun was the stronger of the two.",
# ],
# [
# "When the sunlight strikes raindrops in the air, they act as a prism and form a rainbow. The rainbow is a division of white light into many beautiful colors. These take the shape of a long round arch, with its path high above, and its two ends apparently beyond the horizon. There is, according to legend, a boiling pot of gold at one end. People look, but no one ever finds it. When a man looks for something beyond his reach, his friends say he is looking for the pot of gold at the end of the rainbow. Throughout the centuries people have explained the rainbow in various ways. Some have accepted it as a miracle without physical explanation. To the Hebrews it was a token that there would be no more universal floods. The Greeks used to imagine that it was a sign from the gods to foretell war or heavy rain. The Norsemen considered the rainbow as a bridge over which the gods passed from earth to their home in the sky. Others have tried to explain the phenomenon physically. Aristotle thought that the rainbow was caused by reflection of the sun's rays by the rain. Since then physicists have found that it is not reflection, but refraction by the raindrops which causes the rainbows. Many complicated ideas about the rainbow have been formed. The difference in the rainbow depends considerably upon the size of the drops, and the width of the colored band increases as the size of the rops increases. The actual primary rainbow observed is said to be the effect of superimposition of a number of bows. If the red of the second bow falls upon the green of the first, the result is to give a bow with an abnormally wide yellow band, since red and green light when mixed form yellow. This is a very common type of bow, one showing mainly red and yellow, with little or no green or blue."
# ]
],
fn=fn,
inputs=[
input_txt_box,
max_decoder_steps_txt_box,
sigma_txt_box,
denoiser_txt_box,
seed_txt_box,
sil_sent_txt_box,
sil_para_txt_box,
sent_norm_check_box,
sent_sep_check_box,
],
outputs=[
out_audio,
out_md,
dl_btn,
],
label="Examples",
cache_examples=False,
)
with gr.Tab("Info"):
with gr.Column():
gr.Markdown(
"""
### General information
- Speaker: Linda Johnson
- Language: English
- Accent: North American
- Supported special characters: `.?!,:;-—"'()[]`
### Evaluation results
|Metric|Value|
|---|---|
|MOS naturalness|3.55 ± 0.28 (GT: 4.17 ± 0.23)|
|MOS intelligibility|4.44 ± 0.24 (GT: 4.63 ± 0.19)|
|Mean MCD-DTW|29.15|
|Mean penalty|0.1018|
### Components
|Component|Name|URLs|
|---|---|---|
|Acoustic model|Tacotron|[Checkpoint](https://zenodo.org/records/10107104), [Code](https://github.com/stefantaubert/tacotron)|
|Vocoder|WaveGlow|[Checkpoint](https://catalog.ngc.nvidia.com/orgs/nvidia/models/waveglow_ljs_256channels/files?version=3), [Code](https://github.com/stefantaubert/waveglow)
|Dataset|LJ Speech|[Link](https://keithito.com/LJ-Speech-Dataset), [Transcriptions](https://zenodo.org/records/7499098)|
### Citation
Taubert, S. (2024). en-tts (Version 0.0.1) [Computer software]. https://doi.org/10.5281/zenodo.10479347
### Acknowledgments
Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) – Project-ID 416228727 – [CRC 1410](https://gepris.dfg.de/gepris/projekt/416228727?context=projekt&task=showDetail&id=416228727)
The authors gratefully acknowledge the GWK support for funding this project by providing computing time through the Center for Information Services and HPC (ZIH) at TU Dresden.
The authors are grateful to the Center for Information Services and High Performance Computing [Zentrum fur Informationsdienste und Hochleistungsrechnen (ZIH)] at TU Dresden for providing its facilities for high throughput calculations.
### App information
- Version: 0.0.1
- License: [MIT](https://github.com/stefantaubert/en-tts?tab=MIT-1-ov-file#readme)
- GitHub: [stefantaubert/en-tts](https://github.com/stefantaubert/en-tts)
"""
)
synt_btn.click(
fn=fn,
inputs=[
input_txt_box,
max_decoder_steps_txt_box,
sigma_txt_box,
denoiser_txt_box,
seed_txt_box,
sil_sent_txt_box,
sil_para_txt_box,
sent_norm_check_box,
sent_sep_check_box,
],
outputs=[
out_audio,
out_md,
dl_btn,
],
)
demo.launch(
share=False,
debug=True,
inbrowser=True,
quiet=False,
show_api=False,
)
def synt(text: str, max_decoder_steps: int, sigma: float, denoiser_strength: float, seed: int, silence_sentences: float, silence_paragraphs: float, skip_normalization: bool, skip_sentence_separation: bool, cache: Dict) -> str:
result_path = synthesize_english(
text, cache,
max_decoder_steps=max_decoder_steps,
seed=seed,
sigma=sigma,
denoiser_strength=denoiser_strength,
silence_paragraphs=silence_paragraphs,
silence_sentences=silence_sentences,
skip_normalization=skip_normalization,
skip_sentence_separation=skip_sentence_separation,
)
rate, audio_int = read(result_path)
logs = get_log_path().read_text("utf-8")
zip_dl_path = create_zip_file_of_output()
return (rate, audio_int), logs, zip_dl_path
def create_zip_file_of_output() -> Path:
work_dir = get_work_dir()
name = f"en-tts-{datetime.now().strftime('%Y-%m-%dT%H-%M-%S')}"
res = shutil.make_archive(Path(gettempdir()) / name, 'zip', root_dir=work_dir)
resulting_zip = Path(res)
with zipfile.ZipFile(resulting_zip, "a", compression=zipfile.ZIP_DEFLATED) as zipf:
source_path = get_log_path()
destination = 'output.log'
zipf.write(source_path, destination)
return resulting_zip
if __name__ == "__main__":
run()
|