index-tts-lora

repository·main·Indexed 43 days ago

https://github.com/asr-pub/index-tts-lora

A fine-tuning framework for Bilibili's index-tts that uses LoRA to enable high-quality, natural-sounding speech synthesis for single or multiple speakers. It includes tools for extracting audio codec tokens and speaker conditions, a training script, and a CLI for text-to-speech synthesis using voice prompts.

Tokens
1.3K
Snippets
6
Records
9
Agent score
56%

What's inside index-tts-lora

  1. Extract audio tokens and speaker conditions

    main

    Before training, you must extract audio codec tokens and speaker conditions from your dataset.

    Input Format: The ${audio_list} file must follow a specific format where each line contains an audio file path and its corresponding transcript, separated by a tab (\t):

    /path/to/audio.wav The transcript text goes here.

    Command: Run the extract_codec.py tool with the --extract_condition flag.

    Output: Processed files and a speaker_info.json file will be generated in the finetune_data/processed_data/ directory. The speaker_info.json contains metadata for each speaker, including avg_duration, sample_num, total_duration_in_seconds, and paths to train_jsonl, valid_jsonl, and medoid_condition.npy files.

    # Extract tokens and speaker conditions
    python tools/extract_codec.py --audio_list ${audio_list} --extract_condition
  2. Configure device and precision in IndexTTS CLI

    main

    The CLI automatically selects the best available hardware if no device is specified:

    1. CUDA: If torch.cuda.is_available() is true, it uses cuda:0.
    2. MPS: If torch.mps.is_available() is true, it uses mps.
    3. CPU: Defaults to cpu and automatically disables --fp16 (as FP16 is not supported for CPU inference in this context).

    You can manually override this using the -d or --device flag.

    Example: Force CPU usage

    python indextts/cli.py "text" -v prompt.wav -d cpu
  3. Reference: speaker_info.json schema

    main

    The speaker_info.json file generated after extraction follows this structure for each speaker entry:

    [
        {
            "speaker": "kaishu_30min",
            "avg_duration": 6.6729,
            "sample_num": 270,
            "total_duration_in_seconds": 1801.696,
            "total_duration_in_minutes": 30.028,
            "total_duration_in_hours": 0.500,
            "train_jsonl": "/path/to/kaishu_30min/metadata_train.jsonl",
            "valid_jsonl": "/path/to/kaishu_30min/metadata_valid.jsonl",
            "medoid_condition": "/path/to/kaishu_30min/medoid_condition.npy"
        }
    ]
  4. Reference IndexTTS CLI arguments and flags

    main

    The IndexTTS CLI supports the following arguments for controlling output, configuration, and hardware acceleration:

    ArgumentShortDefaultDescription
    textN/AN/A(Required) The text to be synthesized
    --voice-vRequiredPath to the audio prompt file (wav format)
    --output_path-ogen.wavPath to the output wav file
    --config-ccheckpoints/config.yamlPath to the config file
    --model_dir--model_dircheckpointsPath to the model directory
    --fp16--fp16TrueUse FP16 for inference if available
    --force-fFalseForce to overwrite the output file if it exists
    --device-dNoneDevice to run the model on (cpu, cuda, mps)
  5. Use the IndexTTS CLI for text-to-speech synthesis

    main

    The indextts/cli.py script provides a command-line interface to perform text-to-speech synthesis using a LoRA-based model. You must provide the text to synthesize and a path to a .wav audio prompt file that serves as the voice reference.

    Basic Usage:

    python indextts/cli.py "Your text here" -v path/to/voice_prompt.wav

    Key Requirements:

    • Text: A positional argument containing the string you want to synthesize.
    • Voice Prompt: A required -v or --voice argument pointing to a .wav file.
    • PyTorch: The CLI requires torch to be installed to handle device placement and inference.
    python indextts/cli.py "Hello world" -v prompt.wav