Gokulnath2003 commited on
Commit
24f0334
1 Parent(s): 55dfcfe

Upload 4 files

Browse files
Perler-Text2Voice/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Perler-Text2Voice/README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Parler-TTS Mini
3
+ emoji: 🥖
4
+ colorFrom: blue
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 4.26.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ short_description: High-fidelity Text-To-Speech
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Perler-Text2Voice/app.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import torch
4
+ from transformers.models.speecht5.number_normalizer import EnglishNumberNormalizer
5
+ from string import punctuation
6
+ import re
7
+
8
+
9
+ from parler_tts import ParlerTTSForConditionalGeneration
10
+ from transformers import AutoTokenizer, AutoFeatureExtractor, set_seed
11
+
12
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
13
+
14
+
15
+ repo_id = "parler-tts/parler_tts_mini_v0.1"
16
+
17
+ model = ParlerTTSForConditionalGeneration.from_pretrained(repo_id).to(device)
18
+ tokenizer = AutoTokenizer.from_pretrained(repo_id)
19
+ feature_extractor = AutoFeatureExtractor.from_pretrained(repo_id)
20
+
21
+
22
+ SAMPLE_RATE = feature_extractor.sampling_rate
23
+ SEED = 42
24
+
25
+ default_text = "Please surprise me and speak in whatever voice you enjoy."
26
+ examples = [
27
+ [
28
+ "Remember - this is only the first iteration of the model! To improve the prosody and naturalness of the speech further, we're scaling up the amount of training data by a factor of five times.",
29
+ "A male speaker with a low-pitched voice delivering his words at a fast pace in a small, confined space with a very clear audio and an animated tone."
30
+ ],
31
+ [
32
+ "'This is the best time of my life, Bartley,' she said happily.",
33
+ "A female speaker with a slightly low-pitched, quite monotone voice delivers her words at a slightly faster-than-average pace in a confined space with very clear audio.",
34
+ ],
35
+ [
36
+ "Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
37
+ "A male speaker with a slightly high-pitched voice delivering his words at a slightly slow pace in a small, confined space with a touch of background noise and a quite monotone tone.",
38
+ ],
39
+ [
40
+ "Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
41
+ "A male speaker with a low-pitched voice delivers his words at a fast pace and an animated tone, in a very spacious environment, accompanied by noticeable background noise.",
42
+ ],
43
+ ]
44
+
45
+ number_normalizer = EnglishNumberNormalizer()
46
+
47
+ def preprocess(text):
48
+ text = number_normalizer(text).strip()
49
+ text = text.replace("-", " ")
50
+ if text[-1] not in punctuation:
51
+ text = f"{text}."
52
+
53
+ abbreviations_pattern = r'\b[A-Z][A-Z\.]+\b'
54
+
55
+ def separate_abb(chunk):
56
+ chunk = chunk.replace(".","")
57
+ print(chunk)
58
+ return " ".join(chunk)
59
+
60
+ abbreviations = re.findall(abbreviations_pattern, text)
61
+ for abv in abbreviations:
62
+ if abv in text:
63
+ text = text.replace(abv, separate_abb(abv))
64
+ return text
65
+
66
+ @spaces.GPU
67
+ def gen_tts(text, description):
68
+ inputs = tokenizer(description, return_tensors="pt").to(device)
69
+ prompt = tokenizer(preprocess(text), return_tensors="pt").to(device)
70
+
71
+ set_seed(SEED)
72
+ generation = model.generate(
73
+ input_ids=inputs.input_ids, prompt_input_ids=prompt.input_ids, do_sample=True, temperature=1.0
74
+ )
75
+ audio_arr = generation.cpu().numpy().squeeze()
76
+
77
+ return SAMPLE_RATE, audio_arr
78
+
79
+
80
+ css = """
81
+ #share-btn-container {
82
+ display: flex;
83
+ padding-left: 0.5rem !important;
84
+ padding-right: 0.5rem !important;
85
+ background-color: #000000;
86
+ justify-content: center;
87
+ align-items: center;
88
+ border-radius: 9999px !important;
89
+ width: 13rem;
90
+ margin-top: 10px;
91
+ margin-left: auto;
92
+ flex: unset !important;
93
+ }
94
+ #share-btn {
95
+ all: initial;
96
+ color: #ffffff;
97
+ font-weight: 600;
98
+ cursor: pointer;
99
+ font-family: 'IBM Plex Sans', sans-serif;
100
+ margin-left: 0.5rem !important;
101
+ padding-top: 0.25rem !important;
102
+ padding-bottom: 0.25rem !important;
103
+ right:0;
104
+ }
105
+ #share-btn * {
106
+ all: unset !important;
107
+ }
108
+ #share-btn-container div:nth-child(-n+2){
109
+ width: auto !important;
110
+ min-height: 0px !important;
111
+ }
112
+ #share-btn-container .wrap {
113
+ display: none !important;
114
+ }
115
+ """
116
+ with gr.Blocks(css=css) as block:
117
+ gr.HTML(
118
+ """
119
+ <div style="text-align: center; max-width: 700px; margin: 0 auto;">
120
+ <div
121
+ style="
122
+ display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;
123
+ "
124
+ >
125
+ <h1 style="font-weight: 900; margin-bottom: 7px; line-height: normal;">
126
+ Parler-TTS 🗣️
127
+ </h1>
128
+ </div>
129
+ </div>
130
+ """
131
+ )
132
+ gr.HTML(
133
+ f"""
134
+ <p><a href="https://github.com/huggingface/parler-tts"> Parler-TTS</a> is a training and inference library for
135
+ high-fidelity text-to-speech (TTS) models. The model demonstrated here, <a href="https://huggingface.co/parler-tts/parler_tts_mini_v0.1"> Parler-TTS Mini v0.1</a>,
136
+ is the first iteration model trained using 10k hours of narrated audiobooks. It generates high-quality speech
137
+ with features that can be controlled using a simple text prompt (e.g. gender, background noise, speaking rate, pitch and reverberation).</p>
138
+
139
+ <p>Tips for ensuring good generation:
140
+ <ul>
141
+ <li>Include the term "very clear audio" to generate the highest quality audio, and "very noisy audio" for high levels of background noise</li>
142
+ <li>Punctuation can be used to control the prosody of the generations, e.g. use commas to add small breaks in speech</li>
143
+ <li>The remaining speech features (gender, speaking rate, pitch and reverberation) can be controlled directly through the prompt</li>
144
+ </ul>
145
+ </p>
146
+ """
147
+ )
148
+ with gr.Row():
149
+ with gr.Column():
150
+ input_text = gr.Textbox(label="Input Text", lines=2, value=default_text, elem_id="input_text")
151
+ description = gr.Textbox(label="Description", lines=2, value="", elem_id="input_description")
152
+ run_button = gr.Button("Generate Audio", variant="primary")
153
+ with gr.Column():
154
+ audio_out = gr.Audio(label="Parler-TTS generation", type="numpy", elem_id="audio_out")
155
+
156
+ inputs = [input_text, description]
157
+ outputs = [audio_out]
158
+ gr.Examples(examples=examples, fn=gen_tts, inputs=inputs, outputs=outputs, cache_examples=True)
159
+ run_button.click(fn=gen_tts, inputs=inputs, outputs=outputs, queue=True)
160
+ gr.HTML(
161
+ """
162
+ <p>To improve the prosody and naturalness of the speech further, we're scaling up the amount of training data to 50k hours of speech.
163
+ The v1 release of the model will be trained on this data, as well as inference optimisations, such as flash attention
164
+ and torch compile, that will improve the latency by 2-4x. If you want to find out more about how this model was trained and even fine-tune it yourself, check-out the
165
+ <a href="https://github.com/huggingface/parler-tts"> Parler-TTS</a> repository on GitHub.</p>
166
+
167
+ <p>The Parler-TTS codebase and its associated checkpoints are licensed under <a href='https://github.com/huggingface/parler-tts?tab=Apache-2.0-1-ov-file#readme'> Apache 2.0</a>.</p>
168
+ """
169
+ )
170
+
171
+ block.queue()
172
+ block.launch(share=True)
Perler-Text2Voice/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/ylacombe/parler-tts.git@parler-tts-release