Skip to main content

A modular voice agent with swappable STT/TTS/LLM backends

Project description

fastrtc-voice-agent

A modular voice agent built on FastRTC

Installation

pip install fastrtc-voice-agent

Please install your desired STT and LLM with (for example) :

pip install "fastrtc-voice-agent[ollama]"

or for all optional dependancies :

pip install "fastrtc-voice-agent[all]"

CLI Usage Example

For default config :

fastrtc-voice-agent --run

Please refere to the help for custom config :

fastrtc-voice-agent --help

Python Usage Example

from fastrtc import ReplyOnPause, Stream
from voice_agent import create_agent, AgentConfig, STTConfig, TTSConfig, LLMConfig

config = AgentConfig(
    system_prompt="You are a helpful voice assistant.",
    stt=STTConfig(backend="faster_whisper", model_size="small"),
    tts=TTSConfig(backend="edge", voice="en-US-AvaMultilingualNeural"),
    llm=LLMConfig(backend="ollama", model="llama3.2:3b"),
)

agent = create_agent(config)

stream = Stream(
    ReplyOnPause(agent.create_fastrtc_handler()),
    modality="audio",
    mode="send-receive",
)

stream.ui.launch()

Custom Frontend Integration

If you want to use your own frontend (React, Vue, etc.) instead of the built-in Gradio UI, you can run the agent as an API server.

CLI - API Mode

# Install with API support
pip install "fastrtc-voice-agent[api]"

# Run as API server (no Gradio UI)
fastrtc-voice-agent --run --api --port 8000

This exposes WebRTC endpoints:

  • POST /webrtc/offer - WebRTC signaling
  • WS /websocket/offer - WebSocket alternative

Python - API Server

from voice_agent import create_api_server, AgentConfig, STTConfig, TTSConfig, LLMConfig

# Create a FastAPI app with the voice agent
app = create_api_server(
    config=AgentConfig(
        system_prompt="You are a helpful assistant.",
        stt=STTConfig(backend="faster_whisper"),
        tts=TTSConfig(backend="edge"),
        llm=LLMConfig(backend="ollama"),
    )
)

# Run with: uvicorn main:app --host 0.0.0.0 --port 8000

You can also mount it in an existing FastAPI app:

from fastapi import FastAPI
from voice_agent import create_api_server

main_app = FastAPI()
voice_app = create_api_server()
main_app.mount("/voice", voice_app)

React Example

See the examples/react-client directory for a complete React example with a useVoiceAgent hook.

Quick example:

import { useVoiceAgent } from './useVoiceAgent';

function App() {
  const { isConnected, connect, disconnect } = useVoiceAgent({
    serverUrl: 'http://localhost:8000',
  });

  return (
    <button onClick={isConnected ? disconnect : connect}>
      {isConnected ? 'Stop' : 'Start'}
    </button>
  );
}

Note

To use Anthropic API (may be OpenAI or else later) please copy .env.example as .env file and fill it with your API KEY and the desired model

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

fastrtc_voice_agent-0.1.5.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

fastrtc_voice_agent-0.1.5-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file fastrtc_voice_agent-0.1.5.tar.gz.

File metadata

  • Download URL: fastrtc_voice_agent-0.1.5.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for fastrtc_voice_agent-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3f3eda07c2b3c641fd22b9a1da2795212f858091a15dd4597676aab0bcb3e266
MD5 6d0c32568976d607ddcb228265af6593
BLAKE2b-256 e7d02714cca0d8b7bdbf830dbab3da29889555dcc8828bd25c665bed67ef99b8

See more details on using hashes here.

File details

Details for the file fastrtc_voice_agent-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for fastrtc_voice_agent-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bd1b11fd5a518c7cbc1de5c6391db97053f37fd9fb042614a99b05274b9fa4c1
MD5 0573acffd4a9ac8b6e9f97f851eb42cd
BLAKE2b-256 8e3a57a636b71b8d1cff2b82fec2d355be18d44927231fb314547c82a54626be

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