Integrations
Pipecat
Use Aniwaffle as the text-to-speech service in a Pipecat voice agent with a small TTSService adapter.
Overview
Pipecat handles transport, turn-taking, interruptions and playback. The adapter below sends each assistant reply to the streaming endpoint and returns raw PCM frames to the pipeline.
The adapter requests PCM, so no audio decoder sits in the realtime path, and checks that every chunk arrives in the format it asked for.
Install
bash
python -m pip install "pipecat-ai==1.4.0" "websockets>=15,<17"Set your API key and voice:
bash
export ANIWAFFLE_API_KEY="awp_..."
export ANIWAFFLE_VOICE_ID="YOUR_VOICE_ID"The adapter
aniwaffle_tts.py
import base64
import json
from collections.abc import AsyncGenerator
from pipecat.frames.frames import ErrorFrame, Frame, TTSAudioRawFrame, TTSStartedFrame, TTSStoppedFrame
from pipecat.services.settings import TTSSettings
from pipecat.services.tts_service import TTSService
from websockets.asyncio.client import connect
class AniwaffleTTSService(TTSService):
def __init__(self, *, api_key: str, voice_id: str, sample_rate: int = 48000,
url: str = "wss://aniwaffle.com/v1/tts/stream", **kwargs) -> None:
super().__init__(
sample_rate=sample_rate,
settings=TTSSettings(model="aniwaffle", voice=voice_id, language=None),
**kwargs,
)
self.url = url
self.api_key = api_key
self.voice_id = voice_id
self.output_format = f"pcm_{sample_rate}"
async def run_tts(self, text: str, context_id: str) -> AsyncGenerator[Frame | None, None]:
yield TTSStartedFrame()
try:
async with connect(
self.url,
additional_headers={"Authorization": f"Bearer {self.api_key}"},
open_timeout=10,
max_size=None,
) as websocket:
await websocket.send(json.dumps({
"event": "start",
"request": {
"context_id": context_id,
"voice_id": self.voice_id,
"output_format": self.output_format,
},
}))
await websocket.send(json.dumps({"event": "text", "text": text}))
await websocket.send(json.dumps({"event": "stop"}))
async for message in websocket:
event = json.loads(message)
if event["event"] == "audio":
if event["format"] != self.output_format:
raise ValueError(f"Expected {self.output_format}, got {event['format']}")
yield TTSAudioRawFrame(
audio=base64.b64decode(event["audio"]),
sample_rate=self.sample_rate,
num_channels=1,
context_id=context_id,
)
elif event["event"] == "error":
yield ErrorFrame(error=f"aniwaffle_tts_error:{event['code']}")
break
elif event["event"] == "finish":
break
except Exception as error:
yield ErrorFrame(error=f"aniwaffle_tts_transport_error:{error}")
yield TTSStoppedFrame()Add it to a pipeline
Set the pipeline's output sample rate to the rate you request from Aniwaffle.
bot.py
import os
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.worker import PipelineParams, PipelineWorker
from aniwaffle_tts import AniwaffleTTSService
# transport, stt, llm and context_aggregator come from your existing bot.
tts = AniwaffleTTSService(
api_key=os.environ["ANIWAFFLE_API_KEY"],
voice_id=os.environ["ANIWAFFLE_VOICE_ID"],
sample_rate=48000,
)
pipeline = Pipeline([
transport.input(), stt, context_aggregator.user(), llm,
tts, transport.output(), context_aggregator.assistant(),
])
worker = PipelineWorker(
pipeline,
params=PipelineParams(
audio_in_sample_rate=16000,
audio_out_sample_rate=48000,
enable_metrics=True,
),
)Notes
- Sample rate.
sample_ratecan be 24000, 44100 or 48000. It must matchaudio_out_sample_rate. - Mono only. The adapter emits one channel. Use Waffle Mono, the default model, with Pipecat.
- Lower latency. Point
urlatwss://jp.aniwaffle.com/v1/tts/streamand add"realtime": Trueto the start request to use the realtime tier. - Key safety. The API key stays in the bot process. Never forward it to the browser transport or the RTVI client.