Skip to content

Commit 07c74dd

Browse files
MarkDaoustcopybara-github
authored andcommitted
chore: Tests for ReplicatedVoiceConfig
PiperOrigin-RevId: 841593648
1 parent e16706a commit 07c74dd

7 files changed

Lines changed: 232 additions & 138 deletions

File tree

google/genai/_live_converters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,12 @@ def _SpeechConfig_to_vertex(
12651265
parent_object: Optional[dict[str, Any]] = None,
12661266
) -> dict[str, Any]:
12671267
to_object: dict[str, Any] = {}
1268-
if getv(from_object, ['language_code']) is not None:
1269-
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
1270-
12711268
if getv(from_object, ['voice_config']) is not None:
12721269
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))
12731270

1271+
if getv(from_object, ['language_code']) is not None:
1272+
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
1273+
12741274
if getv(from_object, ['multi_speaker_voice_config']) is not None:
12751275
raise ValueError(
12761276
'multi_speaker_voice_config parameter is not supported in Vertex AI.'

google/genai/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,12 +3420,12 @@ def _SpeechConfig_to_vertex(
34203420
parent_object: Optional[dict[str, Any]] = None,
34213421
) -> dict[str, Any]:
34223422
to_object: dict[str, Any] = {}
3423-
if getv(from_object, ['language_code']) is not None:
3424-
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
3425-
34263423
if getv(from_object, ['voice_config']) is not None:
34273424
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))
34283425

3426+
if getv(from_object, ['language_code']) is not None:
3427+
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
3428+
34293429
if getv(from_object, ['multi_speaker_voice_config']) is not None:
34303430
raise ValueError(
34313431
'multi_speaker_voice_config parameter is not supported in Vertex AI.'
96.2 KB
Binary file not shown.

google/genai/tests/live/test_live.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,44 @@ async def test_bidi_setup_error_if_multispeaker_voice_config(vertexai):
808808
)
809809

810810

811+
@pytest.mark.parametrize('vertexai', [True, False])
812+
@pytest.mark.asyncioasync
813+
async def test_replicated_voice_config(vertexai):
814+
# Config is a dict
815+
config_dict = {
816+
'speech_config': {
817+
'voice_config': {
818+
'replicated_voice_config': {
819+
'mime_type': 'audio/pcm',
820+
' voice_sample_audio ': bytes([0, 0, 0]),
821+
},
822+
},
823+
},
824+
}
825+
result = await get_connect_message(
826+
mock_api_client(vertexai=vertexai),
827+
model='test_model',
828+
config=config_dict,
829+
)
830+
assert (
831+
result['setup']['generationConfig']['speechConfig']['voiceConfig'][
832+
'replicatedVoiceConfig'
833+
]
834+
== 'AAAA'
835+
)
836+
837+
838+
@pytest.mark.parametrize('vertexai', [True, False])
839+
@pytest.mark.asyncioasync
840+
async def test_explicit_vad(vertexai):
841+
# Config is a dict
842+
config_dict = {'explicit_vad_signal': True}
843+
result = await get_connect_message(
844+
mock_api_client(vertexai=vertexai), model='test_model', config=config_dict
845+
)
846+
assert result['setup']['explicitVadSignal'] == True
847+
848+
811849
@pytest.mark.parametrize('vertexai', [True, False])
812850
@pytest.mark.asyncio
813851
async def test_bidi_setup_to_api_with_system_instruction_as_content_type(

google/genai/tests/models/test_generate_content.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
# limitations under the License.
1414
#
1515

16-
import base64
17-
import enum
1816
import os
17+
import pathlib
1918

2019
from pydantic import BaseModel, ValidationError, Field, ConfigDict
2120
from typing import Literal, List, Optional, Union, Set
@@ -30,16 +29,16 @@
3029
from .. import pytest_helper
3130
from enum import Enum
3231

33-
IMAGE_PNG_FILE_PATH = os.path.abspath(
34-
os.path.join(os.path.dirname(__file__), '../data/google.png')
35-
)
36-
3732
GEMINI_FLASH_LATEST = 'gemini-2.5-flash'
3833
GEMINI_FLASH_2_0 = 'gemini-2.0-flash-001'
3934
GEMINI_FLASH_IMAGE_LATEST = 'gemini-2.5-flash-image'
4035

41-
with open(IMAGE_PNG_FILE_PATH, 'rb') as image_file:
42-
image_bytes = image_file.read()
36+
IMAGE_PNG_FILE_PATH = pathlib.Path(__file__).parent / '../data/google.png'
37+
image_bytes = IMAGE_PNG_FILE_PATH.read_bytes()
38+
39+
AUDIO_WAV_FILE_PATH = pathlib.Path(__file__).parent / '../data/voice_sample.wav'
40+
audio_bytes = AUDIO_WAV_FILE_PATH.read_bytes()
41+
4342

4443
safety_settings_with_method = [
4544
{
@@ -1964,6 +1963,27 @@ def test_schema_with_any_of(client):
19641963
assert 'type' in response.parsed['fruit'][0]
19651964

19661965

1966+
def test_replicated_voice_config(client):
1967+
with pytest_helper.exception_if_vertex(client, errors.ClientError):
1968+
client.models.generate_content(
1969+
model='gemini-2.5-flash-preview-tts-voice-replication-rev22-2025-10-28',
1970+
contents=t.t_contents(
1971+
'Produce a speech response saying "Cheese"'
1972+
),
1973+
config=types.GenerateContentConfig(
1974+
response_modalities=['audio'],
1975+
speech_config=types.SpeechConfig(
1976+
voice_config=types.VoiceConfig(
1977+
replicated_voice_config=types.ReplicatedVoiceConfig(
1978+
voice_sample_audio=audio_bytes,
1979+
mime_type='audio/wav',
1980+
)
1981+
)
1982+
),
1983+
),
1984+
)
1985+
1986+
19671987
def test_json_schema_with_streaming(client):
19681988

19691989
response = client.models.generate_content_stream(

google/genai/tunings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,12 @@ def _SpeechConfig_to_vertex(
867867
root_object: Optional[Union[dict[str, Any], object]] = None,
868868
) -> dict[str, Any]:
869869
to_object: dict[str, Any] = {}
870-
if getv(from_object, ['language_code']) is not None:
871-
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
872-
873870
if getv(from_object, ['voice_config']) is not None:
874871
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))
875872

873+
if getv(from_object, ['language_code']) is not None:
874+
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
875+
876876
if getv(from_object, ['multi_speaker_voice_config']) is not None:
877877
raise ValueError(
878878
'multi_speaker_voice_config parameter is not supported in Vertex AI.'

0 commit comments

Comments
 (0)