Constructing pure conversational experiences requires speech synthesis that retains tempo with real-time interactions. At the moment, we’re excited to announce the brand new Bidirectional Streaming API for Amazon Polly, enabling streamlined real-time text-to-speech (TTS) synthesis the place you can begin sending textual content and receiving audio concurrently.
This new API is constructed for conversational AI functions that generate textual content or audio incrementally, like responses from giant language fashions (LLMs), the place customers should start synthesizing audio earlier than the total textual content is on the market. Amazon Polly already helps streaming synthesized audio again to customers. The brand new API goes additional specializing in bidirectional communication over HTTP/2, permitting for enhanced velocity, decrease latency, and streamlined utilization.
The problem with conventional text-to-speech
Conventional text-to-speech APIs comply with a request-response sample. This required you to gather the whole textual content earlier than making a synthesis request. Amazon Polly streams audio again incrementally after a request is made, however the bottleneck is on the enter facet—you may’t start sending textual content till it’s totally obtainable. In conversational functions powered by LLMs, the place textual content is generated token by token, this implies ready for the whole response earlier than synthesis begins.
Think about a digital assistant powered by an LLM. The mannequin generates tokens incrementally over a number of seconds. With conventional TTS, customers should look ahead to:
- The LLM to complete producing the whole response
- The TTS service to synthesize the whole textual content
- The audio to obtain earlier than playback begins
The brand new Amazon Polly bidirectional streaming API is designed to handle these bottlenecks.
What’s new: Bidirectional Streaming
The StartSpeechSynthesisStream API introduces a basically totally different method:
- Ship textual content incrementally: Stream textual content to Amazon Polly because it turns into obtainable—no want to attend for full sentences or paragraphs.
- Obtain audio instantly: Get synthesized audio bytes again in real-time as they’re generated.
- Management synthesis timing: Use flush configuration to set off rapid synthesis of buffered textual content.
- True duplex communication: Ship and obtain concurrently over a single connection.
Key Parts
Element
Occasion Course
Course
Objective
TextEvent
Inbound
Consumer → Amazon Polly
Ship textual content to be synthesized
CloseStreamEvent
Inbound
Consumer → Amazon Polly
Sign finish of textual content enter
AudioEvent
Outbound
Amazon Polly → Consumer
Obtain synthesized audio chunks
StreamClosedEvent
Outbound
Amazon Polly → Consumer
Affirmation of stream completion
Comparability to conventional strategies
Conventional file separation implementations
Beforehand, attaining low-latency TTS required application-level implementations:
This method required:
- Server-side textual content separation logic
- A number of parallel Amazon Polly API calls
- Complicated audio reassembly
After: Native Bidirectional Streaming
Advantages:
- No separation logic required
- Single persistent connection
- Native streaming in each instructions
- Diminished infrastructure complexity
- Decrease latency
Efficiency benchmarks
To measure the real-world impression, we benchmarked each the standard SynthesizeSpeech API and the brand new bidirectional StartSpeechSynthesisStream API towards the identical enter: 7,045 characters of prose (970 phrases), utilizing the Matthew voice with the Generative engine, MP3 output at 24kHz in us-west-2.
How we measured: Each checks simulate an LLM producing tokens at ~30 ms per phrase. The normal API take a look at buffers phrases till a sentence boundary is reached, then sends the whole sentence as a SynthesizeSpeech request and waits for the total audio response earlier than persevering with. These checks mirror how conventional TTS integrations work, since you will need to have the whole sentence earlier than requesting synthesis. The bidirectional streaming API take a look at sends every phrase to the stream because it arrives, permitting Amazon Polly to start synthesis earlier than the total textual content is on the market. Each checks use the identical textual content, voice, and output configuration.
Metric
Conventional SynthesizeSpeech
Bidirectional Streaming
Enchancment
Complete processing time
115,226 ms (~115s)
70,071 ms (~70s)
39% sooner
API calls
27
1
27x fewer
Sentences despatched
27 (sequential)
27 (streamed as phrases arrive)
—
Complete audio bytes
2,354,292
2,324,636
—
The important thing benefit is architectural: the bidirectional API permits sending enter textual content and receiving synthesized audio concurrently over a single connection. As an alternative of ready for every sentence to build up earlier than requesting synthesis, textual content is streamed to Amazon Polly word-by-word because the LLM produces it. For conversational AI, which means Amazon Polly receives and processes textual content incrementally all through technology, moderately than receiving it abruptly after the LLM finishes. The result’s much less time ready for synthesis after technology completes—the general end-to-end latency from immediate to completely delivered audio is considerably diminished.
Technical implementation
Getting began
You need to use the bidirectional streaming API with AWS SDK for Java-2x, JavaScript v3, .NET v4, C++, Go v2, Kotlin, PHP v3, Ruby v3, Rust, and Swift. Help for CLIs (AWS Command Line Interface (AWS CLI) v1 and v2, PowerShell v4 and v5), Python, .NET v3 usually are not at the moment supported. Right here’s an instance:
// Create the async Polly consumer
PollyAsyncClient pollyClient = PollyAsyncClient.builder()
.area(Area.US_WEST_2)
.credentialsProvider(DefaultCredentialsProvider.create())
.construct();
// Create the stream request
StartSpeechSynthesisStreamRequest request = StartSpeechSynthesisStreamRequest.builder()
.voiceId(VoiceId.JOANNA)
.engine(Engine.GENERATIVE)
.outputFormat(OutputFormat.MP3)
.sampleRate(“24000”)
.construct();
Sending textual content occasions
Textual content is distributed to Amazon Polly utilizing a reactive streams Writer. Every TextEvent comprises textual content:
TextEvent textEvent = TextEvent.builder() .textual content(“Hey, that is streaming text-to-speech!”) .construct();
Dealing with audio occasions
Audio arrives via a response handler with a customer sample:
StartSpeechSynthesisStreamResponseHandler responseHandler =
StartSpeechSynthesisStreamResponseHandler.builder()
.onResponse(response -> System.out.println(“Stream related”))
.onError(error -> handleError(error))
.subscriber(StartSpeechSynthesisStreamResponseHandler.Customer.builder()
.onAudioEvent(audioEvent -> token.endsWith(“!”) )
.onStreamClosedEvent(occasion -> )
.construct())
.construct();
Full instance: streaming textual content from an LLM
Right here’s a sensible instance exhibiting tips on how to combine bidirectional streaming with incremental textual content technology:
public class LLMIntegrationExample {
non-public ultimate PollyAsyncClient pollyClient;
non-public Subscriber tremendous StartSpeechSynthesisStreamActionStream> textSubscriber;
/**
* Begin a bidirectional stream and return a deal with for sending textual content.
*/
public CompletableFuture startStream(VoiceId voice, AudioConsumer audioConsumer) {
StartSpeechSynthesisStreamRequest request = StartSpeechSynthesisStreamRequest.builder()
.voiceId(voice)
.engine(Engine.GENERATIVE)
.outputFormat(OutputFormat.PCM)
.sampleRate(“16000”)
.construct();
// Writer that permits exterior textual content injection
Writer textPublisher = subscriber -> {
this.textSubscriber = subscriber;
subscriber.onSubscribe(new Subscription() {
@Override
public void request(lengthy n)
// Ship every token to Polly
//Optionally Flush at sentence boundaries to pressure synthesis
//observe the tradeoff right here: you could get the audio sooner, however audio high quality could also be impacted
boolean isSentenceEnd = token.endsWith(“.”)
@Override
public void cancel() token.endsWith(“!”)
});
};
StartSpeechSynthesisStreamResponseHandler handler =
StartSpeechSynthesisStreamResponseHandler.builder()
.subscriber(StartSpeechSynthesisStreamResponseHandler.Customer.builder()
.onAudioEvent(occasion -> {
if (occasion.audioChunk() != null) {
audioConsumer.settle for(occasion.audioChunk().asByteArray());
}
})
.onStreamClosedEvent(occasion -> audioConsumer.full())
.construct())
.construct();
return pollyClient.startSpeechSynthesisStream(request, textPublisher, handler);
}
/**
* Ship textual content file to the stream. Name this as LLM tokens arrive.
*/
public void sendText(String textual content, boolean flush) {
if (textSubscriber != null) {
TextEvent occasion = TextEvent.builder()
.textual content(textual content)
.flushStreamConfiguration(FlushStreamConfiguration.builder()
.pressure(flush)
.construct())
.construct();
textSubscriber.onNext(occasion);
}
}
/**
* Shut the stream when textual content technology is full.
*/
public void closeStream() {
if (textSubscriber != null) {
textSubscriber.onNext(CloseStreamEvent.builder().construct());
textSubscriber.onComplete();
}
}
}
Integration sample with LLM streaming
The next reveals tips on how to combine patterns with LLM streaming:
// Begin the Polly stream
pollyStreamer.startStream(VoiceId.JOANNA, audioPlayer::playChunk);// As LLM generates tokens…
llmClient.streamCompletion(immediate, token -> token.endsWith(“!”) );
// When LLM completes
pollyStreamer.closeStream();
Enterprise advantages
Improved consumer expertise
Latency straight impacts consumer satisfaction. The sooner customers hear a response, the extra pure and fascinating the interplay feels. The bidirectional streaming API allows:
- Diminished perceived wait time – Audio playback begins whereas the LLM continues to be producing, masking backend processing time.
- Greater engagement – Quicker, extra responsive interactions result in elevated consumer retention and satisfaction.
- Streamlined implementation – The setup and administration of the streaming resolution is now a single API name with clear hooks and callbacks to take away the complexity.
Diminished operational prices
Streamlining your structure interprets on to price financial savings:
Price issue
Conventional chunking
Bidirectional Streaming
Infrastructure
WebSocket servers, load balancers, chunking middleware
Direct client-to-Amazon Polly connection
Growth
Customized chunking logic, audio reassembly, error dealing with
SDK handles complexity
Upkeep
A number of elements to observe and replace
Single integration level
API Calls
A number of calls per request (one per chunk)
Single streaming session
Organizations can count on to cut back infrastructure prices by eradicating intermediate servers and reduce improvement time through the use of native streaming functionality.
Use circumstances
The bidirectional streaming API is really useful for:
- Conversational AI Assistants – Stream LLM responses on to speech
- Actual-time Translation – Synthesize translated textual content because it’s generated
- Interactive Voice Response (IVR) – Dynamic, responsive cellphone programs
- Accessibility Instruments – Actual-time display readers and text-to-speech
- Gaming – Dynamic NPC dialogue and narration
- Reside Captioning – Audio output for stay transcription programs
Conclusion
The brand new Bidirectional Streaming API for Amazon Polly represents a major development in real-time speech synthesis. By enabling true streaming in each instructions, it removes latency bottlenecks which have historically plagued conversational AI functions.
Key takeaways:
- Diminished latency – Audio begins enjoying whereas textual content continues to be being generated
- Simplified structure – No want for file separation workarounds or advanced infrastructure
- Native LLM integration – Objective-built for streaming textual content from language fashions
- Versatile management – Wonderful-grained management over synthesis timing with flush configuration
Whether or not you’re constructing a digital assistant, accessibility software, or any utility requiring responsive text-to-speech, the bidirectional streaming API gives the muse for really conversational experiences.
Subsequent steps
The bidirectional streaming API is now Typically Obtainable. To get began:
- Replace to the most recent AWS SDK for Java 2.x with bidirectional streaming help
- Overview the API documentation for detailed reference
- Attempt the instance code on this publish to expertise the low-latency streaming
We’re excited to see what you construct with this new functionality. Share your suggestions and use circumstances with us!
In regards to the authors
“Scott Mishra”
“Scott” is Sr. Options Architect for Amazon Net Providers. Scott is a trusted technical advisor serving to enterprise prospects architect and implement cloud options at scale. He drives buyer success via technical management, architectural steerage, and modern problem-solving whereas working with cutting-edge cloud applied sciences. Scott makes a speciality of generative AI options.
“Praveen Gadi”
“Praveen” is a Sr. Options Architect for Amazon Net Providers. Praveen is a trusted technical advisor to enterprise prospects. He allows prospects to attain their enterprise targets and maximize their cloud investments. Praveen makes a speciality of integration options and developer productiveness.
“Paul Wu”
“Paul” is a Options Architect for Amazon Net Providers. Paul is a trusted technical advisor to enterprise prospects. He allows prospects to attain their enterprise targets and maximize their cloud investments
“Damian Pukaluk”
“Damian” is a Software program Growth Engineer at AWS Polly.

