Brais: Nós Project's Galician TTS Model

Model description

Brais is a Galician TTS model developed by the Nós project. It was trained from scratch using the Coqui TTS Python library on the corpus Nos_Brais-GL. This corpus comprises a total of 16,121 sentences recorded by a professional male voice talent, corresponding to approximately 18 hours of speech.

The model was trained directly on grapheme inputs, so no phonetic transcription is required. The Cotovía tool can be used to normalize the input text.

You can test the model in our live inference demo (Nós-TTS) or in our spaces (Galician TTS).

Intended uses and limitations

You can use this model to generate synthetic speech in Galician.

Installation

Cotovía

For text normalization, you can use the front-end of Cotovía. This software is available for download on the SourceForge website. The required Debian packages are cotovia_0.5_amd64.deb and cotovia-lang-gl_0.5_all.deb, which can be installed using the following commands:

sudo dpkg -i cotovia_0.5_amd64.deb
sudo dpkg -i cotovia-lang-gl_0.5_all.deb

TTS library

To synthesize speech, you need to install the Coqui TTS library:

pip install TTS

How to use

Command-line usage

The following command normalizes and synthesizes the input text using the Brais model:

echo "Son Brais, unha voz creada con intelixencia artificial" | cotovia -p -n -S | iconv -f iso88591 -t utf8 | tts --text "$(cat -)" --model_path brais.pth --config_path config.json --out_path brais.wav

The output synthesized speech is saved to the specified audio file.

Python usage

Normalization and synthesis can also be performed within Python:

import argparse
import string
import subprocess
from TTS.utils.synthesizer import Synthesizer

def sanitize_filename(filename):
    """Remove or replace any characters that are not allowed in file names."""
    return ''.join(c for c in filename if c.isalnum() or c in (' ', '_', '-')).rstrip()

def to_cotovia(text):
    # Input and output Cotovía files
    COTOVIA_IN_TXT_PATH = res + '.txt'
    COTOVIA_IN_TXT_PATH_ISO = 'iso8859-1' + res + '.txt'
    COTOVIA_OUT_PRE_PATH = 'iso8859-1' + res + '.pre'
    COTOVIA_OUT_PRE_PATH_UTF8 = 'utf8' + res + '.pre'

    with open(COTOVIA_IN_TXT_PATH, 'w') as f:
        f.write(text + '\n')

    # UTF-8 to ISO8859-1
    subprocess.run(["iconv", "-f", "utf-8", "-t", "iso8859-1", COTOVIA_IN_TXT_PATH, "-o", COTOVIA_IN_TXT_PATH_ISO], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
    subprocess.run(["cotovia", "-i", COTOVIA_IN_TXT_PATH_ISO, "-p"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
    subprocess.run(["iconv", "-f", "iso8859-1", "-t", "utf-8", COTOVIA_OUT_PRE_PATH, "-o", COTOVIA_OUT_PRE_PATH_UTF8], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)

    segs = []
    try:
        with open(COTOVIA_OUT_PRE_PATH_UTF8, 'r') as f:
            segs = [line.rstrip() for line in f]
    except:
        print("ERROR: Couldn't read cotovia output")

    subprocess.run(["rm", COTOVIA_IN_TXT_PATH, COTOVIA_IN_TXT_PATH_ISO, COTOVIA_OUT_PRE_PATH, COTOVIA_OUT_PRE_PATH_UTF8], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)

    return segs

def text_preprocess(text):
    cotovia_preproc_text = to_cotovia(text)

    # Convert list to string
    cotovia_preproc_text_res = ' '.join(cotovia_preproc_text)

    # Add final punctuation if missing
    if cotovia_preproc_text_res[-1] not in string.punctuation:
        cotovia_preproc_text_res += '.'

    return cotovia_preproc_text_res

def main():
    parser = argparse.ArgumentParser(description='Cotovía text normalisation')
    parser.add_argument('text', type=str, help='Text to synthetize')
    parser.add_argument('model_path', type=str, help='Absolute path to the model checkpoint.pth')
    parser.add_argument('config_path', type=str, help='Absolute path to the model config.json')

    args = parser.parse_args()

    print("Text before preprocessing: ", args.text)
    text = text_preprocess(args.text)
    print("Text after preprocessing: ", text)

    synthesizer = Synthesizer(
        args.model_path, args.config_path, None, None, None, None,
    )

    # Step 1: Extract the first word from the text
    first_word = args.text.split()[0] if args.text.split() else "audio"
    first_word = sanitize_filename(first_word)  # Sanitize to make it a valid filename

    # Step 2: Use synthesizer's built-in function to synthesize and save the audio
    wavs = synthesizer.tts(text)
    filename = f"{first_word}.wav"
    synthesizer.save_wav(wavs, filename)

    print(f"Audio file saved as: {filename}")

if __name__ == "__main__":
    main()

This Python code takes an input text, normalizes it using Cotovía’s front-end, synthesizes speech from the normalized text, and saves the synthetic output speech as a .wav file.

A more advanced version, including additional text preprocessing, can be found in the script synthesize.py, avaliable in this repository. You can use this script to synthesise speech from an input text as follows:

python synthesize.py text model_path config_path

Training

Hyperparameter

The model is based on VITS proposed by Kim et al. The following hyperparameters were set in the coqui framework.

Hyperparameter Value
Model vits
Batch Size 48
Eval Batch Size 16
Mixed Precision true
Window Length 1024
Hop Length 256
FTT size 1024
Num Mels 80
Phonemizer null
Phoneme Language null
Text Cleaners null
Formatter nos_grafemas
Optimizer adam
Adam betas (0.8, 0.99)
Adam eps 1e-09
Adam weight decay 0.01
Learning Rate Gen 0.0002
Lr. scheduler Gen ExponentialLR
Lr. scheduler Gamma Gen 0.999875
Learning Rate Disc 0.0002
Lr. scheduler Disc ExponentialLR
Lr. scheduler Gamma Disc 0.999875

The model was trained for 160,000 steps.

The nos_grafemas formatter is a modification of the LJSpeech formatter with one extra column for the normalized input (extended numbers and acronyms).

Additional information

Authors

Antonio Moscoso.

Contact information

For further information, send an email to proxecto.nos@usc.gal

Licensing Information

Apache License, Version 2.0

Funding

This research was produced within the framework of the Proxecto Nós, funded by the Ministry for Digital Transformation and Public Administration and the Recovery, Transformation, and Resilience Plan – Funded by the European Union – NextGenerationEU, as part of the Ilenia Project with reference 2022/TL22/00215336, and previously “The Nós project: Galician in the society and economy of Artificial Intelligence”, resulting from the agreement 2021-CP080 between the Xunta de Galicia and the University of Santiago de Compostela, and thanks to the Investigo program, within the National Recovery, Transformation and Resilience Plan, within the framework of the European Recovery Fund (NextGenerationEU).

Citation information

If you use this model, please cite as follows:

Moscoso, Antonio. 2024. Nos_TTS-brais-vits-graphemes. URL: https://huggingface.co/proxectonos/Nos_TTS-brais-vits-graphemes

Downloads last month
15
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for proxectonos/Nos_TTS-brais-vits-graphemes

Quantizations
1 model

Collection including proxectonos/Nos_TTS-brais-vits-graphemes