Code examples - Amazon Nova

Code examples

These code examples help you quickly get started with Amazon Nova 2 Sonic. You can access the complete list of examples in the Amazon Nova Sonic GitHub samples page.

Getting started examples

For simple examples designed to get you started using Amazon Nova 2 Sonic, refer to the following implementations:

  • Basic Amazon Nova 2 Sonic implementation (Python): A basic implementation that demonstrates how events are structured in the bidirectional streaming API. This version does not support barge-in functionality (interrupting the assistant while it is speaking) and does not implement true bidirectional communication.

  • Full featured Amazon Nova 2 Sonic implementation (Python): The full-featured implementation with real bidirectional communication and barge-in support. This allows for more natural conversations where users can interrupt the assistant while it is speaking, similar to human conversations.

  • Amazon Nova 2 Sonic with tool use (Python): An advanced implementation that extends the bidirectional communication capabilities with tool use examples. This version demonstrates how Amazon Nova 2 Sonic can interact with external tools and APIs to provide enhanced functionality.

  • Nova Sonic with text and mixed Input (Python): Example implementation to showcase how Amazon Nova 2 Sonic can have text as an input.

  • Java WebSocket implementation (Java): This example implements a bidirectional WebSocket-based audio streaming application that integrates with Amazon Nova 2 Sonic for real-time speech-to-speech conversation using Java.

  • NodeJS Websocket implementation (NodeJS): This example implements a bidirectional WebSocket-based audio streaming application that integrates with Amazon Nova 2 Sonic for real-time speech-to-speech conversation using NodeJS.

  • NodeJS Websocket implementation (C#): This example implements a bidirectional WebSocket-based audio streaming application that integrates with Amazon Nova 2 Sonic for real-time speech-to-speech conversation using .NET.

Advanced use cases

For advanced examples demonstrating more complex use cases, refer to the following implementations:

  • Amazon Bedrock Knowledge Base implementation (NodeJS): This example demonstrates how to build an intelligent conversational application by integrating Amazon Nova 2 Sonic with Amazon Bedrock Knowledge Base using NodeJS.

  • Chat History Management (Python): This example includes a chat history logging system that captures and preserves all interactions between the user and Amazon Nova 2 Sonic using Python.

  • Hotel Reservation Cancellation (NodeJS): This example demonstrates a practical customer service use case for Amazon Nova 2 Sonic, implementing a hotel reservation cancellation system using NodeJS.

  • LangChain Knowledge Base integration (Python): This implementation demonstrates how to integrate Amazon Nova 2 Sonic speech-to-speech capabilities with a LangChain-powered knowledge base for enhanced conversational experiences using Python.

  • Conversation Resumption (NodeJS): This example demonstrates how to implement conversation resumption capabilities with Amazon Nova 2 Sonic. Using a hotel reservation cancellation scenario as the context, the application shows how to maintain conversation state across sessions, allowing users to seamlessly continue interactions that were previously interrupted using NodeJS.

  • Nova 2 Sonic Speaks First (NodeJS): This example demonstrates how Amazon Nova 2 Sonic can initiate conversations proactively.

  • Session Continuation (Python): This example demonstrates how to enable unlimited conversation length with Amazon Nova 2 Sonic by implementing seamless session transitions. The application automatically creates and switches to new sessions in the background, allowing conversations to continue indefinitely without interruption or context loss.

Hands-on workshop

A hands-on workshop is available that guides you through building a voice chat application using Amazon Nova 2 Sonic with a bidirectional streaming interface. You can access the workshop and find the complete code examples.