|
Download README.md from davidguzmanr/EveryVoice-JSUT-Japanese: direct link, hf CLI and curl.
- Browser
- Download file 15.2 kB
-
https://huggingface.co/davidguzmanr/EveryVoice-JSUT-Japanese/resolve/main/README.md
- Command line
-
hf download hf://davidguzmanr/EveryVoice-JSUT-Japanese/README.md
-
curl -L -o README.md https://huggingface.co/davidguzmanr/EveryVoice-JSUT-Japanese/resolve/main/README.md
15.2 kB
| language: | |
| - ja | |
| license: other | |
| license_name: jsut-non-commercial | |
| license_link: https://sites.google.com/site/shinnosuketakamichi/publication/jsut | |
| library_name: everyvoice | |
| pipeline_tag: text-to-speech | |
| tags: | |
| - text-to-speech | |
| - tts | |
| - everyvoice | |
| - fastspeech2 | |
| - hifigan | |
| - jsut | |
| - japanese | |
| inference: false | |
| # EveryVoice JSUT (Japanese) | |
| A single-speaker Japanese text-to-speech model trained with [EveryVoice](https://github.com/EveryVoiceTTS/EveryVoice) | |
| 0.3.1: a [FastSpeech2](https://arxiv.org/abs/2006.04558) acoustic model trained from scratch for 250,000 steps | |
| on JSUT (one native female speaker, 10.18 hours of read speech), and a [HiFi-GAN](https://arxiv.org/abs/2010.05646) | |
| vocoder fine-tuned on its output for 100,000 steps. Output: 22,050 Hz mono. | |
| > **The model reads katakana, not ordinary Japanese text.** Its training transcripts were converted to their katakana | |
| > pronunciation with [pyopenjtalk](https://github.com/r9y9/pyopenjtalk), and the input text must go through the same | |
| > conversion (`front_end` below). Kanji and hiragana are not in the model's vocabulary. | |
| ## Files | |
| | File | Contents | | |
| |---|---| | |
| | `feature_prediction.ckpt` | FastSpeech2 (text -> mel spectrogram), EveryVoice checkpoint at step 250,000: weights and optimizer state | | |
| | `vocoder.ckpt` | HiFi-GAN (mel spectrogram -> waveform), EveryVoice checkpoint at step 100,000: generator, discriminators and optimizer state | | |
| | `config/` | the EveryVoice project's configs (`everyvoice-*.yaml`), as trained; the data paths are those of the training cluster | | |
| | `code/prepare_data.py` | corpus -> EveryVoice training data (front end, filtering, wav + metadata.psv) | | |
| | `code/EveryVoice-Open-Bible-Japanese.sh` | the Slurm job that trained the model (EveryVoice preprocess, both trainings, vocoder matching) | | |
| | `code/kana.py` | text front end: Japanese text -> katakana (pyopenjtalk); used for training and inference | | |
| ## How to use | |
| ### Install | |
| ```bash | |
| pip install "everyvoice>=0.3.1,<0.5" huggingface_hub "pyopenjtalk==0.4.1" | |
| ``` | |
| Tested from a clean install (Linux, Python 3.11, everyvoice 0.4.1, torch 2.7.1, pyopenjtalk 0.4.1) and in the training environment (Python 3.10, everyvoice 0.3.1, torch 2.3.1), on GPU and CPU; they give the same audio (on CPU up to floating-point differences). everyvoice 0.4.1 needs torch 2.7.1 and Python 3.10-3.12; for a specific CUDA or | |
| CPU build of PyTorch, install torch 2.7.1 first. `pyopenjtalk` builds from source, so it needs CMake and a C++ compiler, and its first call downloads the Open JTalk dictionary. | |
| > **Do not use everyvoice 0.5.0.** The checkpoints were written by everyvoice 0.3.1 (FastSpeech2 model | |
| > version 1.2), which puts 12 built-in symbols (padding, space, punctuation classes) at the start of the symbol table. | |
| > When 0.5.0 converts a 1.2 checkpoint to its format, it rebuilds the old table without them, so every row of the | |
| > embedding table is attributed to the wrong symbol: the Japanese and Korean models load without error but speak | |
| > gibberish, and the Indonesian one fails to load. 0.4.1 reads the checkpoints as they are (no conversion) and gives | |
| > the same audio as 0.3.1. The snippet below stops on 0.5. | |
| ### Synthesize | |
| ```python | |
| import shutil | |
| import tempfile | |
| import unicodedata | |
| from importlib.metadata import version | |
| from pathlib import Path | |
| import torch | |
| from huggingface_hub import snapshot_download | |
| from packaging.version import Version | |
| # everyvoice 0.5 converts these checkpoints wrongly (see Install): stop rather than synthesize gibberish | |
| assert Version(version("everyvoice")) < Version("0.5"), "this model needs everyvoice 0.3.1-0.4.1: pip install 'everyvoice<0.5'" | |
| from everyvoice.config.type_definitions import DatasetTextRepresentation | |
| from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.cli.synthesize import get_global_step, synthesize_helper | |
| from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.model import FastSpeech2 | |
| from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.type_definitions import SynthesizeOutputFormats | |
| from everyvoice.model.vocoder.HiFiGAN_iSTFT_lightning.hfgl.utils import load_hifigan_from_checkpoint | |
| import re | |
| import pyopenjtalk | |
| # Text front end, the same as code/kana.py, which converted the training transcripts | |
| PUNCT = {"、": ",", ",": ",", "。": ".", ".": ".", "?": "?", "!": "!", "…": ",", "―": ",", "—": ","} | |
| KEEP = re.compile(r"[ァ-ヺー,.?!]") | |
| def front_end(text): # Japanese text -> katakana as pronounced, with 、。?! written as , . ? ! | |
| raw = "".join(PUNCT.get(ch, ch) for ch in pyopenjtalk.g2p(text, kana=True)) | |
| unread = [ch for ch in raw if not KEEP.match(ch) and unicodedata.category(ch)[0] in "LN"] | |
| if unread: | |
| print(f"pyopenjtalk could not read {''.join(unread)}: skipped") | |
| return "".join(ch for ch in raw if KEEP.match(ch)) | |
| repo_id = "davidguzmanr/EveryVoice-JSUT-Japanese" | |
| local = Path(snapshot_download(repo_id, allow_patterns=["*.ckpt"])) | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| model = FastSpeech2.load_from_checkpoint(str(local / "feature_prediction.ckpt"), map_location=device).to(device).eval() | |
| model_step = get_global_step(local / "feature_prediction.ckpt") | |
| vocoder_ckpt = torch.load(str(local / "vocoder.ckpt"), map_location=device, weights_only=True) | |
| vocoder, vocoder_config = load_hifigan_from_checkpoint(vocoder_ckpt, device) | |
| vocoder_step = vocoder_ckpt["global_step"] | |
| # Symbols seen in training: the characters of the transcripts and the punctuation `,` `.` `?` `!` | |
| symbols = model.config.text.symbols.model_dump() | |
| TRAINED = {s for name, values in symbols.items() if name.endswith("_characters") for s in values} | set(",.?!") | |
| def synthesize(text, wav_path, duration_control=1.0): | |
| # Write `text` to `wav_path` (22,050 Hz mono). duration_control > 1 makes speech slower, < 1 faster. | |
| model_text = front_end(text) | |
| unknown = "".join(sorted({ch for ch in model_text if ch not in TRAINED and ch != " "})) | |
| if unknown: | |
| print(f"not in the training transcripts, dropped: {unknown}") | |
| model_text = "".join(ch for ch in model_text if ch in TRAINED or ch == " ") | |
| with tempfile.TemporaryDirectory() as tmp: | |
| synthesize_helper( | |
| model=model, texts=None, style_reference=None, language=None, speaker=None, | |
| duration_control=duration_control, global_step=model_step, | |
| output_type=[SynthesizeOutputFormats.wav], text_representation=DatasetTextRepresentation.characters, | |
| accelerator="gpu" if device.type == "cuda" else "cpu", devices=1, device=device, | |
| batch_size=1, num_workers=0, filelist=None, | |
| filelist_data=[dict(basename="utt", characters=model_text, language="und", speaker="speaker_0", | |
| duration_control=duration_control, is_last_input_chunk=True)], | |
| output_dir=Path(tmp), teacher_forcing_directory=None, vocoder_model=vocoder, | |
| vocoder_config=vocoder_config, vocoder_global_step=vocoder_step, | |
| ) | |
| (wav,) = Path(tmp).glob("**/*.wav") # EveryVoice names the file after the text; move it to wav_path | |
| shutil.move(wav, wav_path) | |
| return model_text | |
| print(synthesize("吾輩は猫である。名前はまだ無い。", "output.wav")) # ワガハイワネコデアル.ナマエワマダナイ. | |
| ``` | |
| The model has one speaker (`speaker_0`) and one language (`und`, EveryVoice's "undetermined"); both are fixed in | |
| `filelist_data`. Call `synthesize` once per sentence: the models are loaded once, and each call writes one wav. EveryVoice | |
| prints a progress bar and some logs on every call. Synthesis is deterministic: the same text gives the same audio. | |
| ### The text front end | |
| `front_end` turns the text into the symbols the model was trained on: | |
| | Input | Model input | | |
| |---|---| | |
| | 吾輩は猫である。名前はまだ無い。 | ワガハイワネコデアル.ナマエワマダナイ. | | |
| | 今日は2026年12月2日です。東京の天気は晴れ、気温は15度でしょう。 | キョーワニセンニジューロクネンジューニガツフツカデス.トーキョーノテンキワハレ,キオンワジューゴドデショー. | | |
| | NHKのニュースを見ましたか? | エヌエイチケイノニュースヲミマシタカ? | | |
| - Particles は and へ become ワ and エ, long vowels become ー, and numbers, dates and Latin letters are read out. | |
| - `、` `。` `?` `!` become `,` `.` `?` `!` (`…` and dashes become `,`). Japanese has no spaces, so these marks are the | |
| only phrase boundaries the model sees: keep them in the input. | |
| - Everything else is dropped: brackets, quotes, spaces, symbols, and any character pyopenjtalk cannot read (a rare kanji | |
| missing from its dictionary; `front_end` prints it). | |
| - The readings come from the Open JTalk dictionary. Names, rare words and words with several readings can be misread. | |
| Check the katakana, and fix a reading by writing that part in katakana yourself: katakana passes through unchanged. | |
| Katakana carries no pitch accent; the model infers it from context and can get it wrong. | |
| - Use pyopenjtalk 0.4.1, the version the training transcripts were converted with: forks such as `pyopenjtalk-plus` use | |
| other dictionaries and read some words differently. | |
| - The model's vocabulary is 82 characters: `ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロワヲンヴー`, plus the punctuation `,.?!`. | |
| `synthesize` drops anything else, with a warning. | |
| ## Training data | |
| [JSUT 1.1](https://sites.google.com/site/shinnosuketakamichi/publication/jsut) (Sonobe, Takamichi and Saruwatari, 2017): | |
| 7,696 utterances (10.3 h) of one native Japanese female speaker reading Japanese sentences, recorded in an | |
| anechoic room at 48 kHz, in nine subsets (basic5000, utparaphrase512, onomatopee300, countersuffix26, loanword128, | |
| voiceactress100, travel1000, precedent130, repeat500). All nine were used. `code/prepare_data.py` converts every | |
| transcript with `code/kana.py` and keeps 7,661 utterances (10.18 h, 1.1-14.4 s): it drops | |
| 4 longer than 15 s and 31 containing characters pyopenjtalk could not read (rare kanji, lone Latin | |
| letters). These are the same utterances as [VITS-JSUT-Japanese](https://huggingface.co/davidguzmanr/VITS-JSUT-Japanese). | |
| EveryVoice's preprocessing resampled the audio to 22,050 Hz. No sentence of the Multilingual-MOS listening test is in the | |
| training data. The audio and the training filelists are not included here. | |
| ## Training procedure | |
| - EveryVoice 0.3.1 with the recipe of the Open Bible EveryVoice models | |
| ([open-bible-models](https://github.com/davidguzmanr/open-bible-models), `jobs/FastSpeech/`): character input, all | |
| utterances for training (`train_split` 1.0), validation on the first 511 training utterances. Changes: the corpus and | |
| its text front end, `max_epochs` 10,000 (so that the step budget, not the epoch limit, ends training) and a checkpoint | |
| every 5,000 steps. | |
| - Audio features: 22,050 Hz, 80 mel bands up to 8 kHz, FFT and window 1,024, hop 256; utterances of 0.4-15 s. | |
| - FastSpeech2 with Conformer encoder and decoder (4 layers each, dimension 256, 2 heads), duration, pitch and energy | |
| predictors (pitch and energy averaged per input symbol), alignment learned jointly (no external aligner), and a postnet; | |
| 18.2 M parameters. Trained 250,000 steps (2,100 epochs), batch 32 on each of 2 NVIDIA L40S (DDP, global batch 64), | |
| Noam schedule with learning rate 1e-3 and 1,000 warm-up steps. | |
| - Vocoder: HiFi-GAN V1 (512 initial channels, upsampling 8 x 8 x 2 x 2), initialized from EveryVoice's universal | |
| checkpoint (`hifigan_universal_v1_everyvoice.ckpt`) and fine-tuned 100,000 steps (420 epochs) on the | |
| mel spectrograms this FastSpeech2 predicts for the training utterances with their true durations (teacher forcing), so | |
| the vocoder learns the acoustic model's output. Batch 32 on each of 2 GPUs, AdamW with learning rate 1e-5. | |
| - The whole job (preprocessing, both trainings, spectrogram generation) took 18 h 17 min on 2 NVIDIA L40S. | |
| To retrain (source: [`everyvoice-tts/` in Multilingual-MOS](https://github.com/davidguzmanr/Multilingual-MOS/tree/53457fe/everyvoice-tts)): | |
| ```bash | |
| python code/prepare_data.py --language Japanese # writes data/EveryVoice/Japanese/ (wavs/, metadata.psv): needs pyopenjtalk 0.4.1, ../vits/kana.py | |
| everyvoice new-project # wavs/ and metadata.psv: psv, characters, no text transformation | |
| sbatch code/EveryVoice-Open-Bible-Japanese.sh # preprocess, text-to-spec, vocoder matching, vocoder | |
| ``` | |
| ## Evaluation | |
| An intelligibility check, not a listening test: the 34 Japanese sentences of the Multilingual-MOS listening test (from | |
| Common Voice, FLEURS and the Kokoro audiobook corpus; none is in the training data) were synthesized with the snippet above and | |
| transcribed with Whisper (`openai/whisper-large-v3-turbo`, language set). Character error rate on katakana (reference and transcript both converted with `front_end`, so the choice between homophone kanji does not count as an error): | |
| median 3.2% (mean 5.3%). | |
| ## Limitations | |
| - One voice and one style: neutral read speech. No control of emotion or speaking style; `duration_control` sets the | |
| speed. | |
| - Pronunciation is only as good as pyopenjtalk's reading of the text; pitch accent is not in the input. | |
| - The voice is a real person's: do not use it to impersonate her or to pass synthetic speech off as hers. | |
| ## License | |
| Research and non-commercial use only, following the terms of the JSUT audio: research at academic institutions, | |
| non-commercial research (including within commercial organizations) and personal use. Commercial use needs permission | |
| from the JSUT rights holders (University of Tokyo); see the | |
| [JSUT page](https://sites.google.com/site/shinnosuketakamichi/publication/jsut). The JSUT transcripts are CC BY-SA 4.0. The scripts in `code/` come from [Multilingual-MOS](https://github.com/davidguzmanr/Multilingual-MOS) (Apache 2.0); the Slurm job follows | |
| [open-bible-models](https://github.com/davidguzmanr/open-bible-models) (MIT). | |
| ## Citation | |
| ```bibtex | |
| @article{sonobe2017jsut, | |
| title = {{JSUT} corpus: free large-scale {Japanese} speech corpus for end-to-end speech synthesis}, | |
| author = {Sonobe, Ryosuke and Takamichi, Shinnosuke and Saruwatari, Hiroshi}, | |
| journal = {arXiv preprint arXiv:1711.00354}, | |
| year = {2017} | |
| } | |
| @inproceedings{ren2021fastspeech2, | |
| title = {{FastSpeech} 2: Fast and High-Quality End-to-End Text to Speech}, | |
| author = {Ren, Yi and Hu, Chenxu and Tan, Xu and Qin, Tao and Zhao, Sheng and Zhao, Zhou and Liu, Tie-Yan}, | |
| booktitle = {International Conference on Learning Representations}, | |
| year = {2021} | |
| } | |
| @inproceedings{kong2020hifigan, | |
| title = {{HiFi-GAN}: Generative Adversarial Networks for Efficient and High Fidelity Speech Synthesis}, | |
| author = {Kong, Jungil and Kim, Jaehyeon and Bae, Jaekyoung}, | |
| booktitle = {Advances in Neural Information Processing Systems}, | |
| volume = {33}, | |
| pages = {17022--17033}, | |
| year = {2020} | |
| } | |
| ``` | |