BreezyVoice

repository·main·Indexed 43 days ago

https://github.com/mtkresearch/breezyvoice

A voice-cloning text-to-speech system optimized for Taiwanese Mandarin. It features high naturalness, strong performance in code-switching scenarios, and phonetic control via bopomofo (注音) inputs. The system supports single and batch audio inference, deployment via Docker with an OpenAI-compatible API, and integrates with Matcha-TTS and HiFi-GAN.

Tokens
8.6K
Snippets
32
Records
36
Agent score
56%

What's inside BreezyVoice

  1. Run batch audio inference with `batch_inference.py`

    main

    Use batch_inference.py to process multiple synthesis tasks from a CSV file.

    Arguments:

    • --csv_file: Path to the input CSV file.
    • --speaker_prompt_audio_folder: Folder containing the speaker prompt audio files.
    • --output_audio_folder: Folder where the generated .wav files will be saved.

    CSV File Structure: Your CSV must include these columns:

    • speaker_prompt_audio_filename: The filename (without extension) of the reference audio in the prompt folder.
    • speaker_prompt_text_transcription: (Optional) Transcription of the reference audio.
    • content_to_synthesize: The text to be synthesized.
    • output_audio_filename: The desired filename (without extension) for the output audio.
    python batch_inference.py \
      --csv_file ./data/batch_files.csv \
      --speaker_prompt_audio_folder ./data \
      --output_audio_folder ./results
  2. Export Matcha-TTS models to ONNX

    main

    You can export Matcha checkpoints to ONNX format for optimized inference.

    Requirements:

    • pip install onnx
    • torch>=2.1.0 (required for scaled_product_attention support during export).

    Export Command

    python3 -m matcha.onnx.export matcha.ckpt model.onnx --n-timesteps 5

    Options

    • --n-timesteps <int>: Specifies the number of timesteps (default is 5). This is a hyper-parameter fixed at export time.
    • --vocoder-name <name>: Optionally embed a vocoder in the graph.
    • --vocoder-checkpoint <path>: Optionally embed a specific vocoder checkpoint to enable end-to-end waveform generation.
    python3 -m matcha.onnx.export matcha.ckpt model.onnx --n-timesteps 5
  3. Fine-tune HiFi-GAN

    main

    Fine-tuning allows you to adapt the model to new data using mel-spectrograms generated by models like Tacotron2.

    Steps:

    1. Generate mel-spectrograms in .npy format using teacher-forcing. The filename must match the original audio filename (e.g., LJ001-0001.wav $\rightarrow$ LJ001-0001.npy).
    2. Create a directory named ft_dataset and copy all .npy files into it.
    3. Run the training script with the --fine_tuning flag set to True.
    python train.py --fine_tuning True --config config_v1.json
  4. Train Matcha-TTS with a custom dataset

    main

    To train Matcha-TTS on your own data (e.g., LJ Speech), follow these steps:

    1. Prepare Data: Extract your dataset and create filelists pointing to the audio and text files.

    2. Install from source: pip install -e . inside the repository.

    3. Configure Data: Update configs/data/ljspeech.yaml with your train_filelist_path and valid_filelist_path.

    4. Compute Statistics: Generate normalization statistics using the matcha-data-stats tool:

      matcha-data-stats -i ljspeech.yaml

      Update the data_statistics section in your .yaml config with the returned mel_mean and mel_std values.

    5. Run Training: Use the make command or the python script directly:

      • Standard: make train-ljspeech or python matcha/train.py experiment=ljspeech
      • Low Memory: python matcha/train.py experiment=ljspeech_min_memory
      • Multi-GPU: python matcha/train.py experiment=ljspeech trainer.devices=[0,1]
    6. Inference with custom model:

      matcha-tts --text "<TEXT>" --checkpoint_path <PATH_TO_CHECKPOINT>
  5. Run single audio inference with `single_inference.py`

    main

    Use single_inference.py to synthesize a single piece of text using a reference audio file to set the speaker's style.

    Important: Ensure UTF8 encoding is enabled by setting the environment variable export PYTHONUTF8=1 before running the script.

    Arguments:

    • --content_to_synthesize: The text to convert to speech. You can optionally include phonetic symbols (bopomofo) using the format [:symbols] for manual control (e.g., "今天天氣真好[:ㄏㄠ3]").
    • --speaker_prompt_audio_path: Path to the reference audio file (e.g., ./data/tc_speaker.wav).
    • --speaker_prompt_text_transcription (optional): The transcription of the reference audio. Providing this is highly recommended for accuracy; otherwise, the system uses Whisper to transcribe it automatically.
    • --output_path (optional): Path for the output .wav file. Defaults to results/output.wav.
    • --model_path (optional): Pre-trained model path. Defaults to MediaTek-Research/BreezyVoice.
    # Set UTF8 encoding
    export PYTHONUTF8=1
    
    # Example 1: Synthesis with transcription provided
    python single_inference.py \
      --content_to_synthesize "今天天氣真好" \
      --speaker_prompt_text_transcription "在密碼學中,加密是將明文資訊改變為難以讀取的密文內容..." \
      --speaker_prompt_audio_path "./data/example.wav"
    
    # Example 2: Synthesis with manual phonetic symbols
    python single_inference.py \
      --content_to_synthesize "今天天氣真好[:ㄏㄠ3]" \
      --speaker_prompt_audio_path "./data/example.wav"
  6. Run ONNX inference for Matcha-TTS

    main

    Once a model is exported to ONNX, you can run inference using onnxruntime.

    Setup

    • For CPU: pip install onnxruntime
    • For GPU: pip install onnxruntime-gpu

    Inference Command

    python3 -m matcha.onnx.infer model.onnx --text "hey" --output-dir ./outputs

    Parameters and Modes

    • GPU Acceleration: Add the --gpu flag to use onnxruntime-gpu.
    • Synthesis Control: Use --temperature <float>, --speaking_rate <float>, and --spk <int>.
    • Vocoder Integration:
      • If you exported only Matcha: The output will be mel-spectrograms (numpy arrays). To get audio, pass a vocoder path: --vocoder hifigan.small.onnx.
      • If you exported Matcha + Vocoder: The output will be .wav files directly.
    python3 -m matcha.onnx.infer model.onnx --text "hey" --output-dir ./outputs --gpu
  7. Inference from wav files

    main

    To perform mel-spectrogram inversion (converting existing audio/spectrograms back to waveforms):

    1. Create a test_files directory and copy your .wav files into it.
    2. Run inference.py pointing to your generator checkpoint.

    Options:

    • --checkpoint_file: Path to the generator checkpoint file.
    • --output_dir: Custom directory for generated files (defaults to generated_files).
    python inference.py --checkpoint_file [path_to_checkpoint]
  8. Inference for end-to-end speech synthesis

    main

    To generate audio directly from mel-spectrograms (e.g., from Tacotron2 or Glow-TTS):

    1. Create a test_mel_files directory and copy your generated mel-spectrogram files into it.
    2. Run inference_e2e.py pointing to your generator checkpoint.

    Options:

    • --checkpoint_file: Path to the generator checkpoint file.
    • --output_dir: Custom directory for generated files (defaults to generated_files_from_mel).
    python inference_e2e.py --checkpoint_file [path_to_checkpoint]
  9. Train HiFi-GAN

    main

    You can train the HiFi-GAN model using the train.py script. By default, it uses the V1 generator configuration. To train different versions (V2 or V3), swap the configuration file.

    Options:

    • --config: Path to the JSON configuration file (e.g., config_v1.json, config_v2.json, or config_v3.json).
    • --checkpoint_path: Custom path where checkpoints and configuration copies are saved (defaults to cp_hifigan).
    # Train V1 Generator
    python train.py --config config_v1.json
    
    # Train V2 Generator
    python train.py --config config_v2.json
  10. Install BreezyVoice

    main

    To install BreezyVoice, clone the repository and install the required Python dependencies. This project requires Python 3.10.

    Note on GPU/CPU: The model can run on CPU. If you do not have a GPU, you must change onnxruntime-gpu to onnxruntime in the requirements.txt file before installing. If you have a GPU, ensure you have cudnn installed matching your CUDA version (e.g., sudo apt-get -y install cudnn9-cuda-11).

    # Clone the repo
    git clone https://github.com/mtkresearch/BreezyVoice.git
    cd BreezyVoice
    
    # Install Requirements (requires Python3.10)
    # If using GPU, ensure onnxruntime-gpu is in requirements.txt
    pip uninstall onnxruntime
    pip install -r requirements.txt