MikhbarMIKHBAR
Artificial Intelligence

Stream Low-Latency Speech With Kokoro TTS on Amazon SageMaker AI

A new architectural approach helps AI voice agents reduce perceived latency by streaming sentence-level text to a compact speech synthesis model on Amazon SageMaker AI.

Stream Low-Latency Speech With Kokoro TTS on Amazon SageMaker AI

Addressing Voice Agent Latency

Voice-enabled artificial intelligence agents frequently introduce frustrating delays for users. When a customer asks a question, the underlying model may begin generating a long, multi-paragraph response. Traditional text-to-speech integrations wait for the entire text generation cycle to finish before triggering speech synthesis. This creates a noticeable silence that can last several seconds before the user hears any audio response.

To close this gap, developers can stream individual sentences to a hosted text-to-speech model as soon as the agent produces them. By initiating synthesis on the first sentence rather than waiting for the complete response, audio playback begins much faster. Detailed implementation strategies and architectural overviews are outlined in the AWS Machine Learning Blog.

Client connects to an Amazon SageMaker AI real-time endpoint on ml.g5.xlarge over InvokeEndpointWithBidirectionalStream. A Starlette ASGI app exposing GET /ping, POST /invocations, and WS /invocations-bidirectional-strea
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Deploying the Kokoro-82M Model

The core of this low-latency streaming approach relies on the Kokoro-82M text-to-speech model. Because Kokoro-82M holds only 82 million parameters, it is lightweight enough to run economically on a single mid-tier GPU instance. This compact footprint helps keep both inference costs and operational latency low, making it practical for voice agents handling real production traffic.

Deploying the model involves setting up a custom container on an Amazon SageMaker AI real-time endpoint, specifically running on an ml.g5.xlarge GPU instance. Teams can leverage the AWS Cloud Development Kit (AWS CDK) v2 to provision the foundational architecture, model caches, and IAM roles required for the endpoint infrastructure.

One bidirectional session sending two sentences, each followed by synthesis_start, PCM audio, and synthesis_complete frames, ending with an explicit close message.
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Container Routes and Bidirectional Streaming

The custom container exposes two primary routes to handle incoming requests and audio streams. The first route, POST /invocations, streams a response for one complete input string. The second route, WS /invocations-bidirectional-stream, maintains an open connection across multiple messages moving in both directions simultaneously.

Using Amazon SageMaker AI real-time inference documentation, developers can properly configure bidirectional streaming capabilities. The architecture relies on recognizing binary WebSocket frames correctly and keeping persistent sessions open between messages to avoid the overhead of constant reconnections.

Caller sends a request to an agent container built with BedrockAgentCoreApp over leg 1, POST /invocations, SSE-shaped with base64 audio. The container calls Amazon Bedrock over leg 2, a streaming converse call for text d
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Prerequisites and Tooling Setup

Building and deploying the necessary container images requires a specific development environment. Developers need Python 3.12 or later, Docker, and uv to manage package installations and build the container image efficiently.

Additionally, the setup integrates with Amazon Bedrock AgentCore capabilities to manage the underlying agent runtime. Further architectural guidance can be found by consulting the Amazon Bedrock AgentCore documentation alongside resources available on the official GitHub repository.

Bar chart comparing relative time to first audio for batch and bidi modes, locally and on a deployed Amazon Bedrock AgentCore runtime. Batch is normalized to 1.0x. Local bidi measures 0.42x (2.4 times faster). Deployed b
Image related to the report from AWS Machine Learning Blog · Source: AWS Machine Learning Blog

Sources

Continue chronologically

Related entity coverage