Speaches Documentation

repository·master·Indexed 25 days ago

https://github.com/speaches-ai/speaches

An OpenAI-compatible server for speech-related tasks, providing streaming transcription, translation, and speech generation. It supports engines such as faster-whisper for STT and piper or Kokoro for TTS, with compatibility for both GPU (CUDA) and CPU hardware. Key features include a Realtime API via WebSockets, dynamic model management, and integration with Open WebUI.

Tokens
13K
Snippets
29
Records
82
Agent score
86%

What's inside Speaches

  1. Overview of Speaches

    master

    Speaches is an OpenAI API-compatible server designed for streaming transcription, translation, and speech generation. It functions similarly to Ollama but is specialized for TTS (Text-to-Speech) and STT (Speech-to-Text) models.

    Key capabilities include:

    • OpenAI Compatibility: Works with any tool or SDK designed for OpenAI's API.
    • Audio Generation: Supports text-to-audio summaries, sentiment analysis on recordings, and async speech-to-speech interactions via the chat completions endpoint.
    • Streaming Support: Transcription is delivered via Server-Sent Events (SSE) as it happens, eliminating the need to wait for the full audio file to process.
    • Dynamic Model Management: Models are loaded automatically based on the request and unloaded after a period of inactivity.
    • Engine Support: Uses faster-whisper for STT, and piper or Kokoro for TTS.
    • Hardware Support: Compatible with both GPU and CPU.
  2. Configure Transcription-Only Mode

    master

    Speaches provides an extension for transcription-only scenarios (e.g., live subtitles or voice notes). In this mode, the model URL parameter specifies the transcription model rather than a conversation model, and response generation is disabled (create_response=false).

    You can specify the mode using the intent=transcription query parameter.

    // Transcription-only mode (Speaches extension)
    const ws = new WebSocket(
      "wss://your-speaches-server/v1/realtime?model=deepdml/faster-whisper-large-v3-turbo-ct2&intent=transcription&api_key=your-api-key"
    );
  3. Set up environment variables for Voice Chat

    master

    To use the voice chat proxy functionality, you must configure speaches with an OpenAI-compatible endpoint using the following environment variables:

    • CHAT_COMPLETION_BASE_URL: The base URL of your OpenAI-compatible API (e.g., Ollama or OpenAI).
    • CHAT_COMPLETION_API_KEY: The authentication key required by your API.

    You must also have a Text-to-Speech (TTS) model and a Speech-to-Text (STT) model downloaded and configured.

    # Example for Ollama
    export CHAT_COMPLETION_BASE_URL=http://localhost:11434/v1
    
    # Example for OpenAI
    export CHAT_COMPLETION_BASE_URL=https://api.openai.com/v1
    export CHAT_COMPLETION_API_KEY=sk-xxx
  4. Run Speaches using Docker

    master

    You can run Speaches directly using docker run. Choose the command that matches your hardware requirements.

    CUDA

    docker run \
      --rm \
      --detach \
      --publish 8000:8000 \
      --name speaches \
      --volume hf-hub-cache:/home/ubuntu/.cache/huggingface/hub \
      --gpus=all \
      ghcr.io/speaches-ai/speaches:latest-cuda

    CUDA (with CDI feature enabled)

    docker run \
      --rm \
      --detach \
      --publish 8000:8000 \
      --name speaches \
      --volume hf-hub-cache:/home/ubuntu/.cache/huggingface/hub \
      --device=nvidia.com/gpu=all \
      ghcr.io/speaches-ai/speaches:latest-cuda

    CPU

    docker run \
      --rm \
      --detach \
      --publish 8000:8000 \
      --name speaches \
      --volume hf-hub-cache:/home/ubuntu/.cache/huggingface/hub \
      ghcr.io/speaches-ai/speaches:latest-cpu
  5. Integrate Speaches with Open WebUI via the UI

    master

    To connect Open WebUI to Speaches for Speech-to-Text (STT) functionality, configure the settings within the Open WebUI Admin panel:

    1. Navigate to the Admin Settings page.
    2. Select the Audio tab.
    3. Configure the following values:
      • Speech-to-Text Engine: OpenAI
      • API Base URL: http://speaches:8000/v1
      • API Key: Enter any non-empty string (e.g., speaches-key).
      • Model: Systran/faster-distil-whisper-large-v3
    4. Click Save.
  6. Customize transcription and speech models in Voice Chat

    master

    You can specify which models are used for transcription and speech generation by passing additional parameters to the chat completion endpoint.

    When using the OpenAI Python SDK, these parameters must be passed via the extra_body argument:

    • transcription_model: The model used to transcribe input audio.
    • speech_model: The model used to generate output audio.
    openai_client.chat.completions.create(
            model="gpt-4o-mini",
            modalities=["text", "audio"],
            audio={"voice": "alloy", "format": "wav"},
            stream=False,
            messages=[
                {
                    "role": "user",
                    "content": [
                        {"type": "text", "text": "What is in this recording?"},
                        {"type": "input_audio", "input_audio": {"data": "<bytes ommitted>", "format": "wav"}},
                    ],
                },
            ],
            extra_body={"transcription_model": "Systran/faster-whisper-tiny.en", "speech_model": "hexgrad/Kokoro-82M"}
        )
  7. Use the Speaches Realtime API

    master

    The Speaches Realtime API provides an OpenAI-compatible WebSocket interface for real-time audio processing. It supports two primary modes: Conversation Mode (full interactive AI with speech input and output) and Transcription-Only Mode (speech-to-text without AI responses).

    To achieve optimal real-time performance, it is recommended to use CUDA for TTS and STT inference and an LLM provider with high TPS and low TTFT.

    // Standard OpenAI-compatible usage
    const ws = new WebSocket("wss://your-speaches-server/v1/realtime?model=gpt-4o-realtime-preview", {
      headers: {
        'Authorization': 'Bearer your-api-key'
      }
    });
  8. Install Speaches using Docker Compose (Recommended)

    master

    To run Speaches using Docker Compose, download the appropriate YAML configuration files based on your hardware (CUDA or CPU) and set the COMPOSE_FILE environment variable before starting the service.

    CUDA Setup

    curl --silent --remote-name https://raw.githubusercontent.com/speaches-ai/speaches/master/compose.yaml
    curl --silent --remote-name https://raw.githubusercontent.com/speaches-ai/speaches/master/compose.cuda.yaml
    export COMPOSE_FILE=compose.cuda.yaml

    CUDA with CDI feature enabled

    curl --silent --remote-name https://raw.githubusercontent.com/speaches-ai/speaches/master/compose.yaml
    curl --silent --remote-name https://raw.githubusercontent.com/speaches-ai/speaches/master/compose.cuda.yaml
    curl --silent --remote-name https://raw.githubusercontent.com/speaches-ai/speaches/master/compose.cuda-cdi.yaml
    export COMPOSE_FILE=compose.cuda-cdi.yaml

    CPU Setup

    curl --silent --remote-name https://raw.githubusercontent.com/speaches-ai/speaches/master/compose.yaml
    curl --silent --remote-name https://raw.githubusercontent.com/speaches-ai/speaches/master/compose.cpu.yaml
    export COMPOSE_FILE=compose.cpu.yaml

    After setting the environment variable, start the service with:

    docker compose up --detach
    docker compose up --detach
  9. Manage STT models with speaches-cli

    master

    Use the speaches-cli to list, download, and verify Speech-to-Text (STT) models. Ensure SPEACHES_BASE_URL is set to your server address before running commands.

    • List available STT models: Use registry ls with the --task automatic-speech-recognition flag.
    • Download a model: Use model download <model_id>.
    • Verify installation: Use model ls with the --task text-to-speech flag (Note: the documentation uses text-to-speech in the example to check for the model, ensure you use the correct task for your needs) and filter the output.
    export SPEACHES_BASE_URL="http://localhost:8000"
    
    # Listing all available STT models
    uvx speaches-cli registry ls --task automatic-speech-recognition | jq '.data | [].id'
    
    # Downloading a Systran/faster-distil-whisper-small.en model
    uvx speaches-cli model download Systran/faster-distil-whisper-small.en
    
    # Check that the model has been installed
    uvx speaches-cli model ls --task text-to-speech | jq '.data | map(select(.id == "Systran/faster-distil-whisper-small.en"))'
  10. Discover supported models via the registry

    master

    To see all available models, query the /v1/registry endpoint. You can filter the list by task type (e.g., automatic-speech-recognition, text-to-speech) using the task query parameter.

    Ensure the SPEACHES_BASE_URL environment variable is set to your server URL (e.g., http://localhost:8000).

  11. Mount model_aliases.json in Docker

    master

    When deploying via Docker, bind mount your local model_aliases.json file to the container so the server can load your custom aliases.

    # Docker CLI
    docker run -v /path/to/your/model_aliases.json:/home/ubuntu/speaches/model_aliases.json speaches
    # Docker Compose
    services:
      speaches:
        volumes:
          - ./model_aliases.json:/home/ubuntu/speaches/model_aliases.json