A Streamlit-ready voice pipeline for real-time conversation with OpenAI's GPT-4o Realtime API
Project description
Streamlit Voice Pipeline
A Streamlit-ready voice pipeline for real-time conversation with OpenAI's GPT-4o Realtime API. Build voice-enabled Streamlit applications with minimal setup!
Features
- 🎤 Real-time voice conversation with OpenAI's GPT-4o
- 🔄 Automatic reconnection on connection drops
- 📱 Streamlit-optimized with session state integration
- 🎨 Customizable voices and speech parameters
- 📝 Conversation transcripts and history
- ⚡ Thread-safe and production-ready
- 🛠️ Easy callbacks for transcripts, errors, and status changes
Installation
pip install streamlit-voice-pipeline
Quick Start
import streamlit as st
from streamlit_voice_pipeline import get_or_create_pipeline
st.title("🎤 Voice Chat with AI")
# Initialize pipeline
pipeline = get_or_create_pipeline(
api_key="your-openai-api-key",
voice="alloy" # Options: alloy, echo, fable, onyx, nova, shimmer, verse
)
# Control buttons
col1, col2 = st.columns(2)
with col1:
if st.button("🎤 Start Voice Chat"):
pipeline.start()
st.success("Started!")
with col2:
if st.button("⏹️ Stop"):
pipeline.stop()
st.info("Stopped")
# Show status
st.write(f"**Status:** {pipeline.get_status()}")
# Display conversation
transcripts = pipeline.get_transcripts()
for transcript in transcripts:
st.write(f"**{transcript['role'].title()}:** {transcript['content']}")
Advanced Usage
With Callbacks
def on_transcript(text):
st.session_state.messages.append(text)
def on_error(error):
st.error(f"Error: {error}")
def on_status_change(status):
st.session_state.status = status
pipeline = get_or_create_pipeline(
api_key="your-key",
voice="echo",
temperature=0.8,
max_tokens=800,
on_transcript=on_transcript,
on_error=on_error,
on_status_change=on_status_change
)
Configuration Options
pipeline = StreamlitVoicePipeline(
api_key="your-openai-api-key",
model="gpt-4o-realtime-preview-2025-06-03",
voice="alloy", # Voice selection
temperature=0.8, # Response creativity (0.0-1.0)
max_tokens=800, # Maximum response length
sample_rate=24000, # Audio quality (16000/24000/48000)
vad_threshold=0.7, # Voice detection sensitivity
silence_duration=1200, # Silence before stopping (ms)
)
Available Voices
- alloy - Neutral, balanced
- echo - Expressive, dynamic
- fable - Warm, storytelling
- onyx - Deep, authoritative
- nova - Youthful, energetic
- shimmer - Gentle, soft
- verse - Conversational, friendly
Status Values
stopped- Pipeline not runningconnecting- Establishing connectionconnected- Connected to APIready- Ready for conversationlistening- Waiting for user speechuser_speaking- User is talkingprocessing- Processing user inputai_speaking- AI is respondingerror- Error occurred
Requirements
- Python 3.8+
- OpenAI API key with Realtime API access
- Microphone and speakers/headphones
- Internet connection
Example Applications
Check out the /examples directory for:
- Basic voice chat app
- Advanced configuration demo
- Integration with other Streamlit components
Troubleshooting
Common Issues
"No microphone detected"
# Linux
sudo apt-get install portaudio19-dev python3-pyaudio
# macOS
brew install portaudio
pip install pyaudio
# Windows
pip install pipwin
pipwin install pyaudio
"WebSocket connection failed"
- Check your OpenAI API key
- Ensure you have Realtime API access
- Verify internet connection
"Audio feedback/echo"
- Use headphones instead of speakers
- Adjust
vad_thresholdparameter - Check microphone sensitivity
Contributing
Contributions welcome! Please read our contributing guidelines and submit PRs.
License
MIT License - see LICENSE file for details.
Support
Built with ❤️ for the Streamlit community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_voice_pipeline-1.0.0.tar.gz.
File metadata
- Download URL: streamlit_voice_pipeline-1.0.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
355530e80c9b412e90d0c875c02e6adbbc1508d32297ec30f0703a0d9c9c919b
|
|
| MD5 |
f351f0c4176ec422accf2a0e97046c8d
|
|
| BLAKE2b-256 |
693e92102dc028faf6bdc6868b76ebb6a73dc24c6a5448c0cfd3e20ff35896fe
|
File details
Details for the file streamlit_voice_pipeline-1.0.0-py3-none-any.whl.
File metadata
- Download URL: streamlit_voice_pipeline-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f851cbe549621013bb1fa36c71a7815f48e24ffd5495489f60b4512c9bd6f4f2
|
|
| MD5 |
a472b0ddf9d39ce5824720f30743b75a
|
|
| BLAKE2b-256 |
ecadaf684e1d1d2b4b3ab8ad6176bb92628d62017878a6231bb745a565d769b6
|