一键导入
local-onnx-pipeline
Patterns for building local ONNX inference pipelines with async streaming and TTS integration
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Patterns for building local ONNX inference pipelines with async streaming and TTS integration
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
{what this skill teaches agents}
{what this skill teaches agents}
Expert guidance for implementing OpenAI gpt-realtime-1.5, including WebRTC, WebSocket, and SIP configurations.
基于 SOC 职业分类
| name | local-onnx-pipeline |
| description | Patterns for building local ONNX inference pipelines with async streaming and TTS integration |
| domain | ai-inference |
| confidence | high |
| source | earned — Phase 2 Phi-4 ONNX + Piper TTS implementation |
When building local/offline AI inference pipelines using ONNX models with text-to-speech output, these patterns ensure non-blocking async operation, proper audio format handling, and graceful degradation.
ONNX inference is synchronous. Bridge to async generators via asyncio.Queue:
queue: asyncio.Queue[str | None] = asyncio.Queue()
def _run_inference():
# Sync ONNX generation loop
while not generator.is_done():
generator.generate_next_token()
token = tokenizer.decode(generator.get_last_tokens(1))
loop.call_soon_threadsafe(queue.put_nowait, token)
loop.call_soon_threadsafe(queue.put_nowait, None) # sentinel
asyncio.get_event_loop().run_in_executor(None, _run_inference)
while True:
token = await queue.get()
if token is None: break
yield token
Try GPU-specific packages in order:
onnxruntime_genai_cuda (NVIDIA)onnxruntime_genai_directml (Windows GPU)onnxruntime_genai (CPU fallback)np.interpSplit text at sentence boundaries before synthesis for lower first-audio latency.
Use asyncio.Lock to prevent overlapping inference on the same model instance.
When a cloud/local routing layer exists, always check cloud reachability before routing to cloud when a local alternative is available:
async def _check_cloud_reachable(self) -> bool:
try:
timeout = aiohttp.ClientTimeout(total=3, connect=2)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(endpoint, ssl=True):
return True
except Exception:
return False
Keep the timeout short (2-3s) so the fallback is fast.
Use a dedicated logger name (e.g., local-pipeline) across all modules in the pipeline. Log every step with session IDs and timing: