Skip to navigation

How to enable speaker diarization

View as Markdown

Batch API only: Speaker diarization is only available through the Batch API, not the REST or Streaming APIs.

Speaker diarization identifies and labels different speakers in your audio, making it easy to know “who said what.” This is ideal for meetings, interviews, podcasts, and call center recordings.

Key Features

  • Automatic speaker detection
  • Support for up to 20 speakers
  • Speaker-wise transcription with timestamps

Parameters

ParameterTypeDescription
with_diarizationbooleanEnable speaker diarization (default: false)
num_speakersintegerExpected number of speakers (optional, 1-20)

If you don’t specify num_speakers, the model will automatically detect the number of speakers.

Example Code

from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
# Create batch job with diarization
job = client.speech_to_text_job.create_job(
model="saaras:v4",
language_code="hi-IN",
mode="transcribe",
with_diarization=True
)
# Upload audio files
job.upload_files(file_paths=["meeting_recording.mp3"])
# Start processing
job.start()
# Wait for completion
job.wait_until_complete()
# Download results
job.download_outputs(output_dir="./output")

Output Format

When with_diarization=True is passed, the response includes a diarized_transcript field with speaker information:

{
"request_id": "20260130_d8d2c0e6-1eb6-4982-8045-b267d5165c44",
"transcript": "Full transcript text...",
"timestamps": {
"words": ["Hello, how can I help you today?", "I have a question about my order."],
"start_time_seconds": [0.01, 2.8],
"end_time_seconds": [2.5, 5.2]
},
"diarized_transcript": {
"entries": [
{
"transcript": "Hello, how can I help you today?",
"start_time_seconds": 0.01,
"end_time_seconds": 2.5,
"speaker_id": "0"
},
{
"transcript": "I have a question about my order.",
"start_time_seconds": 2.8,
"end_time_seconds": 5.2,
"speaker_id": "1"
}
]
},
"language_code": "en-IN"
}

Each entry contains:

  • transcript: The text spoken by the speaker
  • start_time_seconds: When the speaker started speaking (float)
  • end_time_seconds: When the speaker stopped speaking (float)
  • speaker_id: Unique identifier for the speaker (e.g., “0”, “1”)

Use Cases

Use CaseRecommended Settings
Call center recordingsnum_speakers=2
MeetingsLet model auto-detect
InterviewsSpecify exact count
Podcastsnum_speakers=2-4

Speaker diarization is available via the Batch API and has separate pricing. See the pricing page for detailed rates.

→ Full Batch API Documentation