Skip to content

Commit 30c0676

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add Lyria enum for music generation mode for vocalization
PiperOrigin-RevId: 789847872
1 parent a57f7d9 commit 30c0676

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

google/genai/_live_converters.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,13 @@ def _LiveMusicGenerationConfig_to_mldev(
10981098
getv(from_object, ['only_bass_and_drums']),
10991099
)
11001100

1101+
if getv(from_object, ['music_generation_mode']) is not None:
1102+
setv(
1103+
to_object,
1104+
['musicGenerationMode'],
1105+
getv(from_object, ['music_generation_mode']),
1106+
)
1107+
11011108
return to_object
11021109

11031110

@@ -2871,6 +2878,13 @@ def _LiveMusicGenerationConfig_from_mldev(
28712878
getv(from_object, ['onlyBassAndDrums']),
28722879
)
28732880

2881+
if getv(from_object, ['musicGenerationMode']) is not None:
2882+
setv(
2883+
to_object,
2884+
['music_generation_mode'],
2885+
getv(from_object, ['musicGenerationMode']),
2886+
)
2887+
28742888
return to_object
28752889

28762890

google/genai/tests/live/test_live_music.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,19 @@ async def test_async_session_send_config(
186186
)
187187
if vertexai:
188188
with pytest.raises(NotImplementedError):
189-
await session.set_music_generation_config(config=types.LiveMusicGenerationConfig(bpm=140))
189+
await session.set_music_generation_config(
190+
config=types.LiveMusicGenerationConfig(
191+
bpm=140,
192+
music_generation_mode=types.MusicGenerationMode.VOCALIZATION,
193+
)
194+
)
190195
return
191-
await session.set_music_generation_config(config=types.LiveMusicGenerationConfig(bpm=140))
196+
await session.set_music_generation_config(
197+
config=types.LiveMusicGenerationConfig(
198+
bpm=140,
199+
music_generation_mode=types.MusicGenerationMode.VOCALIZATION,
200+
)
201+
)
192202
mock_websocket.send.assert_called_once()
193203
sent_data = json.loads(mock_websocket.send.call_args[0][0])
194204
assert 'musicGenerationConfig' in sent_data

google/genai/types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,22 @@ class Scale(_common.CaseInSensitiveEnum):
672672
"""B major or Ab minor."""
673673

674674

675+
class MusicGenerationMode(_common.CaseInSensitiveEnum):
676+
"""The mode of music generation."""
677+
678+
MUSIC_GENERATION_MODE_UNSPECIFIED = 'MUSIC_GENERATION_MODE_UNSPECIFIED'
679+
"""Rely on the server default generation mode."""
680+
QUALITY = 'QUALITY'
681+
"""Steer text prompts to regions of latent space with higher quality
682+
music."""
683+
DIVERSITY = 'DIVERSITY'
684+
"""Steer text prompts to regions of latent space with a larger
685+
diversity of music."""
686+
VOCALIZATION = 'VOCALIZATION'
687+
"""Steer text prompts to regions of latent space more likely to
688+
generate music with vocals."""
689+
690+
675691
class LiveMusicPlaybackControl(_common.CaseInSensitiveEnum):
676692
"""The playback control signal to apply to the music generation."""
677693

@@ -13332,6 +13348,10 @@ class LiveMusicGenerationConfig(_common.BaseModel):
1333213348
default=None,
1333313349
description="""Whether the audio output should contain only bass and drums.""",
1333413350
)
13351+
music_generation_mode: Optional[MusicGenerationMode] = Field(
13352+
default=None,
13353+
description="""The mode of music generation. Default mode is QUALITY.""",
13354+
)
1333513355

1333613356

1333713357
class LiveMusicGenerationConfigDict(TypedDict, total=False):
@@ -13375,6 +13395,9 @@ class LiveMusicGenerationConfigDict(TypedDict, total=False):
1337513395
only_bass_and_drums: Optional[bool]
1337613396
"""Whether the audio output should contain only bass and drums."""
1337713397

13398+
music_generation_mode: Optional[MusicGenerationMode]
13399+
"""The mode of music generation. Default mode is QUALITY."""
13400+
1337813401

1337913402
LiveMusicGenerationConfigOrDict = Union[
1338013403
LiveMusicGenerationConfig, LiveMusicGenerationConfigDict

0 commit comments

Comments
 (0)