Text To Speech
The Text To Speech pipeline generates speech from text.
Example
The following shows a simple example using this pipeline.
from txtai.pipeline import TextToSpeech
# Create and run pipeline
tts = TextToSpeech()
tts("Say something here")
See the link below for a more detailed example.
Notebook | Description | |
---|---|---|
Text to speech generation | Generate speech from text |
This pipeline is backed by ONNX models from the Hugging Face Hub. The following models are currently available.
Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in configuration using the lower case name of the pipeline. Configuration-driven pipelines are run with workflows or the API.
config.yml
# Create pipeline using lower case class name
texttospeech:
# Run pipeline with workflow
workflow:
tts:
tasks:
- action: texttospeech
Run with Workflows
from txtai.app import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("tts", ["Say something here"]))
Run with API
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"tts", "elements":["Say something here"]}'
Methods
Python documentation for the pipeline.
Creates a new TextToSpeech pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | optional Hugging Face model hub id | None | |
maxtokens | maximum number of tokens model can process, defaults to 512 | 512 |
Source code in txtai/pipeline/audio/texttospeech.py
|
|
Generates speech from text. Text longer than maxtokens will be batched and returned as a single waveform per text input.
This method supports files as a string or a list. If the input is a string, the return type is string. If text is a list, the return type is a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | text|list | required |
Returns:
Type | Description |
---|---|
list of speech as NumPy array waveforms |
Source code in txtai/pipeline/audio/texttospeech.py
|
|