Speech recognition with speaker labels (WhisperX)#

This procedure requires access to the installation directory, server configuration and Docker. Save the previous Whisper settings for rollback. To transcribe through Sherpa AI Server, create a model in the account with Transcription support and an active instance that connects to local Whisper and sends large-v2 as its model path. For Chat, assign this model as the transcription default. Editing .env does not create a model card or redirect an external instance to the local service.

This guide explains how to enable local audio and video transcription with speaker separation (diarization) in Sherpa AI Server. Processing runs entirely on your server, without external services or internet access during operation.

Recognized speech segments with an identified speaker receive a speaker label (speaker_1, speaker_2, and so on) and timestamps. Labels start at 1 in the order speakers first appear in the recording. They are included in the API result and the LLM context as lines such as [0:00:05] speaker_1: Привет. The Chat interface has no separate speaker screen.

Requirements#

Before enabling this method, make sure that:

  • Sherpa AI Server is installed and the aiserver-whisper service runs with the whisper or full profile;
  • Whisper runs on an NVIDIA GPU (see Switching Whisper from CPU to GPU); this method is very slow on a CPU;
  • you have the model-whisperx-large-v2.tar.gz model archive (about 3 GB) and enough disk space;
  • your aiserver-whisper image version supports the whisperx method.

The large-v2.pt file used by the standard base method is not suitable for WhisperX: WhisperX uses a different model format. You do not need to delete the existing model files.

Step 1. It is necessary to extract the model files#

The archive includes a separate large-v2 speech recognition model, Russian and English alignment models, and the pyannote/speaker-diarization-community-1 diarization model. Download it from the distribution list. From the installation directory, run:

curl -fL -o model-whisperx-large-v2.tar.gz https://downloads.sherparpa.ru/SherpaAIServer/models/model-whisperx-large-v2.tar.gz
mkdir -p ./whisper/models
tar -tzf model-whisperx-large-v2.tar.gz | head
tar -xzvf model-whisperx-large-v2.tar.gz -C ./whisper/models
ls ./whisper/models/whisperx

The ./whisper/models/whisperx directory should appear alongside the existing model files. In docker-compose.yml, the aiserver-whisper service must mount ./whisper/models:/models:ro so the container can read them. A Hugging Face token and internet access are not needed after downloading the archive.

Step 2. Enable the method in .env#

To configure the local service, open .env and set these values in the # !whisper block:

WHISPER_METHOD=whisperx
WHISPER_MODEL=large-v2
WHISPERX_DIARIZE=true

Additional parameters:

Parameter Purpose
WHISPERX_DIARIZE true — separate speakers (default); false — transcription with timestamps only
WHISPERX_NUM_SPEAKERS The exact number of speakers, if known. It is necessary to leave empty to detect it automatically
WHISPERX_BATCH_SIZE Reduce this value if you receive a CUDA out of memory error

Diarization for an account#

The WHISPERX_DIARIZE parameter defines the local service mode for a direct request without the diarize parameter. Sherpa AI Server always sends the value of "Also perform diarization" from the selected model card. This applies to both an explicit model selection and the account default. Selecting the checkbox adds speaker separation. Clearing it leaves transcription only. The change applies to the next audio without restarting the container. With neither a selected model nor a default, the server returns 404 model_not_found instead of using .env settings. An unavailable instance returns 503 model_unavailable.

The procedure for enabling diarization in the model dialog is described in Models.

Step 3. Apply Whisper settings#

Recreate the aiserver-whisper container to apply its .env settings. The command uses the image already available locally, without rebuilding or pulling it. The restart temporarily interrupts transcription. Saved instance parameters and the diarization checkbox are changed in the model card and do not require a server restart.

docker compose --profile whisper up -d --no-build --pull never --force-recreate aiserver-whisper

Step 4. It is necessary to check operation#

curl -sS http://127.0.0.1:3005/health

The response should contain "method":"whisperx" and "diarization_enabled":true.

This response confirms the service configuration. It does not prove that weights loaded or transcription succeeded: weights load on the first request. Verify the result by processing audio through the selected local route.

To check speaker separation in Chat, select "Also perform diarization" in the default transcription model and save its card. Then attach an audio or video recording of two people talking in the Chat and send a message. The transcription text passed to the LLM will contain speaker_1 and speaker_2 labels with timestamps.

A short recording can be submitted directly to the local Whisper API to inspect the result. The shell variable WHISPER_API_KEY must contain this service's valid key when key verification is enabled. If the service has no key configured, the example does not require the Authorization header.

curl -fsS http://127.0.0.1:3005/v1/audio/transcriptions \
  -H "Authorization: Bearer $WHISPER_API_KEY" \
  -F "file=@./meeting.wav" \
  -F "model=large-v2" \
  -F "response_format=verbose_json" \
  -F "diarize=true"

The response's segments array must be checked for recognized text, start and end timestamps, and speaker for segments whose speaker was identified. A missing speaker does not mean the segment's author was identified. A failed request requires checking the weights, GPU availability and the service message. A successful /health alone does not confirm this result.

Limitations#

  • Processing takes longer than standard transcription. It is necessary to check request timeouts for long recordings.
  • Speakers may be identified incorrectly when their voices overlap significantly.
  • The method does not determine real names: it assigns speaker_N labels only.
  • The prompt and temperature parameters are not used by this method.

Rollback#

To roll back, restore the previous Whisper settings in .env and repeat step 3 for the Whisper container. The previous model weights must be available. If the instance model path was changed, restore it in the model card as well.