Skip to main content

A nearly-live implementation of OpenAI's Whisper.

Project description

WhisperLive

WhisperLive WhisperLive

A nearly-live implementation of OpenAI's Whisper.

This project is a real-time transcription application that uses the OpenAI Whisper model to convert speech input into text output. It can be used to transcribe both live audio input from microphone and pre-recorded audio files.

Installation

  • Install PortAudio (required system dependency for microphone input via PyAudio)
 bash scripts/setup.sh

On Debian/Ubuntu this installs portaudio19-dev, on Fedora portaudio-devel, on macOS it uses Homebrew (portaudio).

  • Install whisper-live from pip
 pip install whisper-live
  • Install 3.12 venv on Fedora
sudo dnf install -y python3.12 python3.12-pip
python3.12 -m venv whisper_env
source whisper_env/bin/activate

OpenAI REST interface

Server

python3 run_server.py --port 9090 --backend faster_whisper --max_clients 4 --max_connection_time 600 --enable_rest --cors-origins="http://localhost:8080,http://127.0.0.1:8080"

Client

python3 client_openai.py $AUDIO_FILE

Setting up NVIDIA/TensorRT-LLM for TensorRT backend

Getting Started

The server supports 3 backends faster_whisper, tensorrt and openvino. If running tensorrt backend follow TensorRT_whisper readme

Running the Server

python3 run_server.py --port 9090 \
                      --backend faster_whisper \
                      --max_clients 4 \
                      --max_connection_time 600
  
# running with custom model and cache_dir to save auto-converted ctranslate2 models
python3 run_server.py --port 9090 \
                      --backend faster_whisper \
                      --max_clients 4 \
                      --max_connection_time 600 \
                      -fw "/path/to/custom/faster/whisper/model" \
                      -c ~/.cache/whisper-live/
  • TensorRT backend. Currently, we recommend to only use the docker setup for TensorRT. Follow TensorRT_whisper readme which works as expected. Make sure to build your TensorRT Engines before running the server with TensorRT backend.
# Run English only model
python3 run_server.py -p 9090 \
                      -b tensorrt \
                      -trt /home/TensorRT-LLM/examples/whisper/whisper_small_en \
                      --max_clients 4 \
                      --max_connection_time 600

# Run Multilingual model
python3 run_server.py -p 9090 \
                      -b tensorrt \
                      -trt /home/TensorRT-LLM/examples/whisper/whisper_small \
                      -m \
                      --max_clients 4 \
                      --max_connection_time 600

Note: The TensorRT backend uses a C++ session by default. If you experience issues (e.g. repeated CrossAttentionMask warnings or crashes), add the --trt_py_session flag to use the Python session instead.

  • Use --max_clients option to restrict the number of clients the server should allow. Defaults to 4.
  • Use --max_connection_time options to limit connection time for a client in seconds. Defaults to 600.
  • WhisperLive now supports the OpenVINO backend for efficient inference on Intel CPUs, iGPU and dGPUs. Currently, we tested the models uploaded to huggingface by OpenVINO.
    • Docker Recommended: Running WhisperLive with OpenVINO inside Docker automatically enables GPU support (iGPU/dGPU) without requiring additional host setup.

    • Native (non-Docker) Use: If you prefer running outside Docker, ensure the Intel drivers and OpenVINO runtime are installed and properly configured on your system. Refer to the documentation for installing OpenVINO.

python3 run_server.py -p 9090 -b openvino

Controlling OpenMP Threads

To control the number of threads used by OpenMP, you can set the OMP_NUM_THREADS environment variable. This is useful for managing CPU resources and ensuring consistent performance. If not specified, OMP_NUM_THREADS is set to 1 by default. You can change this by using the --omp_num_threads argument:

python3 run_server.py --port 9090 \
                      --backend faster_whisper \
                      --omp_num_threads 4

Single model mode

By default, when running the server without specifying a model, the server will instantiate a new whisper model for every client connection. This has the advantage, that the server can use different model sizes, based on the client's requested model size. On the other hand, it also means you have to wait for the model to be loaded upon client connection and you will have increased (V)RAM usage.

