Context Switch is a Rust-based framework for building real-time conversational applications with support for multiple modalities (audio and text). It provides a unified interface for interacting with various speech and language services like Azure Speech Services and OpenAI.
- Multi-modal conversation support (audio and text)
- Pluggable service architecture
- Integration with:
- Azure Speech Services (transcription, translation, synthesis)
- OpenAI dialog services
 
- Asynchronous processing using Tokio
- core/: Core functionality and interfaces
- services/: Implementation of various service integrations- azure/: Azure Speech Services integration
- google-transcribe/: Google Speech-to-Text integration (WIP)
- openai-dialog/: OpenAI conversational services integration
 
- audio-knife/: WebSocket server that implements the mod_audio_fork protocol for real-time audio streaming from telephony systems via FreeSWITCH. Provides a bridge between audio sources and the Context Switch framework.
- examples/: Example applications showcasing different features
- Rust
- API keys for the services you intend to use:
- OpenAI API key
- Azure Speech Services subscription key
- Google Cloud API key (for Google transcription)
 
- For Aristech services:
- Install protoc
- macOS: brew install protobuf
- Linux: apt-get install protobuf-compiler
 
- macOS: 
 
- Install protoc
- 
Clone the repository: git clone https://github.com/pragmatrix/context-switch.git cd context-switch
- 
Initialize submodules: git submodule update --init --recursive 
- 
Create a .envfile with your API keys (see.env.examplefor reference)
The project includes several examples showcasing different functionalities:
# Run OpenAI dialog example
cargo run --example openai-dialog
# Run Azure transcribe example
cargo run --example azure-transcribe
# Run Azure synthesize example
cargo run --example azure-synthesizeAudio Knife is a WebSocket server that implements the mod_audio_fork protocol, allowing real-time audio streaming from and to FreeSWITCH. It acts as a bridge between audio sources and the Context Switch framework.
To run the Audio Knife server:
cargo run -p audio-knifeBy default, it listens on 127.0.0.1:8123. You can customize the address by setting the AUDIO_KNIFE_ADDRESS environment variable.
Configure the services by setting the appropriate environment variables in your .env file:
# OpenAI Configuration
OPENAI_API_KEY=your_openai_key
OPENAI_REALTIME_API_MODEL=gpt-4o-mini-realtime-preview
# Azure Configuration
AZURE_SUBSCRIPTION_KEY=your_azure_key
AZURE_REGION=your_azure_region
# Audio Knife Configuration
AUDIO_KNIFE_ADDRESS=127.0.0.1:8123