Use models

Preview

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

Use a trained Custom Speech-to-Text model in your productionapplication or benchmarking workflows. As soon as you deploy your model througha dedicated endpoint, you automatically get programmatic access through arecognizer object, which can be used directly through the Cloud Speech-to-Text V2API or in the Google Cloud console.

Before you begin

Ensure you have signed up for a Google Cloud account, created a project, traineda custom speech model, and deployed it using an endpoint.

Perform inference in V2

For a Custom Speech-to-Text model to be ready for use, thestate of the model in theModels tab should beActive, and the dedicatedendpoint in theEndpoints tab must beDeployed.

In our example, where a Google Cloud project ID iscustom-models-walkthrough,the endpoint that corresponds to theCustom Speech-to-Text modelquantum-computing-lectures-custom-model isquantum-computing-lectures-custom-model-prod-endpoint. The region that it'savailable isus-east1, and the batch transcription request is the following:

fromgoogle.api_coreimportclient_optionsfromgoogle.cloud.speech_v2importSpeechClientfromgoogle.cloud.speech_v2.typesimportcloud_speechdefquickstart_v2(project_id:str,audio_file:str,)->cloud_speech.RecognizeResponse:"""Transcribe an audio file."""# Instantiates a clientclient=SpeechClient(client_options=client_options.ClientOptions(api_endpoint="us-east1-speech.googleapis.com"))# Reads a file as byteswithopen(audio_file,"rb")asf:content=f.read()config=cloud_speech.RecognitionConfig(auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),language_codes=["en-US"],model="projects/custom-models-walkthrough/locations/us-east1/endpoints/quantum-computing-lectures-custom-model-prod-endpoint",)request=cloud_speech.RecognizeRequest(recognizer=f"projects/custom-models-walkthrough/locations/us-east1/recognizers/_",config=config,content=content,)# Transcribes the audio into textresponse=client.recognize(request=request)forresultinresponse.results:print(f"Transcript:{result.alternatives[0].transcript}")returnresponse
Note: If you try to create a recognizer object in a different region than theone that the endpoint is created in, the request will fail.

What's next

Follow the resources to take advantage of custom speech models in yourapplication. SeeEvaluate your custommodels.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.