By Hakim Engineering10 min read

Build a real-time Arabic voice agent with Pipecat

A working tutorial: assembling a Pipecat pipeline with HakimSTTService and HakimTTSService, handling interruptions and backchannel utterances, and wiring a Twilio inbound-call transport.

EngineeringProduct

Pipecat, Daily's open-source voice AI framework, reached v1.0 in April 2026 and has become the default choice for teams that want more control over their agent's pipeline than a fully-managed platform gives them. Instead of a single session object, Pipecat is a pipeline of frame processors you assemble yourself: transport in, STT, LLM, TTS, transport out, with aggregators and custom processors slotted in wherever your logic needs them. This is a working tutorial for a bilingual Arabic/English voice agent on Pipecat using Hakim's STT and TTS services.

Why Pipecat's model is different

LiveKit's AgentSession gives you a pre-built turn-taking loop; Pipecat gives you the pipeline primitives and expects you to compose them. The trade-off: more code up front, but you can insert custom processors anywhere in the chain: a profanity filter between STT and LLM, a response-length limiter between LLM and TTS, a call-recording tap after transport output, all without fighting a framework's opinions about how a turn should work. Teams that need tight video+voice coupling or non-standard pipeline shapes tend to land here.

What you're building

A Pipecat pipeline that:

  • Ingests audio from a WebRTC or telephony transport
  • Transcribes with HakimSTTService (dialect-aware Arabic + English)
  • Routes the transcript through an LLM service
  • Synthesizes the response with HakimTTSService
  • Ships back through the same transport, with the pipeline's built-in interruption handling stopping generation the moment the caller starts talking

Install

pip install pipecat-ai hakim-pipecat

hakim-pipecat (github.com/tryHakimAI/hakim-pipecat) exposes HakimSTTService and HakimTTSService, both implementing Pipecat's FrameProcessor interface so they slot into a Pipeline list like any other service.

The pipeline

import os
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineTask
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
from pipecat.services.openai import OpenAILLMService
from hakim_pipecat import HakimSTTService, HakimTTSService

async def run_agent(transport):
    stt = HakimSTTService(
        api_key=os.environ["HAKIM_API_KEY"],
        language="auto",  # code-switches between Arabic and English per utterance
    )
    tts = HakimTTSService(
        api_key=os.environ["HAKIM_API_KEY"],
        voice="hakim-preset-egyptian-female-1",
    )
    llm = OpenAILLMService(api_key=os.environ["OPENAI_API_KEY"], model="gpt-4o-mini")

    context = OpenAILLMContext(
        [{"role": "system", "content": "You are a helpful assistant. Reply in the caller's language."}]
    )
    user_aggregator = context.user_response_aggregator()
    assistant_aggregator = context.assistant_response_aggregator()

    pipeline = Pipeline([
        transport.input(),
        stt,
        user_aggregator,
        llm,
        tts,
        transport.output(),
        assistant_aggregator,
    ])

    task = PipelineTask(pipeline)
    runner = PipelineRunner()
    await runner.run(task)

This is the canonical Pipecat shape: audio frames flow left to right through STT, get aggregated into an LLM-ready context, generate a response, and flow through TTS back out. Nothing here is Hakim-specific except the two service classes.

Interruption handling

Pipecat's Pipeline propagates a UserStartedSpeakingFrame the moment STT detects the caller talking again. Any downstream processor with pending work (the LLM mid-generation, the TTS mid-synthesis) receives a cancellation and stops. HakimTTSService implements this by closing out the current audio frame cleanly and halting new frame generation, rather than finishing the in-flight sentence; the caller doesn't hear a truncated word mid-syllable, but they also don't hear the agent talk over them for another 500 ms while a queued response drains.

If you need custom interruption behavior (for example, letting short backchannel utterances like "mm-hmm" or "أيوة" pass through without triggering a full interruption), Pipecat exposes hooks on the aggregators to filter which STT-detected speech actually counts as a turn-taking event versus a passive acknowledgment. This matters more for Arabic than English: backchannel words are more frequent in Arabic conversational speech, and a naive interruption handler will cut the agent off on every "أيوة" or "تمام" the caller says while listening.

Function calling mid-conversation

Pipecat's LLM services support the same tool-calling interfaces as their underlying provider SDKs. A function call the LLM emits mid-pipeline pauses the TTS output, executes your handler, and feeds the result back into the context for the next LLM turn, useful for "let me check that" moments where the agent needs to hit an API (checking an order status, looking up a slot) before it can respond. We cover the pattern in more depth in a dedicated post on function calling in voice agents.

Telephony transports

Pipecat ships transport implementations for Daily, Twilio, and raw WebSocket, in addition to WebRTC. For an inbound support line, the Twilio transport handles the SIP-to-audio-frame conversion so the rest of the pipeline (STT, LLM, TTS) is identical to the WebRTC version above. You're only swapping the transport object, not rewriting the agent logic. This is a meaningful advantage if you're supporting both a web widget and an actual phone number with the same agent codebase.

Production checklist

  1. Pin language="auto" for any deployment where callers might code-switch; Hakim Arab v2 re-detects language per utterance rather than locking onto the first thing it heard.
  2. Tune the backchannel filter on your interruption handler before launch. Test with real Arabic speakers, not scripted English test calls, since backchannel frequency and phrasing differ meaningfully.
  3. Instrument end-to-end turn latency (caller stops talking → agent starts talking) as a single metric in addition to the per-service TTFB numbers; it's what a caller actually experiences.
  4. If your pipeline needs custom processors (recording, moderation, analytics), insert them as their own FrameProcessor rather than bolting logic onto the STT/TTS services; this keeps upgrades to hakim-pipecat painless.

The full example is in the hakim-pipecat repo under examples/, including a Twilio inbound-call variant. If you're still deciding between Pipecat and LiveKit for your next agent, see our framework comparison.

Read next