When serving a custom TensorRT model using the -trt or a custom faster_whisper model using the -fw option, the server will instead only instantiate the custom model once and then reuse it for all client connections.

If you don't want this, set --no_single_model.

Running the Client

Use the below command to run the client:

python3 run_client.py --files <audio-file-name>

This will connect to the localhost server running on port 9090 by default. Use flags --server and --port to use different configurations. The above command will transcribe audio file provided with --files flag.

Here are the details of client instance implemented in run_client.py script:

  • lang: Language of the input audio, applicable only if using a multilingual model.
  • translate: If set to True then translate from any language to en.
  • model: Whisper model size.
  • use_vad: Whether to use Voice Activity Detection on the server.
  • save_output_recording: Set to True to save the microphone input as a .wav file during live transcription. This option is helpful for recording sessions for later playback or analysis. Defaults to False.
  • output_recording_filename: Specifies the .wav file path where the microphone input will be saved if save_output_recording is set to True.
  • mute_audio_playback: Whether to mute audio playback when transcribing an audio file. Defaults to False.
  • enable_translation: Start translation thread on the server (from any to any).
  • target_language: Server translation thread's target translation language.
from whisper_live.client import TranscriptionClient
client = TranscriptionClient(
  "localhost",
  9090,
  lang="en",
  translate=False,
  model="small",                                      # also support hf_model => `Systran/faster-whisper-small`
  use_vad=False,
  save_output_recording=True,                         # Only used for microphone input, False by Default
  output_recording_filename="./output_recording.wav", # Only used for microphone input
  mute_audio_playback=False,                          # Only used for file input, False by Default
  enable_translation=True,
  target_language="hi",
)

It connects to the server running on localhost at port 9090. Using a multilingual model, language for the transcription will be automatically detected. You can also use the language option to specify the target language for the transcription, in this case, English ("en"). The translate option should be set to True if we want to translate from the source language to English and False if we want to transcribe in the source language.

  • Transcribe an audio file:
client("tests/jfk.wav")
  • To transcribe from microphone:
client()
  • To transcribe from a RTSP stream:
client(rtsp_url="rtsp://admin:admin@192.168.0.1/rtsp")
  • To transcribe from a HLS stream:
client(hls_url="http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_1xtra/bbc_1xtra.isml/bbc_1xtra-audio%3d96000.norewind.m3u8")

Advanced Features

Word-Level Timestamps

Enable per-word timing and confidence scores in transcription segments:

client = TranscriptionClient(
  "localhost", 9090,
  word_timestamps=True,
)

When enabled, each segment in the WebSocket response includes a words array:

{
  "segments": [{
    "start": "0.000", "end": "2.500", "text": "Hello world",
    "words": [
      {"word": "Hello", "start": "0.000", "end": "0.800", "probability": 0.95},
      {"word": " world", "start": "0.900", "end": "2.500", "probability": 0.88}
    ]
  }]
}

Custom Vocabulary / Hotwords

Boost recognition of specific terms (product names, acronyms, domain jargon):

client = TranscriptionClient(
  "localhost", 9090,
  hotwords="WhisperLive,TensorRT,OpenVINO",
)

The hotwords parameter is a comma-separated string passed directly to faster-whisper's keyword boosting. Also available in the REST API via the hotwords form field.

Speaker Diarization

Real-time speaker identification using pyannote.audio embeddings (optional dependency):

pip install pyannote.audio
client = TranscriptionClient(
  "localhost", 9090,
  enable_diarization=True,
  max_speakers=4,
)

When enabled, completed segments include a speaker field:

{"start": "0.000", "end": "2.500", "text": "Hello", "speaker": "SPEAKER_00", "completed": true}

Diarization uses online cosine-similarity clustering of speaker embeddings. If pyannote.audio is not installed, the server logs a warning and continues without diarization.

Batch Inference

Batch multiple client sessions into single GPU calls for higher throughput:

python3 run_server.py --port 9090 --backend faster_whisper \
  --batch_inference --batch_max_size 8 --batch_window_ms 50

Raw PCM Input

