Skip to main content

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 running
  • connecting - Establishing connection
  • connected - Connected to API
  • ready - Ready for conversation
  • listening - Waiting for user speech
  • user_speaking - User is talking
  • processing - Processing user input
  • ai_speaking - AI is responding
  • error - 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_threshold parameter
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_voice_pipeline-1.0.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_voice_pipeline-1.0.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

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

Hashes for streamlit_voice_pipeline-1.0.0.tar.gz
Algorithm Hash digest
SHA256 355530e80c9b412e90d0c875c02e6adbbc1508d32297ec30f0703a0d9c9c919b
MD5 f351f0c4176ec422accf2a0e97046c8d
BLAKE2b-256 693e92102dc028faf6bdc6868b76ebb6a73dc24c6a5448c0cfd3e20ff35896fe

See more details on using hashes here.

File details

Details for the file streamlit_voice_pipeline-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_voice_pipeline-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f851cbe549621013bb1fa36c71a7815f48e24ffd5495489f60b4512c9bd6f4f2
MD5 a472b0ddf9d39ce5824720f30743b75a
BLAKE2b-256 ecadaf684e1d1d2b4b3ab8ad6176bb92628d62017878a6231bb745a565d769b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page