From 5b52faaca37744c6a79b2bb37b3204229c445121 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Mon, 20 Jul 2026 11:43:58 -0700 Subject: [PATCH] feat: make ASR fields public in v1main and Interactions PiperOrigin-RevId: 950964813 --- .../_gaos/resources/interactions/__init__.py | 4 + .../_gaos/types/interactions/__init__.py | 10 ++ .../_gaos/types/interactions/annotation.py | 7 +- .../types/interactions/generationconfig.py | 7 + .../types/interactions/transcriptionconfig.py | 100 ++++++++++++++ .../_gaos/types/interactions/wordinfo.py | 124 ++++++++++++++++++ 6 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 google/genai/_gaos/types/interactions/transcriptionconfig.py create mode 100644 google/genai/_gaos/types/interactions/wordinfo.py diff --git a/google/genai/_gaos/resources/interactions/__init__.py b/google/genai/_gaos/resources/interactions/__init__.py index 53589a0cc..7ad864ad5 100644 --- a/google/genai/_gaos/resources/interactions/__init__.py +++ b/google/genai/_gaos/resources/interactions/__init__.py @@ -95,6 +95,7 @@ from ...types.interactions.tool import Tool from ...types.interactions.toolchoiceconfig import ToolChoiceConfig from ...types.interactions.toolchoicetype import ToolChoiceType +from ...types.interactions.transcriptionconfig import TranscriptionConfig from ...types.interactions.urlcitation import URLCitation from ...types.interactions.urlcontextcallarguments import URLContextCallArguments from ...types.interactions.urlcontextcallstep import URLContextCallStep @@ -106,6 +107,7 @@ from ...types.interactions.videocontent import VideoContent from ...types.interactions.videoresponseformat import VideoResponseFormat from ...types.interactions.webhookconfig import WebhookConfig +from ...types.interactions.wordinfo import WordInfo from . import codeexecutioncallstep from . import codemenderagentconfig from . import environment @@ -201,6 +203,7 @@ "Tool", "ToolChoiceConfig", "ToolChoiceType", + "TranscriptionConfig", "URLCitation", "URLContextCallArguments", "URLContextCallStep", @@ -212,6 +215,7 @@ "VideoContent", "VideoResponseFormat", "WebhookConfig", + "WordInfo", "codeexecutioncallstep", "codemenderagentconfig", "environment", diff --git a/google/genai/_gaos/types/interactions/__init__.py b/google/genai/_gaos/types/interactions/__init__.py index 8a2efd152..db3da3032 100644 --- a/google/genai/_gaos/types/interactions/__init__.py +++ b/google/genai/_gaos/types/interactions/__init__.py @@ -446,6 +446,7 @@ from .tool import Tool, ToolParam, UnknownTool from .toolchoiceconfig import ToolChoiceConfig, ToolChoiceConfigParam from .toolchoicetype import ToolChoiceType + from .transcriptionconfig import TranscriptionConfig, TranscriptionConfigParam from .turn import Turn, TurnContent, TurnContentParam, TurnParam from .urlcitation import URLCitation, URLCitationParam from .urlcontext import URLContext, URLContextParam @@ -478,6 +479,7 @@ VideoResponseFormatParam, ) from .webhookconfig import WebhookConfig, WebhookConfigParam + from .wordinfo import WordInfo, WordInfoParam __all__ = [ "AgentOption", @@ -869,6 +871,8 @@ "ToolChoiceParam", "ToolChoiceType", "ToolParam", + "TranscriptionConfig", + "TranscriptionConfigParam", "Transform", "TransformParam", "Turn", @@ -922,6 +926,8 @@ "Visualization", "WebhookConfig", "WebhookConfigParam", + "WordInfo", + "WordInfoParam", ] _dynamic_imports: dict[str, str] = { @@ -1325,6 +1331,8 @@ "ToolChoiceConfig": ".toolchoiceconfig", "ToolChoiceConfigParam": ".toolchoiceconfig", "ToolChoiceType": ".toolchoicetype", + "TranscriptionConfig": ".transcriptionconfig", + "TranscriptionConfigParam": ".transcriptionconfig", "Turn": ".turn", "TurnContent": ".turn", "TurnContentParam": ".turn", @@ -1367,6 +1375,8 @@ "VideoResponseFormatParam": ".videoresponseformat", "WebhookConfig": ".webhookconfig", "WebhookConfigParam": ".webhookconfig", + "WordInfo": ".wordinfo", + "WordInfoParam": ".wordinfo", } diff --git a/google/genai/_gaos/types/interactions/annotation.py b/google/genai/_gaos/types/interactions/annotation.py index 481e76053..13ef5977b 100644 --- a/google/genai/_gaos/types/interactions/annotation.py +++ b/google/genai/_gaos/types/interactions/annotation.py @@ -22,6 +22,7 @@ from .filecitation import FileCitation, FileCitationParam from .placecitation import PlaceCitation, PlaceCitationParam from .urlcitation import URLCitation, URLCitationParam +from .wordinfo import WordInfo, WordInfoParam from functools import partial from pydantic import ConfigDict from pydantic.functional_validators import BeforeValidator @@ -30,7 +31,8 @@ AnnotationParam = TypeAliasType( - "AnnotationParam", Union[URLCitationParam, PlaceCitationParam, FileCitationParam] + "AnnotationParam", + Union[URLCitationParam, PlaceCitationParam, WordInfoParam, FileCitationParam], ) r"""Citation information for model-generated content.""" @@ -49,11 +51,12 @@ class UnknownAnnotation(BaseModel): "url_citation": URLCitation, "file_citation": FileCitation, "place_citation": PlaceCitation, + "word_info": WordInfo, } Annotation = Annotated[ - Union[URLCitation, FileCitation, PlaceCitation, UnknownAnnotation], + Union[URLCitation, FileCitation, PlaceCitation, WordInfo, UnknownAnnotation], BeforeValidator( partial( parse_open_union, diff --git a/google/genai/_gaos/types/interactions/generationconfig.py b/google/genai/_gaos/types/interactions/generationconfig.py index 64dcefea9..afefb0d01 100644 --- a/google/genai/_gaos/types/interactions/generationconfig.py +++ b/google/genai/_gaos/types/interactions/generationconfig.py @@ -24,6 +24,7 @@ from .thinkingsummaries import ThinkingSummaries from .toolchoiceconfig import ToolChoiceConfig, ToolChoiceConfigParam from .toolchoicetype import ToolChoiceType +from .transcriptionconfig import TranscriptionConfig, TranscriptionConfigParam from .videoconfig import VideoConfig, VideoConfigParam import pydantic from pydantic import model_serializer @@ -62,6 +63,8 @@ class GenerationConfigParam(TypedDict): r"""The tool choice configuration.""" top_p: NotRequired[float] r"""The maximum cumulative probability of tokens to consider when sampling.""" + transcription_config: NotRequired[TranscriptionConfigParam] + r"""Configuration for speech recognition (transcription).""" video_config: NotRequired[VideoConfigParam] r"""Configuration options for video generation.""" @@ -102,6 +105,9 @@ class GenerationConfig(BaseModel): top_p: Optional[float] = None r"""The maximum cumulative probability of tokens to consider when sampling.""" + transcription_config: Optional[TranscriptionConfig] = None + r"""Configuration for speech recognition (transcription).""" + video_config: Optional[VideoConfig] = None r"""Configuration options for video generation.""" @@ -119,6 +125,7 @@ def serialize_model(self, handler): "thinking_summaries", "tool_choice", "top_p", + "transcription_config", "video_config", ] ) diff --git a/google/genai/_gaos/types/interactions/transcriptionconfig.py b/google/genai/_gaos/types/interactions/transcriptionconfig.py new file mode 100644 index 000000000..b0453f19e --- /dev/null +++ b/google/genai/_gaos/types/interactions/transcriptionconfig.py @@ -0,0 +1,100 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pyformat: disable + +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" + +from __future__ import annotations +from .. import BaseModel, UNSET_SENTINEL +import pydantic +from pydantic import model_serializer +from typing import List, Optional +from typing_extensions import Annotated, NotRequired, TypedDict + + +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]] + r"""Optional. A list of custom vocabulary phrases to bias the speech recognition model + toward recognizing specific terms. + """ + diarization_mode: NotRequired[str] + r"""Optional. Configures speaker diarization. Supported values: \"speaker\".""" + 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. + """ + + +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( + deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible." + ), + ] = None + r"""Optional. A list of phrases to bias the ASR model towards.""" + + custom_vocabulary: Optional[List[str]] = None + r"""Optional. A list of custom vocabulary phrases to bias the speech recognition model + toward recognizing specific terms. + """ + + diarization_mode: Optional[str] = None + r"""Optional. Configures speaker diarization. Supported values: \"speaker\".""" + + 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. + """ + + @model_serializer(mode="wrap") + def serialize_model(self, handler): + optional_fields = set( + [ + "adaptation_phrases", + "custom_vocabulary", + "diarization_mode", + "timestamp_granularities", + ] + ) + serialized = handler(self) + m = {} + + for n, f in type(self).model_fields.items(): + k = f.alias or n + val = serialized.get(k, serialized.get(n)) + + if val != UNSET_SENTINEL: + if val is not None or k not in optional_fields: + m[k] = val + + return m diff --git a/google/genai/_gaos/types/interactions/wordinfo.py b/google/genai/_gaos/types/interactions/wordinfo.py new file mode 100644 index 000000000..d2431219e --- /dev/null +++ b/google/genai/_gaos/types/interactions/wordinfo.py @@ -0,0 +1,124 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pyformat: disable + +"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" + +from __future__ import annotations +from .. import BaseModel, UNSET_SENTINEL +from ...utils import validate_const +import pydantic +from pydantic import model_serializer +from pydantic.functional_validators import AfterValidator +from typing import Literal, Optional +from typing_extensions import Annotated, NotRequired, TypedDict + + +class WordInfoParam(TypedDict): + r"""Word-level ASR annotation for transcription output. + Carries the word text, optional timing, and optional speaker attribution. + """ + + end_index: NotRequired[int] + r"""End of the attributed segment, exclusive.""" + end_offset: NotRequired[str] + r"""End offset in time of the word relative to the start of the audio. + Present when timestamp_granularities contains \"word\". + """ + speaker: NotRequired[str] + r"""Optional. Speaker label for this word (e.g. \"spk_1\", \"spk_2\"). + Present when diarization_mode is set in TranscriptionConfig. + """ + start_index: NotRequired[int] + r"""Start of segment of the response that is attributed to this source. + + Index indicates the start of the segment, measured in bytes. + """ + start_offset: NotRequired[str] + r"""Start offset in time of the word relative to the start of the audio. + Present when timestamp_granularities contains \"word\". + """ + text: NotRequired[str] + r"""The transcribed word.""" + type: Literal["word_info"] + + +class WordInfo(BaseModel): + r"""Word-level ASR annotation for transcription output. + Carries the word text, optional timing, and optional speaker attribution. + """ + + end_index: Optional[int] = None + r"""End of the attributed segment, exclusive.""" + + end_offset: Optional[str] = None + r"""End offset in time of the word relative to the start of the audio. + Present when timestamp_granularities contains \"word\". + """ + + speaker: Optional[str] = None + r"""Optional. Speaker label for this word (e.g. \"spk_1\", \"spk_2\"). + Present when diarization_mode is set in TranscriptionConfig. + """ + + start_index: Optional[int] = None + r"""Start of segment of the response that is attributed to this source. + + Index indicates the start of the segment, measured in bytes. + """ + + start_offset: Optional[str] = None + r"""Start offset in time of the word relative to the start of the audio. + Present when timestamp_granularities contains \"word\". + """ + + text: Optional[str] = None + r"""The transcribed word.""" + + type: Annotated[ + Annotated[Literal["word_info"], AfterValidator(validate_const("word_info"))], + pydantic.Field(alias="type"), + ] = "word_info" + + @model_serializer(mode="wrap") + def serialize_model(self, handler): + optional_fields = set( + [ + "end_index", + "end_offset", + "speaker", + "start_index", + "start_offset", + "text", + ] + ) + serialized = handler(self) + m = {} + + for n, f in type(self).model_fields.items(): + k = f.alias or n + val = serialized.get(k, serialized.get(n)) + + if val != UNSET_SENTINEL: + if val is not None or k not in optional_fields: + m[k] = val + + return m + + +try: + WordInfo.model_rebuild() +except NameError: + pass