From 3aa251778d4bff8ac2b15632cee29fbf12ddd1ba Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Tue, 21 Jul 2026 12:51:14 -0700 Subject: [PATCH] feat: Add flat `language_codes` field to `AudioTranscriptionConfig`. PiperOrigin-RevId: 951647323 --- .../types/interactions/transcriptionconfig.py | 21 ++++--- google/genai/_live_converters.py | 56 ++----------------- google/genai/_tokens_converters.py | 48 +--------------- google/genai/batches.py | 44 +-------------- google/genai/models.py | 47 +--------------- google/genai/types.py | 25 ++++----- 6 files changed, 30 insertions(+), 211 deletions(-) diff --git a/google/genai/_gaos/types/interactions/transcriptionconfig.py b/google/genai/_gaos/types/interactions/transcriptionconfig.py index b0453f19e..f86a67495 100644 --- a/google/genai/_gaos/types/interactions/transcriptionconfig.py +++ b/google/genai/_gaos/types/interactions/transcriptionconfig.py @@ -27,11 +27,6 @@ class TranscriptionConfigParam(TypedDict): r"""Configuration for speech recognition (transcription).""" - language_hints: List[str] - r"""Required. BCP-47 language codes providing hints about the languages present in the - audio. At least one must be specified, or set to [\"auto\"] to enable - automatic language detection. - """ adaptation_phrases: NotRequired[List[str]] r"""Optional. A list of phrases to bias the ASR model towards.""" custom_vocabulary: NotRequired[List[str]] @@ -40,6 +35,10 @@ class TranscriptionConfigParam(TypedDict): """ diarization_mode: NotRequired[str] r"""Optional. Configures speaker diarization. Supported values: \"speaker\".""" + language_codes: NotRequired[List[str]] + r"""Optional. BCP-47 language codes providing hints about the languages present in the + audio. If omitted or empty, defaults to automatic language detection. + """ timestamp_granularities: NotRequired[List[str]] r"""Optional. The granularity of timestamps to include in the transcription output. Supported values: \"word\". If empty, no timestamps are generated. @@ -49,12 +48,6 @@ class TranscriptionConfigParam(TypedDict): class TranscriptionConfig(BaseModel): r"""Configuration for speech recognition (transcription).""" - language_hints: List[str] - r"""Required. BCP-47 language codes providing hints about the languages present in the - audio. At least one must be specified, or set to [\"auto\"] to enable - automatic language detection. - """ - adaptation_phrases: Annotated[ Optional[List[str]], pydantic.Field( @@ -71,6 +64,11 @@ class TranscriptionConfig(BaseModel): diarization_mode: Optional[str] = None r"""Optional. Configures speaker diarization. Supported values: \"speaker\".""" + language_codes: Optional[List[str]] = None + r"""Optional. BCP-47 language codes providing hints about the languages present in the + audio. If omitted or empty, defaults to automatic language detection. + """ + timestamp_granularities: Optional[List[str]] = None r"""Optional. The granularity of timestamps to include in the transcription output. Supported values: \"word\". If empty, no timestamps are generated. @@ -83,6 +81,7 @@ def serialize_model(self, handler): "adaptation_phrases", "custom_vocabulary", "diarization_mode", + "language_codes", "timestamp_granularities", ] ) diff --git a/google/genai/_live_converters.py b/google/genai/_live_converters.py index d3ca54c5e..165ac5f98 100644 --- a/google/genai/_live_converters.py +++ b/google/genai/_live_converters.py @@ -23,46 +23,6 @@ from ._common import set_value_by_path as setv -def _AudioTranscriptionConfig_to_mldev( - from_object: Union[dict[str, Any], object], - parent_object: Optional[dict[str, Any]] = None, -) -> dict[str, Any]: - to_object: dict[str, Any] = {} - if getv(from_object, ['language_codes']) is not None: - raise ValueError( - 'language_codes parameter is only supported in Gemini Enterprise Agent' - ' Platform mode, not in Gemini Developer API mode.' - ) - - if getv(from_object, ['language_auto']) is not None: - setv(to_object, ['languageAuto'], getv(from_object, ['language_auto'])) - - if getv(from_object, ['language_hints']) is not None: - setv(to_object, ['languageHints'], getv(from_object, ['language_hints'])) - - if getv(from_object, ['custom_vocabulary']) is not None: - setv( - to_object, - ['customVocabulary'], - getv(from_object, ['custom_vocabulary']), - ) - - if getv(from_object, ['adaptation_phrases']) is not None: - setv( - to_object, - ['adaptationPhrases'], - getv(from_object, ['adaptation_phrases']), - ) - - if getv(from_object, ['word_timestamp']) is not None: - setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp'])) - - if getv(from_object, ['diarization']) is not None: - setv(to_object, ['diarization'], getv(from_object, ['diarization'])) - - return to_object - - def _AuthConfig_to_mldev( from_object: Union[dict[str, Any], object], parent_object: Optional[dict[str, Any]] = None, @@ -733,18 +693,14 @@ def _LiveClientSetup_to_mldev( setv( to_object, ['inputAudioTranscription'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['input_audio_transcription']), to_object - ), + getv(from_object, ['input_audio_transcription']), ) if getv(from_object, ['output_audio_transcription']) is not None: setv( to_object, ['outputAudioTranscription'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['output_audio_transcription']), to_object - ), + getv(from_object, ['output_audio_transcription']), ) if getv(from_object, ['proactivity']) is not None: @@ -982,18 +938,14 @@ def _LiveConnectConfig_to_mldev( setv( parent_object, ['setup', 'inputAudioTranscription'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['input_audio_transcription']), to_object - ), + getv(from_object, ['input_audio_transcription']), ) if getv(from_object, ['output_audio_transcription']) is not None: setv( parent_object, ['setup', 'outputAudioTranscription'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['output_audio_transcription']), to_object - ), + getv(from_object, ['output_audio_transcription']), ) if getv(from_object, ['realtime_input_config']) is not None: diff --git a/google/genai/_tokens_converters.py b/google/genai/_tokens_converters.py index f408a8a3e..acfdb0eef 100644 --- a/google/genai/_tokens_converters.py +++ b/google/genai/_tokens_converters.py @@ -23,46 +23,6 @@ from ._common import set_value_by_path as setv -def _AudioTranscriptionConfig_to_mldev( - from_object: Union[dict[str, Any], object], - parent_object: Optional[dict[str, Any]] = None, -) -> dict[str, Any]: - to_object: dict[str, Any] = {} - if getv(from_object, ['language_codes']) is not None: - raise ValueError( - 'language_codes parameter is only supported in Gemini Enterprise Agent' - ' Platform mode, not in Gemini Developer API mode.' - ) - - if getv(from_object, ['language_auto']) is not None: - setv(to_object, ['languageAuto'], getv(from_object, ['language_auto'])) - - if getv(from_object, ['language_hints']) is not None: - setv(to_object, ['languageHints'], getv(from_object, ['language_hints'])) - - if getv(from_object, ['custom_vocabulary']) is not None: - setv( - to_object, - ['customVocabulary'], - getv(from_object, ['custom_vocabulary']), - ) - - if getv(from_object, ['adaptation_phrases']) is not None: - setv( - to_object, - ['adaptationPhrases'], - getv(from_object, ['adaptation_phrases']), - ) - - if getv(from_object, ['word_timestamp']) is not None: - setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp'])) - - if getv(from_object, ['diarization']) is not None: - setv(to_object, ['diarization'], getv(from_object, ['diarization'])) - - return to_object - - def _AuthConfig_to_mldev( from_object: Union[dict[str, Any], object], parent_object: Optional[dict[str, Any]] = None, @@ -435,18 +395,14 @@ def _LiveConnectConfig_to_mldev( setv( parent_object, ['setup', 'inputAudioTranscription'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['input_audio_transcription']), to_object - ), + getv(from_object, ['input_audio_transcription']), ) if getv(from_object, ['output_audio_transcription']) is not None: setv( parent_object, ['setup', 'outputAudioTranscription'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['output_audio_transcription']), to_object - ), + getv(from_object, ['output_audio_transcription']), ) if getv(from_object, ['realtime_input_config']) is not None: diff --git a/google/genai/batches.py b/google/genai/batches.py index eebf003f5..55dfd786e 100644 --- a/google/genai/batches.py +++ b/google/genai/batches.py @@ -34,46 +34,6 @@ logger = logging.getLogger('google_genai.batches') -def _AudioTranscriptionConfig_to_mldev( - from_object: Union[dict[str, Any], object], - parent_object: Optional[dict[str, Any]] = None, -) -> dict[str, Any]: - to_object: dict[str, Any] = {} - if getv(from_object, ['language_codes']) is not None: - raise ValueError( - 'language_codes parameter is only supported in Gemini Enterprise Agent' - ' Platform mode, not in Gemini Developer API mode.' - ) - - if getv(from_object, ['language_auto']) is not None: - setv(to_object, ['languageAuto'], getv(from_object, ['language_auto'])) - - if getv(from_object, ['language_hints']) is not None: - setv(to_object, ['languageHints'], getv(from_object, ['language_hints'])) - - if getv(from_object, ['custom_vocabulary']) is not None: - setv( - to_object, - ['customVocabulary'], - getv(from_object, ['custom_vocabulary']), - ) - - if getv(from_object, ['adaptation_phrases']) is not None: - setv( - to_object, - ['adaptationPhrases'], - getv(from_object, ['adaptation_phrases']), - ) - - if getv(from_object, ['word_timestamp']) is not None: - setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp'])) - - if getv(from_object, ['diarization']) is not None: - setv(to_object, ['diarization'], getv(from_object, ['diarization'])) - - return to_object - - def _AuthConfig_to_mldev( from_object: Union[dict[str, Any], object], parent_object: Optional[dict[str, Any]] = None, @@ -1226,9 +1186,7 @@ def _GenerateContentConfig_to_mldev( setv( to_object, ['audioTranscriptionConfig'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['audio_transcription_config']), to_object - ), + getv(from_object, ['audio_transcription_config']), ) return to_object diff --git a/google/genai/models.py b/google/genai/models.py index 7bb3a8aed..861b030d0 100644 --- a/google/genai/models.py +++ b/google/genai/models.py @@ -65,47 +65,6 @@ def _VideoGenerationReferenceType_to_mldev_enum_validate( ) -def _AudioTranscriptionConfig_to_mldev( - from_object: Union[dict[str, Any], object], - parent_object: Optional[dict[str, Any]] = None, - root_object: Optional[Union[dict[str, Any], object]] = None, -) -> dict[str, Any]: - to_object: dict[str, Any] = {} - if getv(from_object, ['language_codes']) is not None: - raise ValueError( - 'language_codes parameter is only supported in Gemini Enterprise Agent' - ' Platform mode, not in Gemini Developer API mode.' - ) - - if getv(from_object, ['language_auto']) is not None: - setv(to_object, ['languageAuto'], getv(from_object, ['language_auto'])) - - if getv(from_object, ['language_hints']) is not None: - setv(to_object, ['languageHints'], getv(from_object, ['language_hints'])) - - if getv(from_object, ['custom_vocabulary']) is not None: - setv( - to_object, - ['customVocabulary'], - getv(from_object, ['custom_vocabulary']), - ) - - if getv(from_object, ['adaptation_phrases']) is not None: - setv( - to_object, - ['adaptationPhrases'], - getv(from_object, ['adaptation_phrases']), - ) - - if getv(from_object, ['word_timestamp']) is not None: - setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp'])) - - if getv(from_object, ['diarization']) is not None: - setv(to_object, ['diarization'], getv(from_object, ['diarization'])) - - return to_object - - def _AuthConfig_to_mldev( from_object: Union[dict[str, Any], object], parent_object: Optional[dict[str, Any]] = None, @@ -1508,11 +1467,7 @@ def _GenerateContentConfig_to_mldev( setv( to_object, ['audioTranscriptionConfig'], - _AudioTranscriptionConfig_to_mldev( - getv(from_object, ['audio_transcription_config']), - to_object, - root_object, - ), + getv(from_object, ['audio_transcription_config']), ) return to_object diff --git a/google/genai/types.py b/google/genai/types.py index d5d04ea46..f1831d51c 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -6156,13 +6156,13 @@ class ModelArmorConfigDict(TypedDict, total=False): class LanguageAuto(_common.BaseModel): - """Indicates the language of the audio should be automatically detected.""" + """Deprecated: Language auto-detection is now the default when language_codes is omitted.""" pass class LanguageAutoDict(TypedDict, total=False): - """Indicates the language of the audio should be automatically detected.""" + """Deprecated: Language auto-detection is now the default when language_codes is omitted.""" pass @@ -6171,19 +6171,18 @@ class LanguageAutoDict(TypedDict, total=False): class LanguageHints(_common.BaseModel): - """Provides hints to the model about possible languages present in the audio.""" + """Deprecated: Use AudioTranscriptionConfig.language_codes instead.""" language_codes: Optional[list[str]] = Field( - default=None, - description="""BCP-47 language codes. At least one must be specified.""", + default=None, description="""Deprecated. BCP-47 language codes.""" ) class LanguageHintsDict(TypedDict, total=False): - """Provides hints to the model about possible languages present in the audio.""" + """Deprecated: Use AudioTranscriptionConfig.language_codes instead.""" language_codes: Optional[list[str]] - """BCP-47 language codes. At least one must be specified.""" + """Deprecated. BCP-47 language codes.""" LanguageHintsOrDict = Union[LanguageHints, LanguageHintsDict] @@ -6194,15 +6193,15 @@ class AudioTranscriptionConfig(_common.BaseModel): language_codes: Optional[list[str]] = Field( default=None, - description="""Deprecated: use LanguageAuto or LanguageHints instead.""", + description="""BCP-47 language codes providing hints about the languages present in the audio. If omitted or empty, defaults to automatic language detection.""", ) language_auto: Optional[LanguageAuto] = Field( default=None, - description="""The model will detect the language automatically. Do not use together with LanguageHints.""", + description="""Deprecated: Auto-detection is now the default when language_codes is omitted. This field will be removed in a future version.""", ) language_hints: Optional[LanguageHints] = Field( default=None, - description="""Specifies one or more languages in the audio. Do not use together with LanguageAuto.""", + description="""Deprecated: Use top-level language_codes instead. This field will be removed in a future version.""", ) custom_vocabulary: Optional[list[str]] = Field( default=None, @@ -6228,13 +6227,13 @@ class AudioTranscriptionConfigDict(TypedDict, total=False): """The audio transcription configuration in Setup.""" language_codes: Optional[list[str]] - """Deprecated: use LanguageAuto or LanguageHints instead.""" + """BCP-47 language codes providing hints about the languages present in the audio. If omitted or empty, defaults to automatic language detection.""" language_auto: Optional[LanguageAutoDict] - """The model will detect the language automatically. Do not use together with LanguageHints.""" + """Deprecated: Auto-detection is now the default when language_codes is omitted. This field will be removed in a future version.""" language_hints: Optional[LanguageHintsDict] - """Specifies one or more languages in the audio. Do not use together with LanguageAuto.""" + """Deprecated: Use top-level language_codes instead. This field will be removed in a future version.""" custom_vocabulary: Optional[list[str]] """A list of custom vocabulary phrases, which biases the ASR model to improve recognition of these specific terms."""