Skip to main content
ai-coustics enhances incoming audio inside Pipecat’s input transport. This example sends microphone audio through AICFilter and returns it to your headphones. It does not require a speech-to-text (STT), language model or text-to-speech provider.

Prerequisites

  • Use Python 3.11. The example targets pipecat-ai==1.11.0 and aic-sdk==3.1.0. Pipecat’s aic extra requires the SDK’s 3.1 series; do not force the 3.2 SDK used by the LiveKit example into this environment.
  • Get an SDK key. Create one on the developer platform and keep it on the server.
  • Use headphones and a microphone. Open the local client in a browser with microphone permission. Headphones prevent feedback from the loopback.
  • Allow model provisioning and SDK authentication. The first connection downloads model weights. See authentication and SDK telemetry for the separate network requirements.

Installation

Create a directory and choose one setup below. Run the remaining commands there. In bash and zsh, keep package extras quoted.
The runner extra installs the local web client, FastAPI and Uvicorn. The webrtc extra supplies the browser transport. This example does not need PyAudio or the local extra. On Windows, activate the environment with .venv\Scripts\Activate.ps1 in PowerShell instead of source .venv/bin/activate.

Usage

Save this complete file as bot.py:
bot.py

Running the example

Set the key in the same terminal and start the server:
Open http://localhost:7860, connect the client and allow microphone access. Speak, pause and speak again. The server creates a filter for each connection. Disconnect before restarting the server with Ctrl+C.

Check the result

Check all three signals:
  1. Initialization: verbose logs include ai-coustics filter started:, the selected model ID, sample rate and frames per chunk. AIC model initialization failed or ai-coustics filter is not ready. means enhancement did not activate.
  2. Audio flow: Loopback: frames=... samples=... rate=16000 channels=1 appears and its counts increase. You hear your microphone through the headphones. These counts confirm frame flow.
  3. Continued processing: keep the connection open and check for SDK authentication or processing errors. Disconnect, reconnect and confirm initialization again.
If processor construction fails, AICFilter logs the failure and passes incoming audio through unchanged. Audible loopback alone is not proof of enhancement. Model download or model loading failures can instead stop startup. Fix the error and reconnect before evaluating the result.
Quail is intended for machine listening. Compare STT results on representative recordings when evaluating it; naturalness to a human listener and transcription accuracy are different measures.

Recover from a failure

Architecture overview

AICFilter runs inside the input transport, before downstream processors. It converts mono signed 16-bit PCM to normalized float32 SDK blocks and returns signed 16-bit PCM. It buffers partial blocks, so a call can return no audio until a complete model block is available. Stopping the filter clears the remaining partial block and terminates its processing session.

AICFilter integration

At transport startup, the filter downloads or loads the model, creates ProcessorAsync for the transport sample rate and obtains a ProcessorContext for enhancement and bypass controls. It does not expose a VAD context. A process-wide model manager shares read-only enhancement weights; each filter has its own processing state. To use a provisioned model, replace model_id and model_download_dir in bot.py with model_path=Path("path/to/model.aicmodel"). Use the path returned by Model.download; filenames can include a content identifier. SDK authentication is still required.

Monitor SDK processing

Enable OpenTelemetry for Pipecat to send SDK processing and usage metrics to your collector. The guide covers shell and .env configuration, collector endpoints, containers and receipt checks.

Standalone ai-coustics VAD

AICQuailVADAnalyzer performs independent voice activity detection (VAD). In Pipecat 1.11.0 its default model ID is vad-2.1-xxs-16khz. Enhancement models cannot be used in its place. To test VAD with the loopback above, add these imports to bot.py:
Inside bot, replace the pipeline = Pipeline(...) block with:
Restart with -v and reconnect. As you speak and pause, look for AICQuailVADAnalyzer initialized, then User started speaking and User stopped speaking from VADProcessor. This loopback checks speech boundaries; it runs no LLM and cannot measure agent response latency.
With audio_in_filter=aic_filter, the VAD receives enhanced audio. The SDK VAD is intended for the original signal, and this combination also adds enhancement delay before VAD prediction. Pipecat 1.11.0 does not provide a pre-enhancement audio tap to this downstream analyzer. Evaluate missed speech, false starts and end-of-turn latency on your own recordings. For VAD on original audio, remove audio_in_filter=aic_filter from this example.
For an existing conversational pipeline, replace the loopback analyzer’s params argument with:
Pass that analyzer to LLMUserAggregatorParams(vad_analyzer=vad_analyzer) when creating LLMContextAggregatorPair. Let that aggregator own VAD instead of also adding VADProcessor. TransportParams.vad_analyzer was removed in Pipecat 1.0.
The loopback uses stop_secs=0.8. Pipecat 1.11.0’s conversational TurnAnalyzerUserTurnStopStrategy assumes stop_secs=0.2 in its built-in STT latency estimates. A stop delay at or above that estimate leaves no additional transcript wait time and can delay turn detection. For another delay, measure the 99th-percentile time from speech end to final transcript with your VAD/STT settings. Pass it in seconds as ttfs_p99_latency to the STT service constructor, such as DeepgramSTTService. Restart and reconnect the conversational pipeline to check timing warnings before measuring response latency. A custom estimate still produces the nondefault VAD warning; the loopback does not run these checks.
Tune Pipecat’s VADParams: confidence is the probability threshold, and start_secs and stop_secs govern speech timing. The SDK arguments sensitivity, speech_hold_duration and minimum_speech_duration have been accepted but ignored since Pipecat 1.5.0 and are scheduled for removal in 2.0.0.

Adapt this example

Continue with the Pipecat 1.11.0 conversational example, which connects Deepgram speech-to-text (STT), an OpenAI large language model (LLM) and Cartesia text-to-speech (TTS). Keep the pinned Pipecat version from this guide and add the deepgram, openai, cartesia and daily extras to the installation command above. This released example imports the Daily transport even when you select WebRTC, so it needs the daily extra; the WebRTC path does not need Daily credentials. The example reads AIC_SDK_LICENSE, DEEPGRAM_API_KEY, OPENAI_API_KEY and CARTESIA_API_KEY; configure any additional credentials required by your chosen transport. These are server-side environment variables. The example gives VAD ownership to LLMContextAggregatorPair through LLMUserAggregatorParams; do not also add the loopback’s VADProcessor. It applies enhancement before VAD, so review the original-audio and timing constraints above. It also writes conversation audio to local WAV files; review that recording behavior before using it with other people’s audio.
  • Evaluate changes one at a time. Keep the input recording, STT version and VAD settings fixed when comparing models or enhancement levels. Measure VAD timing separately from loopback delay.
  • Keep streams separate. Create a filter and VAD analyzer per concurrent stream. Let pipeline cancellation finish cleanup before reusing or discarding that session.
  • Upgrade deliberately. Preserve your environment lock and model IDs, then rerun initialization, speech/silence/noise, disconnect and reconnect checks after changing Pipecat or SDK versions. PipelineWorker and WorkerRunner replace the deprecated task/runner aliases used in older examples.

Further reading

After checking your pipeline, evaluate audio and agent behavior, then prepare your deployment. Use troubleshooting to diagnose setup and runtime failures.

Pipecat AICFilter

Read Pipecat’s filter documentation.

ai-coustics VAD

Understand VAD models and the distinction between SDK and Pipecat timing controls.