v2.2: speaking styles (reading, conversational), 592 voices, new README and samples; CC BY-SA 4.0 (DailyTalk)
Browse filesFiles changed (16)
- .gitattributes+7
- README.md+98-37
- app.py+15-6
- config.json+21-3
- model.safetensors+2-2
- samples/studio11697_s00.wav → samples/story_11697.wavRenamed+2-2
- samples/studio11697_s13.wav → samples/story_8051.wavRenamed+2-2
- samples/studio11697_s17.wav → samples/story_92.wavRenamed+2-2
- samples/studio92_s13.wavDeleted-3
- samples/studio92_s17.wavDeleted-3
- samples/studio92_s00.wav → samples/talk_11697_conversational.wavRenamed+2-2
- samples/talk_11697_reading.wavAdded+3
- samples/talk_92_conversational.wavAdded+3
- samples/talk_92_reading.wavAdded+3
- tts_english/__init__.py+7-1
- tts_english/model.py+23-7
44 unmodified lines4546474849505152535444 unmodified linessamples/studio92_s00.wav filter=lfs diff=lfs merge=lfs -textsamples/studio92_s13.wav filter=lfs diff=lfs merge=lfs -textsamples/studio92_s17.wav filter=lfs diff=lfs merge=lfs -textsamples/story_11697.wav filter=lfs diff=lfs merge=lfs -textsamples/story_8051.wav filter=lfs diff=lfs merge=lfs -textsamples/story_92.wav filter=lfs diff=lfs merge=lfs -textsamples/talk_11697_conversational.wav filter=lfs diff=lfs merge=lfs -textsamples/talk_11697_reading.wav filter=lfs diff=lfs merge=lfs -textsamples/talk_92_conversational.wav filter=lfs diff=lfs merge=lfs -textsamples/talk_92_reading.wav filter=lfs diff=lfs merge=lfs -text1223457 unmodified lines131415161718192021212222232425242526272826272829303132333034353233343536363738393840414041424344454647484950515253545524 unmodified lines808182727383848586878889909192939495969798848599100101102103104891051061071081 unmodified line110111112971139910010111411511611711810511912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916011316116216316417 unmodified lines1821831841851861871881891907 unmodified lines19819920015020120220320420518 unmodified lines22422522617522722817817918022923023123223313 unmodified lines2472482492502512522532542552562572582592022602612622632641 unmodified line266267268210211212269270271272273274275276---license: cc-by-4.0license: cc-by-sa-4.0language:- enpipeline_tag: text-to-speech7 unmodified linesdatasets:- mythicinfinity/libritts_r- MikhailT/hifi-tts- eustlb/dailytalk- mmmhusto/sktts-en-features---
# mmmhusto TTS English
A small multi-speaker English text-to-speech model, written and trained from scratch: phonemes in, a 24 kHz waveformout, 590 voices.**A 56 M-parameter English text-to-speech model that reads and talks.** Written and trained from scratch, smallenough to read in an afternoon, fast enough for a laptop GPU, and open about everything: code, data, training runs andthe experiments that failed.
| | Parameters ||---|---|| Acoustic model (this repo, our own) | 42.0 M || Vocoder (NVIDIA BigVGAN base, MIT, not retrained) | 14.0 M || **Total** | **56.0 M** |- **Two speaking styles in every voice:** audiobook reading and everyday conversation, with a strength knob.- **Three studio voices** (two female, one male, 26 to 30 hours each) plus 589 more.- **Small:** 42 M acoustic model + 14 M vocoder. The whole model is one file of plain PyTorch (~414 lines).- **Fast:** about 7x faster than real time on an RTX 3080, faster than real time on an Apple M-series GPU.- **Controllable:** pace, comma pauses, the gap between sentences, style strength, seed.- **Cheap to adapt:** the conversational style was added in 30 minutes on one RTX 3080 (12 GB).- **A local web page** to try it: `python app.py`.
For scale: Kokoro, the open model we compare against, has 82 M.## Listen
**Status, honestly.** On automatic measures this model is level with Kokoro (table below). The author's own listeningput the first samples (LibriTTS-R voices) roughly 20 to 40 % below Kokoro; the studio voices and the post-processingdescribed under "One steady voice" came after that and have not been judged by ear yet. The measures we use do not capture what the ear hears, so treat thenumbers as a floor, not a verdict. Where the gap comes from (the acoustic model, or the audiobook data and the vocoder)is still being tested.| | Voice 92 (female, default) | Voice 11697 (male) | Voice 8051 (female) ||---|---|---|---|| Reading a story | <audio controls preload="none" src="https://huggingface.co/mmmhusto/TTS-English/resolve/main/samples/story_92.wav"></audio> | <audio controls preload="none" src="https://huggingface.co/mmmhusto/TTS-English/resolve/main/samples/story_11697.wav"></audio> | <audio controls preload="none" src="https://huggingface.co/mmmhusto/TTS-English/resolve/main/samples/story_8051.wav"></audio> |
## SamplesThe same text in both styles ("Are you kidding me? We missed the train again? Okay, okay, I get it."):
`samples/` holds three sentences in the default voice (`en_hifi_92_clean`, female) and in `en_hifi_11697_other`(male), exactly as the code below produces them.| | Reading | Conversational ||---|---|---|| Voice 92 | <audio controls preload="none" src="https://huggingface.co/mmmhusto/TTS-English/resolve/main/samples/talk_92_reading.wav"></audio> | <audio controls preload="none" src="https://huggingface.co/mmmhusto/TTS-English/resolve/main/samples/talk_92_conversational.wav"></audio> || Voice 11697 | <audio controls preload="none" src="https://huggingface.co/mmmhusto/TTS-English/resolve/main/samples/talk_11697_reading.wav"></audio> | <audio controls preload="none" src="https://huggingface.co/mmmhusto/TTS-English/resolve/main/samples/talk_11697_conversational.wav"></audio> |
All clips are exactly what the code below produces (voice 11697 conversational at `style_scale=1.0`).
**Status, honestly.** On automatic measures (intelligibility, signal quality) the model scores like larger openmodels. By ear it is not there yet: the author's listening puts it somewhat below the best open English TTS, mostly innaturalness. The numbers below are a floor, not a verdict; listen to the samples and judge for yourself. What we areworking on next is at the end of this page.
## Quick start
24 unmodified linesspeech take about 5 s.
**Which voice.** Use the studio voices: `en_hifi_92_clean` (default, female), `en_hifi_8051_other` (female) and`en_hifi_11697_other` (male). The model heard each of them for 26 to 30 hours. `tts.voices` lists all 590, but theother 585 are LibriTTS-R readers with 0.1 to 0.5 hours each: they work, and they sound duller and less steady (see`en_hifi_11697_other` (male). The model heard each of them for 26 to 30 hours. `tts.voices` lists all 592; 585 of theothers are LibriTTS-R readers with 0.1 to 0.5 hours each: they work, and they sound duller and less steady (see"One steady voice" below). Keyword arguments override the delivery in `config.json`(`guidance`, `length_scale`, `pause_scale`, `temperature`, `dur_temperature`, `n_timesteps`); `seed=None` gives adifferent rendition every call.
**Styles.** `tts(text, style="conversational")` speaks the text as a reply in a conversation instead of reading italoud; `style_scale` (default 1.5) sets how strongly. Every voice can use either style; without `style` a voice keepsthe style it was recorded in (reading for all but `en_dt_0` and `en_dt_1`). See "Speaking styles" below.
**Pauses.** `pause_scale` (default 2.5) stretches the pauses at commas, semicolons and colons. The pause after asentence end (`. ! ?`) is not stretched: it is capped at `sentence_gap` seconds (default 0.35). The audiobooks taughtthe model about a second of silence between sentences, which the stretch used to make even longer; in a 3-sentencetest the gaps went from 0.85 s to about 0.45 s, including the decay of the last word. `sentence_gap=None` restoresthe earlier behaviour (sentence ends stretched by `pause_scale` like commas).
Speed: 10 solver steps with classifier-free guidance are 20 decoder passes. On a laptop CPU that is about twice slowerthan real time; on a GPU it is far faster than real time.Speed: 10 solver steps with classifier-free guidance are 20 decoder passes. On an RTX 3080 60 replies (3 minutes ofspeech) take 26 s; on an Apple M-series GPU 8 s of speech take about 5 s; on a laptop CPU it is about twice slower thanreal time.
## One steady voice
The first samples of this model used LibriTTS-R voices and sounded clearly worse than Kokoro. Measuring what a listenerThe first samples of this model used LibriTTS-R voices and sounded dull and unsteady. Measuring what a listenerhears, over 30 sentences per voice, showed why, and none of the fixes needed training:
| | Highs above 6 kHz | Colour drift between sentences | Pitch drift | Start of the clip |1 unmodified line| LibriTTS-R voices (0.5 h each) | −22 dB | ±140 Hz | ±8 to 20 Hz | 80 ms || Studio voice 92, raw | −16 dB | ±183 Hz | ±9 Hz | 80 ms || **Studio voice 92, default pipeline** | −16 dB | **±113 Hz** | ±9 Hz | 150 ms of silence || Kokoro af_heart | −15 dB | ±46 Hz | ±5 Hz | 320 ms of silence |
- **The voice.** LibriTTS-R itself has about 10 dB less energy above 10 kHz than Kokoro's output, even as real recordings through the vocoder. The HiFi-TTS studio readers are as bright as Kokoro, and their pauses are about 25 dB quieter.- **The voice.** LibriTTS-R itself has about 10 dB less energy above 10 kHz than the HiFi-TTS studio readers, even as real recordings through the vocoder, and its pauses are about 25 dB noisier.- **The colour.** The flow model draws a slightly different "recording" of the voice for every sentence. `match_timbre` (in `tts_english/post.py`) pulls each sentence's long-term spectrum towards the voice's average profile, stored in `config.json` for the three studio voices. On held-out sentences the drift fell from ±183 to ±101 Hz with PESQ unchanged (3.95 to 3.98). Kokoro is still about 2.5 times steadier. with PESQ unchanged (3.95 to 3.98). Real recordings of the same reader drift too (±178 Hz within one book), because a sentence full of "s" is simply brighter: part of this "drift" is the text, not the model.- **The clip.** `finish` cuts the speech to its edges, fades it, adds clean silence and brings every sentence to one loudness. `tts(text, raw=True)` returns the untouched vocoder output.- **What did not help:** lower temperature and stronger guidance left the drift unchanged; a fixed noise seed helped a little (it is the default: `seed=0`).
## Speaking styles
The audiobook voices only ever heard reading, so the model could only read. A style vector, added to the voice vectorlike a second voice, now carries how a sentence is said; the reading vector is fixed at zero, so reading is exactly themodel as it was. The conversational vector was learned from [DailyTalk](https://github.com/keonlee9420/DailyTalk)(2 actors, 21.5 h of acted everyday dialogue, 2 541 conversations) alongside the three studio voices, on one RTX 3080in 0.5 h.
Measured over 60 everyday replies per voice, with the package's default pipeline (melody = spread of the pitch,range = 5th to 95th percentile, both in semitones; pitch = median, pYIN):
| | Reading | Conversational ×1.0 | Conversational ×1.5 ||---|---|---|---|| **Voice 92** (female): melody / range | 2.60 / 7.8 st | 3.26 / 9.8 st | 3.33 / 10.3 st || pitch, PESQ | 215 Hz, 3.81 | 230 Hz, 3.86 | 223 Hz, 3.78 || **Voice 11697** (male): melody / range | 2.95 / 9.4 st | 3.77 / 11.5 st | 4.13 / 12.5 st || pitch, PESQ | 173 Hz, 3.91 | 170 Hz, 3.77 | 156 Hz, 3.79 || **Voice 8051** (female): melody / range | 2.12 / 6.5 st | 2.29 / 7.3 st | 2.38 / 7.8 st || pitch, PESQ | 234 Hz, 4.02 | 237 Hz, 4.02 | 235 Hz, 3.99 |
Word errors (Whisper small.en) stay between 0.6 and 1.8 % everywhere. Real DailyTalk recordings have a melody of 3.4to 4.2 st and a range of 11 to 13 st. Voice 8051 barely changes: the style works much better on some voices than onothers. Reading quality is unchanged on the 30-sentence bench (PESQ 3.81 before, 3.82 after; word errors 1.8 % both),with a slightly flatter melody (2.75 → 2.56 st).
**What did not work.** The first try kept the new voices' vectors almost fixed (a tenth of the learning rate). The stylethen also learned who was speaking: the male studio voice fell from 170 to 126 Hz, the pitch of the DailyTalk man, andPESQ dropped to 3.60. Letting the voice vectors learn at full speed kept each voice itself; the style came out weaker,and at strength 1.0 the voices keep their pitch (the male voice within 3 Hz). At 1.5 the melody grows a little more butthe male voice speaks 1.5 semitones lower; at 2.0 it drops 3 semitones. Without post-processing the style also brightens the voices (15 to30 % higher spectral centroid), the sound of the DailyTalk studio; with `match_timbre` (on by default) the change staysunder 8 %.
## Architecture
All of it is in `tts_english/model.py`, ~250 lines of plain PyTorch, no vendored code.All of it is in `tts_english/model.py`, ~414 lines of plain PyTorch, no vendored code.
- **Text encoder.** Six pre-norm transformer layers (256 wide) with rotary positions over ARPAbet phonemes from g2p_en. It also predicts a coarse mel per phoneme, which drives the alignment.17 unmodified lines - [LibriTTS-R](https://huggingface.co/datasets/mythicinfinity/libritts_r): audiobook speech, restored, 24 kHz. - [HiFi-TTS](https://huggingface.co/datasets/MikhailT/hifi-tts): studio audiobooks from 10 readers, resampled to 24 kHz. - Both are CC BY 4.0. - [DailyTalk](https://github.com/keonlee9420/DailyTalk) (copy on the Hub: `eustlb/dailytalk`): acted everyday dialogue, 2 speakers, 21.5 h, 24 kHz, CC BY-SA 4.0. Used only for the conversational style (v2.2); its two speakers are the voices `en_dt_0` (male) and `en_dt_1` (female).- **Features:** mels, phonemes and a quality score for every 12th clip. They are public as [mmmhusto/sktts-en-features](https://huggingface.co/datasets/mmmhusto/sktts-en-features): 455 183 clips, 525 hours.- **Training subset:** the best-sounding 60 % of the speakers by the SQUIM SI-SDR estimate, which leaves 590 voices7 unmodified lines|---|---|---|---|---|| v2-en | 25 000 | from scratch | the v2 architecture | 1x AMD MI300X || v2-en-long | +50 000 | v2-en | cosine schedule, EMA 0.9999, 160 k frames per batch | MI300X, 6.3 h || **v2.1 (this model)** | +20 000 | v2-en-long, step 50 000 | phone position, sampled durations, 20 % uniform flow times | MI300X, 2.7 h || v2.1 | +20 000 | v2-en-long, step 50 000 | phone position, sampled durations, 20 % uniform flow times | MI300X, 2.7 h || **v2.2 (this model)** | +6 000 | v2.1 | speaking styles: studio voices 92, 8051, 11697 + DailyTalk (twice), voice vectors at full learning rate, lr 1e-4 | 1x RTX 3080 12 GB, 0.5 h |
Common settings: Adam, bf16, length-bucketed batches with fixed shapes (MIOpen re-plans every new shape),learning-rate warm-up, and gradient clipping at 5. The last v2-en-long run was stopped at 50 000 of 55 000 steps,18 unmodified lines| v2.1, untouched durations | 5 / 1 260 | 3.82 | 25.6 | 0.306 | 5.5 % | 2.66 st || v2, 50 k steps, hand-set pace | 5 / 1 260 | 3.79 | 25.8 | 0.328 | 8.4 % | 2.89 st || v2, 25 k steps, 112 M BigVGAN-v2 | – | 2.41 | 14.2 | – | – | – || Kokoro v1.0, af_heart (82 M) | – | 3.78 | 26.0 | 0.318 | 12.4 % | 2.75 st |
The figures above were measured before the `sentence_gap` cap (sentence ends were stretched like commas then), sothe pace and pause share of the current default are a little faster and lower. Kokoro's pause share includes digitalsilence, so it reads high. The default studio voice reads slowly on its own: withthe default stretch it is about 19 % slower than Kokoro; `pause_scale=1.4` shortens the pauses (13 % pause share).the pace and pause share of the current default are a little faster and lower. The default studio voice reads slowlyon its own; `pause_scale=1.4` shortens the pauses (13 % pause share) and `length_scale=0.95` speeds it up.
## What we learned on the way
13 unmodified lines- **Automatic scores saturate.** Most remaining "word errors" were the scorer's, and PESQ cannot hear what a listener hears, as the status note above says.
## What is next
- **A vocoder tuned to this model.** BigVGAN was trained on mels of real recordings; the mels this model draws are slightly different. Fine-tuning the 14 M vocoder on the model's own mels is in progress.- **Emotions**, as more style vectors next to "conversational".- **Fewer sampling steps** (distillation), for real-time speech on a CPU.- **Other languages**, starting with Slovak.
## Limitations
- English only. The delivery is read-aloud audiobook style, not conversational.- English only. Two styles, reading and conversation; no emotions yet. The conversational style comes from two actors, so it is one particular way of talking, not conversation in general.- g2p_en handles common words well, but numbers, abbreviations and rare names can come out wrong. There is no text normalization beyond what g2p_en does.- The voices belong to real LibriTTS-R and HiFi-TTS readers. Do not use them to impersonate anyone or to deceive.1 unmodified line
## Licenses and attribution
- **This model** (weights and code in this repo): CC BY 4.0.- **Training data:** LibriTTS-R (Koizumi et al., 2023; derived from LibriTTS and LibriSpeech, CC BY 4.0) and HiFi-TTS (Bakhturina et al., 2021, CC BY 4.0).- **This model** (weights and code in this repo): CC BY-SA 4.0, because v2.2 learned from DailyTalk, which is CC BY-SA 4.0. Version v2.1 (in this repo's history, without styles) was trained only on CC BY data and stays CC BY 4.0.- **Training data:** LibriTTS-R (Koizumi et al., 2023; derived from LibriTTS and LibriSpeech, CC BY 4.0), HiFi-TTS (Bakhturina et al., 2021, CC BY 4.0) and DailyTalk (Lee et al., "DailyTalk: Spoken Dialogue Dataset for Conversational Text-to-Speech", ICASSP 2023, CC BY-SA 4.0).- **Vocoder:** NVIDIA BigVGAN (Lee et al., 2023), MIT. Loaded from `nvidia/bigvgan_base_24khz_100band`, not redistributed here.- **G2P:** g2p_en (Kyubyong Park), Apache-2.0, with the CMU Pronouncing Dictionary.27 unmodified lines2829303131323334353637373839405 unmodified lines464748495051526 unmodified lines59606161626364651 unmodified line676869707172732 unmodified lines767778777980818236 unmodified lines11912012112212312412512612012712812913017 unmodified lines14814915014415115215315415515627 unmodified linesmain{max-width:760px;margin:0 auto;padding:28px max(16px,env(safe-area-inset-left)) 60px}h1{font-size:22px;margin:0 0 4px}p.sub{color:var(--mute);margin:0 0 20px}.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:16px;display:grid;gap:14px}textarea{width:100%;min-height:110px;resize:vertical;font:16px/1.5 inherit;padding:10px;border:1px solid var(--line);border-radius:8px;background:var(--bg);color:var(--fg)}textarea{width:100%;min-height:110px;resize:vertical;font:16px/1.5 system-ui,-apple-system,sans-serif;padding:10px;border:1px solid var(--line);border-radius:8px;background:var(--bg);color:var(--fg)}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:12px 20px}label{display:grid;gap:4px;font-size:13px;color:var(--mute)}label b{color:var(--fg);font-weight:600}select{font:inherit;padding:6px;border-radius:6px;border:1px solid var(--line);background:var(--bg);color:var(--fg)}input[type=range]{width:100%;accent-color:var(--acc)}.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}button{font:600 15px inherit;padding:9px 18px;border-radius:8px;border:0;background:var(--acc);color:var(--accfg);cursor:pointer}button{font:600 15px system-ui,-apple-system,sans-serif;padding:9px 18px;border-radius:8px;border:0;background:var(--acc);color:var(--accfg);cursor:pointer}button.ghost{background:transparent;color:var(--acc);border:1px solid var(--line);font-weight:500}button:disabled{opacity:.5;cursor:wait}#status{color:var(--mute);font-size:13px}#out{display:grid;gap:10px;margin-top:18px}.item{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:10px 12px;display:grid;gap:6px}5 unmodified lines<textarea id=text>The morning was quiet. Then the phone rang, and everything changed. She picked it up, listened for a moment, and smiled.</textarea><div class=grid><label>Hlas<select id=voice>__VOICES__</select></label>__STYLE__<label>Medzera medzi vetami <b><span id=gap_v></span> s</b><input id=gap type=range min=0.1 max=1.5 step=0.05 value=0.35></label><label>Pauza pri čiarke <b>×<span id=comma_v></span></b><input id=comma type=range min=1 max=5 step=0.25 value=2.5></label><label>Tempo (väčšie = pomalšie) <b><span id=pace_v></span></b><input id=pace type=range min=0.8 max=1.3 step=0.02 value=1.04></label>6 unmodified lines</main><script>const $=id=>document.getElementById(id);const sliders=["gap","comma","pace","uni","seed"];const sliders=["gap","comma","pace","uni","seed"].concat($("sscale")?["sscale"]:[]);const defaults={};sliders.forEach(s=>{defaults[s]=$(s).value;const f=()=>$(s+"_v").textContent=$(s).value;$(s).oninput=f;f()});$("reset").onclick=()=>sliders.forEach(s=>{$(s).value=defaults[s];$(s).oninput()});async function go(){1 unmodified line $("go").disabled=true;$("status").textContent="Generujem…"; const body={text,voice:$("voice").value,sentence_gap:+$("gap").value,pause_scale:+$("comma").value, length_scale:+$("pace").value,uniform:+$("uni").value,seed:+$("seed").value}; if($("style")){body.style=$("style").value;body.style_scale=+$("sscale").value} try{ const r=await fetch("/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}); if(!r.ok)throw new Error(await r.text());2 unmodified lines const d=document.createElement("div");d.className="item"; d.innerHTML=`<div class=t></div><audio controls autoplay src="${url}"></audio><div class=m></div>`; d.querySelector(".t").textContent=text; d.querySelector(".m").textContent=`${body.voice} · medzera ${body.sentence_gap} s · čiarka ×${body.pause_scale} · tempo ${body.length_scale} · seed ${body.seed} · ${secs} s zvuku za ${took} s`; d.querySelector(".m").textContent=`${body.voice}${body.style?" · "+body.style+" ×"+body.style_scale:""} · medzera ${body.sentence_gap} s · čiarka ×${body.pause_scale} · tempo ${body.length_scale} · seed ${body.seed} · ${secs} s zvuku za ${took} s`; $("out").prepend(d);$("status").textContent=""; }catch(e){$("status").textContent="Chyba: "+e.message} $("go").disabled=false;36 unmodified lines
shown = list(VOICE_NAMES) + [v for v in tts.config.get("recommended_voices", []) if v not in VOICE_NAMES] options = "".join(f'<option value="{v}">{VOICE_NAMES.get(v, v)}</option>' for v in shown if v in tts.voices) names = {"reading": "čítanie", "conversational": "rozhovor"} style = "" if not tts.styles else ( "<label>Štýl<select id=style>" + "".join(f'<option value="{s}">{names.get(s, s)}</option>' for s in tts.styles) + "</select></label>\n<label>Sila štýlu <b>×<span id=sscale_v></span></b>" f"<input id=sscale type=range min=0 max=2 step=0.1 value={tts.config['delivery'].get('style_scale', 1)}></label>") page = PAGE.replace("__VOICES__", options).replace("__DEVICE__", {"mps": "grafika Apple", "cuda": "NVIDIA GPU", page = PAGE.replace("__STYLE__", style).replace("__VOICES__", options).replace("__DEVICE__", {"mps": "grafika Apple", "cuda": "NVIDIA GPU", "cpu": "procesor"}[device]).encode()
class Handler(BaseHTTPRequestHandler):17 unmodified lines req = json.loads(self.rfile.read(int(self.headers.get("Content-Length", 0)))) text = str(req["text"]).strip()[:2000] voice = req.get("voice") if req.get("voice") in tts.voices else None settings = {k: float(req[k]) for k in ("pause_scale", "length_scale") if k in req} settings = {k: float(req[k]) for k in ("pause_scale", "length_scale", "style_scale") if k in req} if req.get("style") in tts.styles: settings["style"] = req["style"] t0 = time.time() with lock: wav = tts(text, voice, seed=int(req.get("seed", 0)), uniform=float(req.get("uniform", 0.7)),14 unmodified lines151617181819202122665 unmodified lines6886896906906916926936946956963 unmodified lines700701702700703704705706707315 unmodified lines102310241025102610271028102910301031103210331034103510361037103810391040104114 unmodified lines "dur_flow": true, "dur_dim": 192, "dur_layers": 3, "t_uniform": 0.2 "t_uniform": 0.2, "n_styles": 2 }, "symbols": [ "<pad>",665 unmodified lines "en_hifi_6670_other", "en_hifi_8051_other", "en_hifi_9136_other", "en_hifi_92_clean" "en_hifi_92_clean", "en_dt_0", "en_dt_1" ], "mel_mean": -5.9344089481310744, "mel_std": 2.3695238543771113,3 unmodified lines "pause_scale": 2.5, "n_timesteps": 10, "temperature": 0.667, "sentence_gap": 0.35 "sentence_gap": 0.35, "style_scale": 1.5 }, "vocoder": "nvidia/bigvgan_base_24khz_100band", "sample_rate": 24000,315 unmodified lines -7.1776, -8.5237 ] }, "styles": [ "reading", "conversational" ], "voice_styles": { "en_dt_1": "conversational", "en_dt_0": "conversational" }, "style_finetune": { "from_step": 20000, "steps": 6000, "data": "HiFi-TTS voices 92, 8051, 11697 + DailyTalk (CC BY-SA 4.0)", "gpu": "RTX 3080" }}12323version https://git-lfs.github.com/spec/v1oid sha256:b578fb5bf7bdc0805af91a026a03cb30941333d972243ac4c6472c9547887d5fsize 167889680oid sha256:b6aa40997901b383515c13941dd94e3dd6bf0f35b883f95b3a7f8ac17a74ca8csize 16789386412323version https://git-lfs.github.com/spec/v1oid sha256:4a94114155beec01e1b128e2d61268a83dfb36375604be351ff70321183d1068size 200204oid sha256:ef3a145ea4aab78d73eb3273372decfa59aca24746bcb4f42c4d3382cacf7810size 36436412323version https://git-lfs.github.com/spec/v1oid sha256:c40b3339c265dba8db09da7d2a04f022948f16ace5617b813e66205e22dd677bsize 243404oid sha256:4f80404624186b9686ce76a7384b57297a03c3f8f4b62a0531411360b828e653size 39892412323version https://git-lfs.github.com/spec/v1oid sha256:2af2743d6970e51d8335fbeb4f942a2c1fba6ebb93345bd86255babb05da7ccdsize 306764oid sha256:1f84fcba2687c809843999d63496bda9b03108d2e2aaf971828e82ff93e9a08bsize 389324123version https://git-lfs.github.com/spec/v1oid sha256:f0234946c9c47322e718c0001110d926ca8e5156bcfc49d2bd98ff507401887fsize 290444123version https://git-lfs.github.com/spec/v1oid sha256:78d6a99fb1203959f61c5a71780e574ad08d7cd3577962b3417c51484d7a3b01size 30676412323version https://git-lfs.github.com/spec/v1oid sha256:28ae9a35167496bfe5b6fc9a8dbd1199961c6ed4293ac3497296227a409784a4size 208844oid sha256:ddf553dcaac95afaa02553e672baef32d4bc4dd2cf38503bd4f1448b9632bf4dsize 234764123version https://git-lfs.github.com/spec/v1oid sha256:e7b7d907fb285581972b656d3c5dcf932cdab6d48236001537230d887bf14242size 239564123version https://git-lfs.github.com/spec/v1oid sha256:65521700d96f8bbe8b5419351a31498f2964a0335948519fd5df9944864e7957size 257804123version https://git-lfs.github.com/spec/v1oid sha256:bd471db6e58dc0986f5f72452d1cd5b9d82e245f3a759d4d2f1e2b06934c3887size 24724442 unmodified lines43444546474849505116 unmodified lines686970687172737475767778798081828342 unmodified lines def __init__(self, model: SkttsV2, config: dict, vocoder, device: str = "cpu"): self.model, self.config, self.vocoder, self.device = model.eval().to(device), config, vocoder, device self.voices = config["voices"] self.styles = config.get("styles", []) # e.g. ["reading", "conversational"]; empty = a model without styles for voice, style in config.get("voice_styles", {}).items(): # voices recorded in another style than reading self.model.spk_style[self.voices.index(voice)] = self.styles.index(style) self._pause, self._stop = pause_tokens(SYMBOLS), stop_tokens(SYMBOLS)
@classmethod16 unmodified lines def mel(self, text: str, voice: str, seed: int | None = 0, sentence_gap=_CONFIG, **settings) -> torch.Tensor: """[100, frames] log-mel. ``settings`` override the delivery in config.json (guidance, length_scale, pause_scale, temperature, dur_temperature, n_timesteps). ``sentence_gap`` is the longest pause after pause_scale, temperature, dur_temperature, n_timesteps, and with a model that has styles ``style`` (a name from ``tts.styles``) and ``style_scale``). ``sentence_gap`` is the longest pause after . ! ? in seconds (default from config.json; None = stretched by pause_scale like commas, as before).""" if seed is not None: torch.manual_seed(seed) ids = encode(phonemize(text)) x = torch.tensor([ids], device=self.device) kw = {**self.config["delivery"], "pause_tokens": self._pause, **settings} if isinstance(kw.get("style"), str): # style="conversational" (None = the style the voice was recorded in) kw["style"] = self.styles.index(kw["style"]) gap = kw.pop("sentence_gap", None) if sentence_gap is _CONFIG else sentence_gap kw.pop("sentence_gap", None) if gap is not None:38 unmodified lines39404142434445464748495051226 unmodified lines2782792802812822832842852862872882892901 unmodified line29229329428328428529529629729828829930030130230330430530640 unmodified lines34734834933535035135235335435535634234335735835936036136238 unmodified lines "dec_dim": 512, "dec_layers": 10, "dec_heads": 8, "dropout": 0.1, "dec_dropout": 0.0, "p_uncond": 0.1, "phone_pos": False, "dur_flow": False, "dur_dim": 192, "dur_layers": 3, "t_uniform": 0.0, "n_styles": 0,}V21 = {"phone_pos": True, "dur_flow": True, "t_uniform": 0.2}# Speaking styles (cfg["n_styles"] = len(STYLES)): a vector per style added to the voice vector, so any voice can be# asked for any style. Style 0 is the audiobook reading every voice was trained on; its vector is fixed at zero, so a# model without styles and the reading style of a model with them are the same network.STYLES = ["reading", "conversational"]POS_DIM = 18 # phone_position featuresDUR_MEAN, DUR_STD = 1.6, 0.7 # log-frames of a token (about 5 frames), to bring the flow target near unit scale
226 unmodified lines self.cfg = c = {**DEFAULT, **(cfg or {})} self.n_vocab, self.n_spks, self.n_feats = n_vocab, n_spks, c["n_feats"] self.spk_emb = nn.Embedding(max(n_spks, 1), c["spk_dim"]) self.style_emb = None if c["n_styles"]: self.style_emb = nn.Embedding(c["n_styles"], c["spk_dim"], padding_idx=0) nn.init.zeros_(self.style_emb.weight) # starts as the model without styles # the style each voice was recorded in (training, and the default when synthesising); not saved with the # weights: the checkpoint keeps it by speaker name ("speaker_styles") self.register_buffer("spk_style", torch.zeros(max(n_spks, 1), dtype=torch.long), persistent=False) self.encoder = TextEncoder(n_vocab, c) self.decoder = Decoder(c) self.dur_flow = DurationFlow(c) if c["dur_flow"] else None1 unmodified line self.register_buffer("mel_mean", torch.as_tensor(mel_mean, dtype=torch.float32).clone()) self.register_buffer("mel_std", torch.as_tensor(mel_std, dtype=torch.float32).clone())
def _speaker(self, spks, spk_vec, batch: int, device): if spk_vec is not None: return spk_vec def _speaker(self, spks, spk_vec, batch: int, device, style=None, style_scale: float = 1.0): """Voice vector plus the style vector. ``style`` None = the style the voice was recorded in.""" if spks is None: spks = torch.zeros(batch, dtype=torch.long, device=device) return self.spk_emb(spks.long()) vec = spk_vec if spk_vec is not None else self.spk_emb(spks.long()) if self.style_emb is None or (spk_vec is not None and style is None): return vec sid = self.spk_style[spks.long()] if style is None else torch.full((batch,), int(style), device=device) return vec + style_scale * self.style_emb(sid)
def forward(self, x, x_lengths, y, y_lengths, spks=None): """(duration loss, prior loss, flow-matching loss, alignment); ``y`` [b, n_feats, t] normalized."""40 unmodified lines length_scale: float = 1.0, spk_vec=None, guidance: float = 1.0, sway: float = -1.0, pause_scale: float = 1.0, pause_tokens: tuple[int, ...] = (), t_min: float = 0.0, dur_temperature: float | None = 0.7, stop_tokens: tuple[int, ...] = (), max_stop: float | None = None) -> dict: max_stop: float | None = None, style: int | None = None, style_scale: float = 1.0) -> dict: """``guidance`` 0 = plain conditional sampling; ``sway`` < 0 spends more steps near the noise end; ``pause_scale`` stretches the tokens in ``pause_tokens`` (the punctuation ids) on top of ``length_scale``: the model learns short pauses from read audiobooks, a longer pause at commas reads more naturally. ``t_min`` is the smallest time the decoder is asked about: training draws the time from a logit-normal, which almost never gives exactly 0, where the first solver step starts. With a ``dur_flow`` head the durations are sampled at ``dur_temperature`` (None = the regression head, as in v2). ``stop_tokens`` (sentence ends) are not stretched by ``pause_scale`` but capped at ``max_stop`` frames (None = no cap).""" spk = self._speaker(spks, spk_vec, x.shape[0], x.device) not stretched by ``pause_scale`` but capped at ``max_stop`` frames (None = no cap). ``style`` is an index into ``STYLES`` (None = the style the voice was recorded in), ``style_scale`` its strength (1 = as trained).""" spk = self._speaker(spks, spk_vec, x.shape[0], x.device, style, style_scale) h_x, _, logw, x_mask = self.encoder(x, x_lengths, spk) # rounded, not ceiled: ceil adds half a frame to every token on average (~6 % slower speech) if self.dur_flow is not None and dur_temperature is not None:.gitattributes+7
README.md+98-37
app.py+15-6
config.json+21-3
model.safetensors+2-2
samples/studio11697_s00.wav → samples/story_11697.wavRenamed+2-2
samples/studio11697_s13.wav → samples/story_8051.wavRenamed+2-2
samples/studio11697_s17.wav → samples/story_92.wavRenamed+2-2
samples/studio92_s13.wavDeleted-3
samples/studio92_s17.wavDeleted-3
samples/studio92_s00.wav → samples/talk_11697_conversational.wavRenamed+2-2
samples/talk_11697_reading.wavAdded+3
samples/talk_92_conversational.wavAdded+3
samples/talk_92_reading.wavAdded+3
tts_english/__init__.py+7-1
tts_english/model.py+23-7