Files
semantic-kernel/python/samples/concepts/realtime
Evan Mattson 429dd1c4c0 Python: support (Azure) OpenAI realtime audio models (#13291)
### Motivation and Context

As of 2/27/2026, revived the PR, and the latest code is working for both
Azure OpenAI realtime models and OpenAI realtime models.

SK has support for realtime-preview models; however, since they've gone
to GA we have not added support for the latest library abstractions.
This PR brings in the changes to support running models like
`gpt-realtime-1.5`, `gpt-realtime`, `gpt-realtime-mini` or `gpt-audio`.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Closes #13267
- Code now relies on `openai` >= 2.0
- Considered a breaking change due some new config added to the
execution settings.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2026-02-28 09:01:03 +09:00
..

Realtime Multi-modal API Samples

These samples are more complex then most because of the nature of these API's. They are designed to be run in real-time and require a microphone and speaker to be connected to your computer.

To run these samples, you will need to have the following setup:

  • Environment variables for OpenAI (websocket or WebRTC), with your key and OPENAI_REALTIME_MODEL_ID set.
  • Environment variables for Azure (websocket only), set with your endpoint, optionally a key and AZURE_OPENAI_REALTIME_DEPLOYMENT_NAME set. The API version needs to be at least 2025-08-28.
  • To run the sample with a simple version of a class that handles the incoming and outgoing sound you need to install the following packages in your environment:
    • semantic-kernel[realtime]
    • pyaudio
    • sounddevice
    • pydub e.g. pip install pyaudio sounddevice pydub semantic-kernel[realtime]

The samples all run as python scripts, that can either be started directly or through your IDE.

All demos have a similar output, where the instructions are printed, each new response item from the API is put into a new Mosscap (transcript): line. The nature of these api's is such that the transcript arrives before the spoken audio, so if you interrupt the audio the transcript will not match the audio.

The realtime api's work by sending event from the server to you and sending events back to the server, this is fully asynchronous. The samples show you can listen to the events being sent by the server and some are handled by the code in the samples, others are not. For instance one could add a clause in the match case in the receive loop that logs the usage that is part of the response.done event.

For more info on the events, go to our documentation, as well as the documentation of OpenAI and Azure.

Simple chat samples

Simple chat with realtime websocket

This sample uses the websocket api with Azure OpenAI to run a simple interaction based on voice. If you want to use this sample with OpenAI, just change AzureRealtimeWebsocket into OpenAIRealtimeWebsocket.

Simple chat with realtime WebRTC

This sample uses the WebRTC api with OpenAI to run a simple interaction based on voice. Because of the way the WebRTC protocol works this needs a different player and recorder than the websocket version.

Function calling samples

The following two samples use function calling with the following functions:

  • get_weather: This function will return the weather for a given city, it is randomly generated and not based on any real data.
  • get_time: This function will return the current time and date.
  • goodbye: This function will end the conversation.

A line is logged whenever one of these functions is called.

Chat with function calling Websocket

This sample uses the websocket api with Azure OpenAI to run a voice agent, capable of taking actions on your behalf.

Chat with function calling WebRTC

This sample uses the WebRTC api with OpenAI to run a voice agent, capable of taking actions on your behalf.