Get started with Chirp 3 Transcription

Source notebook

Repo path: audio/speech/getting-started/get_started_with_chirp_3_transcription.ipynb · Open on GitHub · intro

Uses Chirp 3 with Speech-to-Text V2 for sync, language-auto, diarized batch, and streaming transcription.

Summary

This notebook teaches how to use Chirp 3 through the Google Cloud Speech-to-Text API V2. It walks through project setup, client creation, synchronous recognition from local bytes and Cloud Storage URIs, language-agnostic transcription, batch recognition with speaker diarization saved to Cloud Storage, and simulated streaming recognition from microphone audio chunks.

Key code patterns

Speech client endpoint

client = SpeechClient(
    client_options=ClientOptions(api_endpoint=f"{STT_LOCATION}-speech.googleapis.com")
)
recognizer = client.recognizer_path(PROJECT_ID, STT_LOCATION, "_")
model = "chirp_3"

Creates a regional Speech-to-Text V2 client and default recognizer for Chirp 3 requests.

Synchronous recognition

config = cloud_speech.RecognitionConfig(
    auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
    model=model,
    language_codes=["en-US"],
)
request = cloud_speech.RecognizeRequest(
    recognizer=recognizer,
    config=config,
    content=audio_content,
)
response = client.recognize(request=request)

Shows the basic online recognition pattern for audio under 1 minute.

Language auto detection

config = cloud_speech.RecognitionConfig(
    auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
    model=model,
    language_codes=["auto"],
)
request = cloud_speech.RecognizeRequest(
    recognizer=recognizer,
    config=config,
    uri=audio_gcs_uri,
)

Uses language_codes=[“auto”] so Chirp 3 identifies the dominant spoken language.

Batch diarization to GCS

config = cloud_speech.RecognitionConfig(
    auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
    features=cloud_speech.RecognitionFeatures(
        diarization_config=cloud_speech.SpeakerDiarizationConfig(),
    ),
    model=model,
    language_codes=["en-US"],
)
operation = client.batch_recognize(request=request)
response = operation.result(timeout=MAX_AUDIO_LENGTH_SECS)

Combines batch recognition, speaker diarization, and Cloud Storage output for longer audio.

Streaming generator

def create_streaming_requests(audio_file_path):
    yield cloud_speech.StreamingRecognizeRequest(
        recognizer=recognizer,
        streaming_config=cloud_speech.StreamingRecognitionConfig(config=recognition_config),
    )
    with open(audio_file_path, "rb") as f:
        audio_content = f.read()
    for chunk in generate_audio_chunks(audio_content, CHUNK_SIZE):
        yield cloud_speech.StreamingRecognizeRequest(audio=chunk)

Structures streaming_recognize input as one config request followed by audio chunk requests.

Models & APIs used

  • Models: chirp_3
  • APIs / services: Speech-to-Text API V2, Cloud Storage
  • SDKs / libraries: google-cloud-speech, ipywebrtc, google-api-core

When to use this

Use this pattern when building Google Cloud speech transcription workflows with Chirp 3, including multilingual, diarized, batch, or streaming audio.

Gotchas & caveats

  • A Google Cloud project is required and speech.googleapis.com must be enabled.
  • Colab users must authenticate with google.colab.auth.authenticate_user().
  • Application Default Credentials and quota project are configured with gcloud commands.
  • Chirp 3 regional availability matters; the notebook sets STT_LOCATION to us and uses a regional endpoint.
  • Online synchronous recognition is described for audio files less than 1 minute long.
  • Batch diarization output requires a writable Cloud Storage output folder.
  • Streaming demo depends on microphone capture through ipywebrtc and FFmpeg conversion from webm to mp3.
  • The batch operation timeout is set to 8 hours with MAX_AUDIO_LENGTH_SECS.

Best practices

  • Use AutoDetectDecodingConfig so the API detects audio encoding.
  • Use a regional Speech-to-Text endpoint based on STT_LOCATION.
  • Use Cloud Storage URIs for batch recognition inputs and outputs.
  • Use language_codes=[“auto”] for language-agnostic transcription.
  • Configure SpeakerDiarizationConfig inside RecognitionFeatures for diarization.
  • Send streaming recognition as an initial config request followed by audio chunks.