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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|