Skip to content

Commit fc282b3

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add flat language_codes field to AudioTranscriptionConfig.
PiperOrigin-RevId: 955519477
1 parent 0e38b63 commit fc282b3

6 files changed

Lines changed: 30 additions & 211 deletions

File tree

google/genai/_gaos/types/interactions/transcriptionconfig.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
class TranscriptionConfigParam(TypedDict):
2828
r"""Configuration for speech recognition (transcription)."""
2929

30-
language_hints: List[str]
31-
r"""Required. BCP-47 language codes providing hints about the languages present in the
32-
audio. At least one must be specified, or set to [\"auto\"] to enable
33-
automatic language detection.
34-
"""
3530
adaptation_phrases: NotRequired[List[str]]
3631
r"""Optional. A list of phrases to bias the ASR model towards."""
3732
custom_vocabulary: NotRequired[List[str]]
@@ -40,6 +35,10 @@ class TranscriptionConfigParam(TypedDict):
4035
"""
4136
diarization_mode: NotRequired[str]
4237
r"""Optional. Configures speaker diarization. Supported values: \"speaker\"."""
38+
language_codes: NotRequired[List[str]]
39+
r"""Optional. BCP-47 language codes providing hints about the languages present in the
40+
audio. If omitted or empty, defaults to automatic language detection.
41+
"""
4342
timestamp_granularities: NotRequired[List[str]]
4443
r"""Optional. The granularity of timestamps to include in the transcription output.
4544
Supported values: \"word\". If empty, no timestamps are generated.
@@ -49,12 +48,6 @@ class TranscriptionConfigParam(TypedDict):
4948
class TranscriptionConfig(BaseModel):
5049
r"""Configuration for speech recognition (transcription)."""
5150

52-
language_hints: List[str]
53-
r"""Required. BCP-47 language codes providing hints about the languages present in the
54-
audio. At least one must be specified, or set to [\"auto\"] to enable
55-
automatic language detection.
56-
"""
57-
5851
adaptation_phrases: Annotated[
5952
Optional[List[str]],
6053
pydantic.Field(
@@ -71,6 +64,11 @@ class TranscriptionConfig(BaseModel):
7164
diarization_mode: Optional[str] = None
7265
r"""Optional. Configures speaker diarization. Supported values: \"speaker\"."""
7366

67+
language_codes: Optional[List[str]] = None
68+
r"""Optional. BCP-47 language codes providing hints about the languages present in the
69+
audio. If omitted or empty, defaults to automatic language detection.
70+
"""
71+
7472
timestamp_granularities: Optional[List[str]] = None
7573
r"""Optional. The granularity of timestamps to include in the transcription output.
7674
Supported values: \"word\". If empty, no timestamps are generated.
@@ -83,6 +81,7 @@ def serialize_model(self, handler):
8381
"adaptation_phrases",
8482
"custom_vocabulary",
8583
"diarization_mode",
84+
"language_codes",
8685
"timestamp_granularities",
8786
]
8887
)

google/genai/_live_converters.py

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,6 @@
2323
from ._common import set_value_by_path as setv
2424

2525

26-
def _AudioTranscriptionConfig_to_mldev(
27-
from_object: Union[dict[str, Any], object],
28-
parent_object: Optional[dict[str, Any]] = None,
29-
) -> dict[str, Any]:
30-
to_object: dict[str, Any] = {}
31-
if getv(from_object, ['language_codes']) is not None:
32-
raise ValueError(
33-
'language_codes parameter is only supported in Gemini Enterprise Agent'
34-
' Platform mode, not in Gemini Developer API mode.'
35-
)
36-
37-
if getv(from_object, ['language_auto']) is not None:
38-
setv(to_object, ['languageAuto'], getv(from_object, ['language_auto']))
39-
40-
if getv(from_object, ['language_hints']) is not None:
41-
setv(to_object, ['languageHints'], getv(from_object, ['language_hints']))
42-
43-
if getv(from_object, ['custom_vocabulary']) is not None:
44-
setv(
45-
to_object,
46-
['customVocabulary'],
47-
getv(from_object, ['custom_vocabulary']),
48-
)
49-
50-
if getv(from_object, ['adaptation_phrases']) is not None:
51-
setv(
52-
to_object,
53-
['adaptationPhrases'],
54-
getv(from_object, ['adaptation_phrases']),
55-
)
56-
57-
if getv(from_object, ['word_timestamp']) is not None:
58-
setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp']))
59-
60-
if getv(from_object, ['diarization']) is not None:
61-
setv(to_object, ['diarization'], getv(from_object, ['diarization']))
62-
63-
return to_object
64-
65-
6626
def _AuthConfig_to_mldev(
6727
from_object: Union[dict[str, Any], object],
6828
parent_object: Optional[dict[str, Any]] = None,
@@ -733,18 +693,14 @@ def _LiveClientSetup_to_mldev(
733693
setv(
734694
to_object,
735695
['inputAudioTranscription'],
736-
_AudioTranscriptionConfig_to_mldev(
737-
getv(from_object, ['input_audio_transcription']), to_object
738-
),
696+
getv(from_object, ['input_audio_transcription']),
739697
)
740698

741699
if getv(from_object, ['output_audio_transcription']) is not None:
742700
setv(
743701
to_object,
744702
['outputAudioTranscription'],
745-
_AudioTranscriptionConfig_to_mldev(
746-
getv(from_object, ['output_audio_transcription']), to_object
747-
),
703+
getv(from_object, ['output_audio_transcription']),
748704
)
749705

750706
if getv(from_object, ['proactivity']) is not None:
@@ -982,18 +938,14 @@ def _LiveConnectConfig_to_mldev(
982938
setv(
983939
parent_object,
984940
['setup', 'inputAudioTranscription'],
985-
_AudioTranscriptionConfig_to_mldev(
986-
getv(from_object, ['input_audio_transcription']), to_object
987-
),
941+
getv(from_object, ['input_audio_transcription']),
988942
)
989943

990944
if getv(from_object, ['output_audio_transcription']) is not None:
991945
setv(
992946
parent_object,
993947
['setup', 'outputAudioTranscription'],
994-
_AudioTranscriptionConfig_to_mldev(
995-
getv(from_object, ['output_audio_transcription']), to_object
996-
),
948+
getv(from_object, ['output_audio_transcription']),
997949
)
998950

999951
if getv(from_object, ['realtime_input_config']) is not None:

google/genai/_tokens_converters.py

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,6 @@
2323
from ._common import set_value_by_path as setv
2424

2525

26-
def _AudioTranscriptionConfig_to_mldev(
27-
from_object: Union[dict[str, Any], object],
28-
parent_object: Optional[dict[str, Any]] = None,
29-
) -> dict[str, Any]:
30-
to_object: dict[str, Any] = {}
31-
if getv(from_object, ['language_codes']) is not None:
32-
raise ValueError(
33-
'language_codes parameter is only supported in Gemini Enterprise Agent'
34-
' Platform mode, not in Gemini Developer API mode.'
35-
)
36-
37-
if getv(from_object, ['language_auto']) is not None:
38-
setv(to_object, ['languageAuto'], getv(from_object, ['language_auto']))
39-
40-
if getv(from_object, ['language_hints']) is not None:
41-
setv(to_object, ['languageHints'], getv(from_object, ['language_hints']))
42-
43-
if getv(from_object, ['custom_vocabulary']) is not None:
44-
setv(
45-
to_object,
46-
['customVocabulary'],
47-
getv(from_object, ['custom_vocabulary']),
48-
)
49-
50-
if getv(from_object, ['adaptation_phrases']) is not None:
51-
setv(
52-
to_object,
53-
['adaptationPhrases'],
54-
getv(from_object, ['adaptation_phrases']),
55-
)
56-
57-
if getv(from_object, ['word_timestamp']) is not None:
58-
setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp']))
59-
60-
if getv(from_object, ['diarization']) is not None:
61-
setv(to_object, ['diarization'], getv(from_object, ['diarization']))
62-
63-
return to_object
64-
65-
6626
def _AuthConfig_to_mldev(
6727
from_object: Union[dict[str, Any], object],
6828
parent_object: Optional[dict[str, Any]] = None,
@@ -435,18 +395,14 @@ def _LiveConnectConfig_to_mldev(
435395
setv(
436396
parent_object,
437397
['setup', 'inputAudioTranscription'],
438-
_AudioTranscriptionConfig_to_mldev(
439-
getv(from_object, ['input_audio_transcription']), to_object
440-
),
398+
getv(from_object, ['input_audio_transcription']),
441399
)
442400

443401
if getv(from_object, ['output_audio_transcription']) is not None:
444402
setv(
445403
parent_object,
446404
['setup', 'outputAudioTranscription'],
447-
_AudioTranscriptionConfig_to_mldev(
448-
getv(from_object, ['output_audio_transcription']), to_object
449-
),
405+
getv(from_object, ['output_audio_transcription']),
450406
)
451407

452408
if getv(from_object, ['realtime_input_config']) is not None:

google/genai/batches.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,6 @@
3434
logger = logging.getLogger('google_genai.batches')
3535

3636

37-
def _AudioTranscriptionConfig_to_mldev(
38-
from_object: Union[dict[str, Any], object],
39-
parent_object: Optional[dict[str, Any]] = None,
40-
) -> dict[str, Any]:
41-
to_object: dict[str, Any] = {}
42-
if getv(from_object, ['language_codes']) is not None:
43-
raise ValueError(
44-
'language_codes parameter is only supported in Gemini Enterprise Agent'
45-
' Platform mode, not in Gemini Developer API mode.'
46-
)
47-
48-
if getv(from_object, ['language_auto']) is not None:
49-
setv(to_object, ['languageAuto'], getv(from_object, ['language_auto']))
50-
51-
if getv(from_object, ['language_hints']) is not None:
52-
setv(to_object, ['languageHints'], getv(from_object, ['language_hints']))
53-
54-
if getv(from_object, ['custom_vocabulary']) is not None:
55-
setv(
56-
to_object,
57-
['customVocabulary'],
58-
getv(from_object, ['custom_vocabulary']),
59-
)
60-
61-
if getv(from_object, ['adaptation_phrases']) is not None:
62-
setv(
63-
to_object,
64-
['adaptationPhrases'],
65-
getv(from_object, ['adaptation_phrases']),
66-
)
67-
68-
if getv(from_object, ['word_timestamp']) is not None:
69-
setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp']))
70-
71-
if getv(from_object, ['diarization']) is not None:
72-
setv(to_object, ['diarization'], getv(from_object, ['diarization']))
73-
74-
return to_object
75-
76-
7737
def _AuthConfig_to_mldev(
7838
from_object: Union[dict[str, Any], object],
7939
parent_object: Optional[dict[str, Any]] = None,
@@ -1226,9 +1186,7 @@ def _GenerateContentConfig_to_mldev(
12261186
setv(
12271187
to_object,
12281188
['audioTranscriptionConfig'],
1229-
_AudioTranscriptionConfig_to_mldev(
1230-
getv(from_object, ['audio_transcription_config']), to_object
1231-
),
1189+
getv(from_object, ['audio_transcription_config']),
12321190
)
12331191

12341192
return to_object

google/genai/models.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -65,47 +65,6 @@ def _VideoGenerationReferenceType_to_mldev_enum_validate(
6565
)
6666

6767

68-
def _AudioTranscriptionConfig_to_mldev(
69-
from_object: Union[dict[str, Any], object],
70-
parent_object: Optional[dict[str, Any]] = None,
71-
root_object: Optional[Union[dict[str, Any], object]] = None,
72-
) -> dict[str, Any]:
73-
to_object: dict[str, Any] = {}
74-
if getv(from_object, ['language_codes']) is not None:
75-
raise ValueError(
76-
'language_codes parameter is only supported in Gemini Enterprise Agent'
77-
' Platform mode, not in Gemini Developer API mode.'
78-
)
79-
80-
if getv(from_object, ['language_auto']) is not None:
81-
setv(to_object, ['languageAuto'], getv(from_object, ['language_auto']))
82-
83-
if getv(from_object, ['language_hints']) is not None:
84-
setv(to_object, ['languageHints'], getv(from_object, ['language_hints']))
85-
86-
if getv(from_object, ['custom_vocabulary']) is not None:
87-
setv(
88-
to_object,
89-
['customVocabulary'],
90-
getv(from_object, ['custom_vocabulary']),
91-
)
92-
93-
if getv(from_object, ['adaptation_phrases']) is not None:
94-
setv(
95-
to_object,
96-
['adaptationPhrases'],
97-
getv(from_object, ['adaptation_phrases']),
98-
)
99-
100-
if getv(from_object, ['word_timestamp']) is not None:
101-
setv(to_object, ['wordTimestamp'], getv(from_object, ['word_timestamp']))
102-
103-
if getv(from_object, ['diarization']) is not None:
104-
setv(to_object, ['diarization'], getv(from_object, ['diarization']))
105-
106-
return to_object
107-
108-
10968
def _AuthConfig_to_mldev(
11069
from_object: Union[dict[str, Any], object],
11170
parent_object: Optional[dict[str, Any]] = None,
@@ -1508,11 +1467,7 @@ def _GenerateContentConfig_to_mldev(
15081467
setv(
15091468
to_object,
15101469
['audioTranscriptionConfig'],
1511-
_AudioTranscriptionConfig_to_mldev(
1512-
getv(from_object, ['audio_transcription_config']),
1513-
to_object,
1514-
root_object,
1515-
),
1470+
getv(from_object, ['audio_transcription_config']),
15161471
)
15171472

15181473
return to_object

0 commit comments

Comments
 (0)