google_utils#

Additional utilities for working with the Google Cloud steps.

voice_stream.integrations.google_utils._resolve_audio_decoding(audio_format)#
async voice_stream.integrations.google_utils.create_recognizer(client: SpeechAsyncClient, project_id: str, location: str, recognizer_id: str, model: str, language_codes: str | list[str], audio_format: AudioFormat | ExplicitDecodingConfig | None = None)#

Helper function to create a Google Speech V2 recognizer in a Google Cloud project.

With Google Speech V2, you need to create a recognizer first before you can run speech recognition. The V1 API uses a fixed set of recognizers and doesn’t require this step. This function sets up and initializes a speech recognizer with the specified configuration options.

Parameters:
  • client (SpeechAsyncClient) – An instance of SpeechAsyncClient for interacting with the Google Cloud Speech API.

  • project_id (str) – The ID of the Google Cloud project where the recognizer is to be created.

  • location (str) – The location or region where the recognizer is to be deployed.

  • recognizer_id (str) – The unique identifier for the recognizer within the project.

  • model (str) – The model to be used by the recognizer for speech recognition.

  • language_codes (Union[str, list[str]]) – The language code(s) for the recognizer. Can be a single string or a list of strings.

  • audio_format (GoogleDecodingConfig, optional) – Optional configuration for audio decoding. If not specified, the recognizer will auto-detect the audio configuration.

Notes

  • The function handles the creation and configuration of a recognizer in an asynchronous manner, utilizing the SpeechAsyncClient.

  • It constructs the necessary request with the provided parameters and sends it to the Google Cloud Speech API.

  • After the recognizer is successfully created, the function logs its name for confirmation.

Examples

>>> await create_recognizer(client, "my-project", "us-west1", "my-recognizer", "phone_call", "en-US")

This example demonstrates how to create a recognizer for English language phone calls in the ‘us-west1’ region of the ‘my-project’ Google Cloud project.