How to Use Google Cloud Speech-to-Text Speaker Diarization
Learn how to enable speaker diarization in Google Cloud Speech-to-Text, request speaker labels with a JSON configuration, and check the transcript output.
Before you start
Google Cloud diarization does not run on the local device. You send an audio file to the Speech-to-Text API and receive a transcript with optional speaker tags. A local microphone or other input device can create the recording, but it is not used for recognition during the API request.
- Check that the recording has one audio track with audible speech from two or more people.
- Use a supported audio encoding and set the correct sample rate in the request, such as 16000 Hz for many telephony recordings or 48000 Hz for higher-quality video audio.
- Reduce continuous background noise before uploading because overlap, music, low input level, and room echo can make speaker boundaries less reliable.
- Confirm that the Google Cloud project has Speech-to-Text enabled and that the request can authenticate.
Step-by-step instructions
Speaker labeling is configured in the same transcription request as speech recognition, not as a separate endpoint. The available options depend on the API version and client library that you use.
- Open the Speech-to-Text section in the Google Cloud console or prepare a client-library script with the Speech-to-Text package installed.
- Upload or reference the audio source in Cloud Storage if the recording is longer than the inline request limit. Short files can be sent inline as base64 content.
- Set the recognition config language code to match the spoken language.
- Enable speaker diarization using enableSpeakerDiarization in the diarizationConfig section.
- Set diarizationSpeakerCount to the expected number of speakers when this is already known. You can also omit or set the minimum value to allow the service to estimate the count, but results may vary with audio quality and turn-taking.
- Submit the long-running or synchronous recognition request according to the audio duration and the client-library method you selected.
- Wait for the operation to finish before reading the results.
{
"config": {
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"languageCode": "en-US",
"diarizationConfig": {
"enableSpeakerDiarization": true,
"minSpeakerCount": 2,
"maxSpeakerCount": 2
}
},
"audio": {
"uri": "gs://your-bucket/meeting-audio.wav"
}
}
The exact field names and nesting can differ between API generations. If one spelling is rejected, check the client-library documentation for the enabled version rather than mixing settings from different releases.
Check the output
- Open the completed operation response and confirm that it contains transcript segments rather than only a single transcript string.
- Look for speakerTag values such as 1 and 2 on the word or segment entries.
- Compare the tagged segments with the recording to see whether a change of speaker matches an actual turn change.
- Read the overall transcript for incorrect words, especially where speakers overlap or talk over each other.
Diarization labels identify speakers only as numeric tags. They do not provide names or identities, and the same tag is not guaranteed to refer to the same person if you send the audio again in a separate operation.
Common problems and next steps
- If the response has no speaker labels, verify that diarization was enabled in the same config used by the completed operation and that the selected API method supports it.
- If all speakers are grouped into one tag, the audio may be recorded at too low an input level, contain too much background noise, or have the speakers too close to one microphone.
- If tags change inside one speaker's turn, avoid adding background music, phone alerts, or side conversation, and check whether the recording is clipped or heavily compressed.
- If the expected number is wrong, provide the known speaker count when the setting is available, or test a cleaner recording with clear pauses between turns.
- Use separate recordings with one speaker close to the microphone when reliable identity labels are required. Diarization alone is not a speaker identification system.