Accept raw PCM int16 audio from clients (useful for embedded devices):

python3 run_server.py --port 9090 --backend faster_whisper --raw_pcm_input

Audio is automatically normalized to float32 range [-1.0, 1.0].

Browser Extensions

iOS Client

Use WhisperLive on iOS with our native iOS client.
Refer to ios-client and ios-client/README.md for setup and usage instructions.

Whisper Live Server in Docker

  • GPU

    • Faster-Whisper
    docker run -it --gpus all -p 9090:9090 ghcr.io/collabora/whisperlive-gpu:latest
    
    docker build . -f docker/Dockerfile.tensorrt -t whisperlive-tensorrt
    docker run -p 9090:9090 --runtime=nvidia --gpus all --entrypoint /bin/bash -it whisperlive-tensorrt
    
    # Build small.en engine
    bash build_whisper_tensorrt.sh /app/TensorRT-LLM-examples small.en        # float16
    bash build_whisper_tensorrt.sh /app/TensorRT-LLM-examples small.en int8   # int8 weight only quantization
    bash build_whisper_tensorrt.sh /app/TensorRT-LLM-examples small.en int4   # int4 weight only quantization
    
    # Run server with small.en (pick one engine)
    python3 run_server.py --port 9090 \
                          --backend tensorrt \
                          --trt_model_path "/app/TensorRT-LLM-examples/whisper/whisper_small_en_float16"
    # or int8 / int4:
    # --trt_model_path "/app/TensorRT-LLM-examples/whisper/whisper_small_en_int8"
    # --trt_model_path "/app/TensorRT-LLM-examples/whisper/whisper_small_en_int4"
    
    • OpenVINO
    docker run -it --device=/dev/dri -p 9090:9090 ghcr.io/collabora/whisperlive-openvino
    
  • CPU

    • Faster-whisper
    docker run -it -p 9090:9090 ghcr.io/collabora/whisperlive-cpu:latest
    

Future Work

  • Add translation to other languages on top of transcription.

Blog Posts

Contact

We are available to help you with both Open Source and proprietary AI projects. You can reach us via the Collabora website or vineet.suryan@collabora.com and marcus.edel@collabora.com.

Citations

@article{Whisper
  title = {Robust Speech Recognition via Large-Scale Weak Supervision},
  url = {https://arxiv.org/abs/2212.04356},
  author = {Radford, Alec and Kim, Jong Wook and Xu, Tao and Brockman, Greg and McLeavey, Christine and Sutskever, Ilya},
  publisher = {arXiv},
  year = {2022},
}
@misc{Silero VAD,
  author = {Silero Team},
  title = {Silero VAD: pre-trained enterprise-grade Voice Activity Detector (VAD), Number Detector and Language Classifier},
  year = {2021},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/snakers4/silero-vad}},
  email = {hello@silero.ai}
}

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

whisper_live-0.9.0.tar.gz (99.1 kB view details)

Uploaded Source

Built Distribution

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

whisper_live-0.9.0-py3-none-any.whl (107.4 kB view details)

Uploaded Python 3

File details

Details for the file whisper_live-0.9.0.tar.gz.

File metadata

  • Download URL: whisper_live-0.9.0.tar.gz
  • Upload date:
  • Size: 99.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for whisper_live-0.9.0.tar.gz
Algorithm Hash digest
SHA256 947f596197af53f1864f827b7d9485ef9c695d13e29fe929e5c83217c9136c6c
MD5 9632cafef43d15b69bc256d7b28866e9
BLAKE2b-256 6f3b95cb0d912d7b37c5806921d7b55d5941d056b3d4c291ea1852ff4b4aff64

See more details on using hashes here.

File details

Details for the file whisper_live-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: whisper_live-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 107.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for whisper_live-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8317e0fec36866f92ed77d29508bfc686e50446998bf3cd7a3c1e4499c609c3
MD5 0f765395f3413e6899b52ecbb0e2e5c7
BLAKE2b-256 c403bdd18eaca447d5cfd5ceaf09c6f8c0c4168a5291ae7ed2028299f4b9240b

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