文本转音频
文本转音频流水线从文本生成音频。
示例
以下展示了使用此流水线的一个简单示例。
from txtai.pipeline import TextToAudio
# Create and run pipeline
tta = TextToAudio()
tta("Describe the audio to generate here")
有关更详细的示例,请参阅下方链接。
笔记本 | 描述 | |
---|---|---|
生成式音频 | 使用生成式音频工作流讲故事 |
配置驱动的示例
流水线可以使用 Python 或配置运行。流水线可以在 配置 中使用流水线的全小写名称实例化。配置驱动的流水线可以使用 工作流 或 API 运行。
config.yml
# Create pipeline using lower case class name
texttoaudio:
# Run pipeline with workflow
workflow:
tta:
tasks:
- action: texttoaudio
使用工作流运行
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("tta", ["Describe the audio to generate here"]))
使用 API 运行
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"tta", "elements":["Describe the audio to generate here"]}'
方法
流水线的 Python 文档。
__init__(path=None, quantize=False, gpu=True, model=None, rate=None, **kwargs)
源代码位于 txtai/pipeline/audio/texttoaudio.py
14 15 16 17 18 19 20 21 22 |
|
__call__(text, maxlength=512)
从文本生成音频。
此方法支持文本为字符串或列表。如果输入是字符串,则返回类型为单个音频输出。如果文本是列表,则返回类型是列表。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
text
|
text|list |
必需 | |
maxlength
|
生成音频的最大长度 |
512
|
返回值
类型 | 描述 |
---|---|
列表 (音频, 采样率) |
源代码位于 txtai/pipeline/audio/texttoaudio.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|