Metadata-Version: 2.4
Name: tts-with-rvc
Version: 0.1.10
Summary: TTS with RVC pipeline
Author: Atm4x
License-Expression: MIT
Project-URL: Homepage, https://github.com/Atm4x/tts-with-rvc
Project-URL: Repository, https://github.com/Atm4x/tts-with-rvc
Project-URL: Bug Tracker, https://github.com/Atm4x/tts-with-rvc/issues
Keywords: tts,rvc,voice-conversion,speech-synthesis
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: <3.13,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: huggingface_hub
Requires-Dist: av
Requires-Dist: torch
Requires-Dist: edge-tts
Requires-Dist: numpy==1.26.0
Requires-Dist: librosa==0.9.1
Requires-Dist: faiss-cpu==1.10.0
Requires-Dist: soundfile>=0.12.1
Requires-Dist: ffmpeg-python>=0.2.0
Requires-Dist: praat-parselmouth>=0.4.2
Requires-Dist: resampy>=0.4.2
Requires-Dist: scikit-learn
Requires-Dist: tqdm>=4.63.1
Requires-Dist: audioread
Requires-Dist: pyworld==0.3.5
Requires-Dist: torchcrepe==0.0.20
Requires-Dist: numba==0.60.0
Requires-Dist: cffi<2.0.0
Requires-Dist: einops
Requires-Dist: local_attention
Requires-Dist: fairseq-built; sys_platform == "win32" and python_version >= "3.10" and python_version < "3.13"
Requires-Dist: fairseq-fixed; sys_platform != "win32" or python_version < "3.10" or python_version >= "3.13"
Dynamic: license-file

# **TTS-with-RVC** 0.1.10

***TTS-with-RVC** (Text-to-Speech with RVC)* is a package designed to enhance the capabilities of *text-to-speech (TTS)* systems by introducing a *RVC* module. The package enables users to not only convert text into speech but also personalize and customize the voice output according to their preferences with RVC support.

PyTorch is required. CUDA or MPS can accelerate inference; CPU is also supported.

**It may contain bugs. Report an issue in case of error.**

## Release notes

**0.1.10** - September 30, 2026: Added MultiGPU support: run independent instances on different GPUs in the same process. Separate model/runtime state per instance, explicit GPU selection, automatic precision, async usage with `generate_async()`, and resource cleanup with `close()` / context managers.

**0.1.9** - March 31, 2025: Some small fixes, fixed fairseq installation for linux.

**0.1.8** - March 30, 2025: Added all RVC parameters, implemented `FCPE` support, added PyPI installation support, fixed bug with rmvpe-only f0 method.

**0.1.6** - March 28, 2025: Updated all files with the latest RVC commit - 1.5-2x times faster inference. Reduced required packages. ONNX support [here](https://github.com/Atm4x/tts-with-rvc/tree/releases-onnx).

**0.1.5** - February 21, 2025: Removed all unnecessary packages, **Removed** `rvc_path`, Added `f0_method` for more control.

**0.1.4** - November 22, 2024: Added `index_path` and `index_rate` parameters for more control over index-based voice conversion.

**0.1.3** - fixed a lot problems, some optimization.

## Prerequisites

You must have **Python 3.10, 3.11 or 3.12** installed.

You must have **CUDA or MPS** support for your GPU (mps is not tested yet). Otherwise it will use CPU, which is very slow.

## **Installation**
1) Install pytorch **with CUDA or MPS support** here: https://pytorch.org/get-started/locally/

