音频流
音频流管线是一个播放音频片段的线程管线。该管线设计用于在本地机器上运行,因为它需要访问输出设备进行写入。
示例
以下展示了使用该管线的一个简单示例。
from txtai.pipeline import AudioStream
# Create and run pipeline
audio = AudioStream()
audio(data)
该管线可能需要额外的系统依赖。请参阅本节了解更多信息。
请参阅以下链接以获取更详细的示例。
Notebook | 描述 | |
---|---|---|
语音到语音 RAG ▶️ | 包含 RAG 的完整语音到语音工作流 |
配置驱动的示例
管线可以通过 Python 或配置运行。管线可以在配置中使用管线的全小写名称进行实例化。配置驱动的管线通过工作流或API运行。
config.yml
# Create pipeline using lower case class name
audiostream:
# Run pipeline with workflow
workflow:
audiostream:
tasks:
- action: audiostream
使用工作流运行
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("audiostream", [["numpy data", "sample rate"]]))
使用 API 运行
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"audiostream", "elements":[["numpy data", "sample rate"]]}'
方法
该管线的 Python 文档。
__init__(rate=None)
创建一个 AudioStream 管线。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
rate
|
可选的目标采样率,否则使用每个音频片段的输入目标采样率 |
None
|
源代码位于 txtai/pipeline/audio/audiostream.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
__call__(segment)
将音频片段排队给音频播放器。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
segment
|
(音频, 采样率)|列表 |
必需 |
返回
类型 | 描述 |
---|---|
segment |
源代码位于 txtai/pipeline/audio/audiostream.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|