mirror of
https://github.com/wassname/TTS.git
synced 2026-09-09 11:16:00 +08:00
Python API implementation (#2195)
* Draft implementation * Fix style * Add api tests * Fix lint * Update docs * Update tests * Set env * Fixup * Fixup * Fix lint * Revert
This commit is contained in:
@@ -11,6 +11,7 @@ After the installation, 2 terminal commands are available.
|
||||
|
||||
1. TTS Command Line Interface (CLI). - `tts`
|
||||
2. Local Demo Server. - `tts-server`
|
||||
3. In 🐍Python. - `from TTS.api import TTS`
|
||||
|
||||
## On the Commandline - `tts`
|
||||

|
||||
@@ -99,5 +100,30 @@ tts-server --model_name "<type>/<language>/<dataset>/<model_name>" \
|
||||
--vocoder_name "<type>/<language>/<dataset>/<model_name>"
|
||||
```
|
||||
|
||||
## TorchHub
|
||||
You can also use [this simple colab notebook](https://colab.research.google.com/drive/1iAe7ZdxjUIuN6V4ooaCt0fACEGKEn7HW?usp=sharing) using TorchHub to synthesize speech.
|
||||
## Python API
|
||||
|
||||
You can run a multi-speaker and multi-lingual model in Python as
|
||||
|
||||
```python
|
||||
from TTS.api import TTS
|
||||
|
||||
# List available 🐸TTS models and choose the first one
|
||||
model_name = TTS.list_models()[0]
|
||||
# Init TTS
|
||||
tts = TTS(model_name)
|
||||
# Run TTS
|
||||
# ❗ Since this model is multi-speaker and multi-lingual, we must set the target speaker and the language
|
||||
# Text to speech with a numpy output
|
||||
wav = tts.tts("This is a test! This is also a test!!", speaker=tts.speakers[0], language=tts.languages[0])
|
||||
# Text to speech to a file
|
||||
tts.tts_to_file(text="Hello world!", speaker=tts.speakers[0], language=tts.languages[0], file_path="output.wav")
|
||||
```
|
||||
|
||||
Here is an example for a single speaker model.
|
||||
|
||||
```python
|
||||
# Init TTS with the target model name
|
||||
tts = TTS(model_name="tts_models/de/thorsten/tacotron2-DDC", progress_bar=False, gpu=False)
|
||||
# Run TTS
|
||||
tts.tts_to_file(text="Ich bin eine Testnachricht.", file_path=OUTPUT_PATH)
|
||||
```
|
||||
Reference in New Issue
Block a user