2) Then, install TTS-with-RVC using pip install:
```
pip install tts-with-rvc
```
3) And finally, install [ffmpeg](https://ffmpeg.org/download.html) if you don't already have one, and add it to the folder with your script **or better yet** add ffmpeg to the `Environment variables` in `Path`.

## How it Works
1. **Text-to-Speech (TTS):** Users enter text into the TTS module, which then processes it and generates the corresponding speech as a file saved in the temp directory
2. **RVC:** With .pth file provided, RVC module reads the generated audio file, processes it and generates an new audio saved in *output_directory* with voice replaced.

## Usage

TTS-with-RVC has a class called `TTS_RVC`. There are a few parameters that are required:

`model_path` - path to your .pth model

And optional parameters:

`voice` - voice from edge-tts list *(default is "ru-RU-DmitryNeural")*

`device` - set device ("cpu", "cuda:N", "mps"; with `None`, selects CUDA, then MPS, then CPU)

`tmp_directory` - path to TTS input directory (Temp directory for saving TTS output, default is Temp folder)

`output_directory` - directory for saving voiced audio (`temp/` is default).

`index_path` - path to the file index for voice model adjustments (default is empty string `""`).

`index_rate` - blending rate between original and indexed voice conversion (default is `0.75`).

`f0_method` - method for calculating the pitch of the audio (default is `rmvpe`). Available: 'rmvpe', 'fcpe' (fp32 only), 'pm', 'harvest', 'dio', 'crepe'.

Deprecated:

`input_directory` - path to TTS input directory (Temp directory for saving TTS output, default is None)



To set the voice, firstly, make instance of TTS_RVC:

```python
from tts_with_rvc import TTS_RVC

tts = TTS_RVC(model_path="models\\YourModel.pth",
                index_path="logs\\YourIndex.index",
                f0_method="rmvpe")
```


All voices available placed in `voices.txt` file:

Voice discovery is available as the async module-level function `get_voices()` from `tts_with_rvc`.

Next, set the voice for TTS with `tts.set_voice()` function:

```python
tts.set_voice("un-Un-SelectedNeural")
```

Setting the appropriate language is necessary if you are using other languages for voiceovers!

And final step is calling `tts` to replace voice:

```python
path = tts(text="Привет, мир!", pitch=6, index_rate=0.50)
```

Parameters:

`text` - text for TTS (required)

`pitch` - pitch change (transpose) for RVC in semitones (optional, neg. values are compatible, default is 0)

`tts_rate` - extra rate of speech for Edge TTS in percentage (+-) (optional, neg. values are compatible, default is 0)

`tts_volume` - extra volume of speech for Edge TTS in percentage (+-) (optional, neg. values are compatible, default is 0)

`tts_pitch` - extra pitch of TTS-generated audio in Hz (+-) (optional, neg. values are compatible, <b>not recommended</b>, default is 0)

`output_filename` - name for the output file (optional, default is `None`, a unique name is generated)

`index_rate` - blending rate between original and indexed voice conversion (0 to 1) (optional, default is `0.75`).

`is_half` - Precision override: `True` for FP16, `False` for FP32, or `None` for the instance's automatic precision policy. CPU FP16 is rejected.

`f0method` - F0 extraction method for this specific call, overrides the instance default: 'rmvpe', 'fcpe' (fp32 only), 'pm', 'harvest', 'dio', 'crepe'. (optional, default uses instance setting).

`file_index2` - Path to secondary index file for RVC. (optional, default is empty string `""`).

`filter_radius` - Median filter radius for pitch results. Values >=3 reduce breathiness. (optional, default is `3`).

`resample_sr` - Sample rate to resample audio to before RVC. 0 means no resampling. (optional, default is `0`).

`rms_mix_rate` - Volume envelope scaling (0-1). Lower values mimic original volume more closely. (optional, default is `0.5`).

`protect` - Protection for voiceless consonants and breaths (0-1). Lower values increase protection. 0.5 disables. (optional, default is `0.33`).

`verbose` - Enable verbose logging for RVC conversion. (optional, default is `False`).



## Example of usage
A simple example for voicing text:

```python
from tts_with_rvc import TTS_RVC
from playsound import playsound

tts = TTS_RVC(
    model_path="models\\DenVot13800.pth",
    index_path="logs\\added_IVF1749_Flat_nprobe_1.index"
)

tts.set_voice("ru-RU-DmitryNeural")
path = tts(text="Привет, мир!", pitch=6, index_rate=0.9)

# Normalize path for playsound if needed (example)
# path = path.replace("\\\\", "/").replace("\\","/")

playsound(path)
```
## New usage (0.1.10)

### MultiGPU

Create one instance per GPU. Each instance owns its model state; distribute requests between them in your application.

```python
from concurrent.futures import ThreadPoolExecutor
from tts_with_rvc import TTS_RVC

with TTS_RVC(
    model_path="models/voice.pth", device="cuda:0", output_directory="output/gpu0",
) as first, TTS_RVC(
    model_path="models/voice.pth", device="cuda:1", output_directory="output/gpu1",
) as second:
    with ThreadPoolExecutor(max_workers=2) as pool:
        jobs = [
            pool.submit(first, "First request."),
            pool.submit(second, "Second request."),
        ]
        output_paths = [job.result() for job in jobs]
        print(output_paths)
```

A bare `cuda` selects GPU zero. Use separate instances for parallel conversion; each converter serializes its own conversion calls.

### Async applications

```python
import asyncio
from tts_with_rvc import TTS_RVC

async def main():
    with TTS_RVC(model_path="models/voice.pth", device="cuda:0") as tts:
        path = await tts.generate_async("Hello, world!")
        print(path)

asyncio.run(main())
```

### Changing settings and releasing resources

`tts.set_model(path)` changes the RVC voice model. Use `tts.device = "cuda:1"` to change the device.
You can direct auxiliary model downloads to `models_dir` in the constructor.
A `with` block closes the instance automatically; otherwise call `tts.close()` when finished.

## Text parameters

There are some text parameters processor for integration issues such as adding GPT module.

You can process them using `process_args` in `TTS_RVC` class:

`--tts-rate (value)` - TTS parameter to edit the speech rate (negative value for decreasing rate and positive value for increasing rate)

`--tts-volume (value)` - TTS parameter to edit the speech volume (negative value for decreasing volume and positive value for increasing volume) <b>Seems to not work because of the RVC module conversion.</b>

`--tts-pitch (value)` - TTS parameter to edit the pitch of TTS generated audio (negative value for decreasing pitch and positive value for increasing pitch) <b>I do not recommend using this because the RVC module has its own `pitch` for output.</b>

`--rvc-pitch (value)` - RVC parameter to edit the pitch of the output audio (negative value for decreasing pitch and positive value for increasing pitch)

Now the principle of work:

```python
from tts_with_rvc import TTS_RVC

tts = TTS_RVC(model_path="models\\YourModel.pth")

# This method returns arguments and original text without these text parameters
args, message = tts.process_args(message)
```

The `args` variable contains an array with the following structure:

`args[0]` - TTS Rate

`args[1]` - TTS Volume

`args[2]` - TTS Pitch

`args[3]` - RVC pitch

And now we are ready to use it for generation:
```python
path = tts(message, tts_rate=args[0],
                    tts_volume=args[1],
                    tts_pitch=args[2],
                    pitch=args[3])
```

### Methods

`set_index_path(index_path)` - updates the path to the index file for voice model adjustments.

`voiceover_file(path, filename="converted.wav")` - converts existing audio without TTS.

`set_precision(None)` restores automatic precision; pass `False` to select FP32.


## Exceptions
1) `DeviceResolutionError`: the requested device is unavailable. Check the GPU index and your PyTorch installation.

2) RuntimeError:
```RuntimeError: Failed to load audio: {e}```

Be sure you installed `ffmpeg`.

## Acknowledgements
[RVC Project](https://github.com/RVC-Project/) - for RVC


## License
MIT License

## Authors
[Atm4x](https://github.com/Atm4x) (Artem Dikarev)
