Skip to content

Commit c50e47b

Browse files
jscudcopybara-github
authored andcommitted
feat: support multi speaker for Vertex AI
PiperOrigin-RevId: 843858005
1 parent 96cf8a0 commit c50e47b

File tree

4 files changed

+23
-81
lines changed

4 files changed

+23
-81
lines changed

src/main/java/com/google/genai/LiveConverters.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,7 @@ ObjectNode generationConfigToVertex(JsonNode fromObject, ObjectNode parentObject
307307
Common.setValueByPath(
308308
toObject,
309309
new String[] {"speechConfig"},
310-
speechConfigToVertex(
311-
JsonSerializable.toJsonNode(
312-
Common.getValueByPath(fromObject, new String[] {"speechConfig"})),
313-
toObject));
310+
Common.getValueByPath(fromObject, new String[] {"speechConfig"}));
314311
}
315312

316313
if (Common.getValueByPath(fromObject, new String[] {"stopSequences"}) != null) {
@@ -1038,11 +1035,8 @@ ObjectNode liveConnectConfigToVertex(JsonNode fromObject, ObjectNode parentObjec
10381035
Common.setValueByPath(
10391036
parentObject,
10401037
new String[] {"setup", "generationConfig", "speechConfig"},
1041-
speechConfigToVertex(
1042-
JsonSerializable.toJsonNode(
1043-
Transformers.tLiveSpeechConfig(
1044-
Common.getValueByPath(fromObject, new String[] {"speechConfig"}))),
1045-
toObject));
1038+
Transformers.tLiveSpeechConfig(
1039+
Common.getValueByPath(fromObject, new String[] {"speechConfig"})));
10461040
}
10471041

10481042
if (Common.getValueByPath(fromObject, new String[] {"thinkingConfig"}) != null) {
@@ -1480,32 +1474,6 @@ ObjectNode sessionResumptionConfigToMldev(JsonNode fromObject, ObjectNode parent
14801474
return toObject;
14811475
}
14821476

1483-
@ExcludeFromGeneratedCoverageReport
1484-
ObjectNode speechConfigToVertex(JsonNode fromObject, ObjectNode parentObject) {
1485-
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
1486-
if (Common.getValueByPath(fromObject, new String[] {"voiceConfig"}) != null) {
1487-
Common.setValueByPath(
1488-
toObject,
1489-
new String[] {"voiceConfig"},
1490-
Common.getValueByPath(fromObject, new String[] {"voiceConfig"}));
1491-
}
1492-
1493-
if (Common.getValueByPath(fromObject, new String[] {"languageCode"}) != null) {
1494-
Common.setValueByPath(
1495-
toObject,
1496-
new String[] {"languageCode"},
1497-
Common.getValueByPath(fromObject, new String[] {"languageCode"}));
1498-
}
1499-
1500-
if (!Common.isZero(
1501-
Common.getValueByPath(fromObject, new String[] {"multiSpeakerVoiceConfig"}))) {
1502-
throw new IllegalArgumentException(
1503-
"multiSpeakerVoiceConfig parameter is not supported in Vertex AI.");
1504-
}
1505-
1506-
return toObject;
1507-
}
1508-
15091477
@ExcludeFromGeneratedCoverageReport
15101478
ObjectNode toolToMldev(JsonNode fromObject, ObjectNode parentObject) {
15111479
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

src/main/java/com/google/genai/Models.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,11 +1567,8 @@ ObjectNode generateContentConfigToVertex(
15671567
Common.setValueByPath(
15681568
toObject,
15691569
new String[] {"speechConfig"},
1570-
speechConfigToVertex(
1571-
JsonSerializable.toJsonNode(
1572-
Transformers.tSpeechConfig(
1573-
Common.getValueByPath(fromObject, new String[] {"speechConfig"}))),
1574-
toObject));
1570+
Transformers.tSpeechConfig(
1571+
Common.getValueByPath(fromObject, new String[] {"speechConfig"})));
15751572
}
15761573

15771574
if (Common.getValueByPath(fromObject, new String[] {"audioTimestamp"}) != null) {
@@ -2980,10 +2977,7 @@ ObjectNode generationConfigToVertex(JsonNode fromObject, ObjectNode parentObject
29802977
Common.setValueByPath(
29812978
toObject,
29822979
new String[] {"speechConfig"},
2983-
speechConfigToVertex(
2984-
JsonSerializable.toJsonNode(
2985-
Common.getValueByPath(fromObject, new String[] {"speechConfig"})),
2986-
toObject));
2980+
Common.getValueByPath(fromObject, new String[] {"speechConfig"}));
29872981
}
29882982

29892983
if (Common.getValueByPath(fromObject, new String[] {"stopSequences"}) != null) {
@@ -4208,32 +4202,6 @@ ObjectNode segmentImageSourceToVertex(JsonNode fromObject, ObjectNode parentObje
42084202
return toObject;
42094203
}
42104204

4211-
@ExcludeFromGeneratedCoverageReport
4212-
ObjectNode speechConfigToVertex(JsonNode fromObject, ObjectNode parentObject) {
4213-
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
4214-
if (Common.getValueByPath(fromObject, new String[] {"voiceConfig"}) != null) {
4215-
Common.setValueByPath(
4216-
toObject,
4217-
new String[] {"voiceConfig"},
4218-
Common.getValueByPath(fromObject, new String[] {"voiceConfig"}));
4219-
}
4220-
4221-
if (Common.getValueByPath(fromObject, new String[] {"languageCode"}) != null) {
4222-
Common.setValueByPath(
4223-
toObject,
4224-
new String[] {"languageCode"},
4225-
Common.getValueByPath(fromObject, new String[] {"languageCode"}));
4226-
}
4227-
4228-
if (!Common.isZero(
4229-
Common.getValueByPath(fromObject, new String[] {"multiSpeakerVoiceConfig"}))) {
4230-
throw new IllegalArgumentException(
4231-
"multiSpeakerVoiceConfig parameter is not supported in Vertex AI.");
4232-
}
4233-
4234-
return toObject;
4235-
}
4236-
42374205
@ExcludeFromGeneratedCoverageReport
42384206
ObjectNode toolConfigToMldev(JsonNode fromObject, ObjectNode parentObject) {
42394207
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

src/main/java/com/google/genai/types/MultiSpeakerVoiceConfig.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030
import java.util.List;
3131
import java.util.Optional;
3232

33-
/** The configuration for the multi-speaker setup. This data type is not supported in Vertex AI. */
33+
/** Configuration for a multi-speaker text-to-speech request. */
3434
@AutoValue
3535
@JsonDeserialize(builder = MultiSpeakerVoiceConfig.Builder.class)
3636
public abstract class MultiSpeakerVoiceConfig extends JsonSerializable {
37-
/** Required. All the enabled speaker voices. */
37+
/**
38+
* Required. A list of configurations for the voices of the speakers. Exactly two speaker voice
39+
* configurations must be provided.
40+
*/
3841
@JsonProperty("speakerVoiceConfigs")
3942
public abstract Optional<List<SpeakerVoiceConfig>> speakerVoiceConfigs();
4043

@@ -59,15 +62,17 @@ private static Builder create() {
5962
/**
6063
* Setter for speakerVoiceConfigs.
6164
*
62-
* <p>speakerVoiceConfigs: Required. All the enabled speaker voices.
65+
* <p>speakerVoiceConfigs: Required. A list of configurations for the voices of the speakers.
66+
* Exactly two speaker voice configurations must be provided.
6367
*/
6468
@JsonProperty("speakerVoiceConfigs")
6569
public abstract Builder speakerVoiceConfigs(List<SpeakerVoiceConfig> speakerVoiceConfigs);
6670

6771
/**
6872
* Setter for speakerVoiceConfigs.
6973
*
70-
* <p>speakerVoiceConfigs: Required. All the enabled speaker voices.
74+
* <p>speakerVoiceConfigs: Required. A list of configurations for the voices of the speakers.
75+
* Exactly two speaker voice configurations must be provided.
7176
*/
7277
@CanIgnoreReturnValue
7378
public Builder speakerVoiceConfigs(SpeakerVoiceConfig... speakerVoiceConfigs) {
@@ -77,7 +82,8 @@ public Builder speakerVoiceConfigs(SpeakerVoiceConfig... speakerVoiceConfigs) {
7782
/**
7883
* Setter for speakerVoiceConfigs builder.
7984
*
80-
* <p>speakerVoiceConfigs: Required. All the enabled speaker voices.
85+
* <p>speakerVoiceConfigs: Required. A list of configurations for the voices of the speakers.
86+
* Exactly two speaker voice configurations must be provided.
8187
*/
8288
@CanIgnoreReturnValue
8389
public Builder speakerVoiceConfigs(SpeakerVoiceConfig.Builder... speakerVoiceConfigsBuilders) {

src/main/java/com/google/genai/types/SpeechConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public abstract class SpeechConfig extends JsonSerializable {
3939
public abstract Optional<String> languageCode();
4040

4141
/**
42-
* Optional. The configuration for the multi-speaker setup. It is mutually exclusive with the
43-
* voice_config field. This field is not supported in Vertex AI.
42+
* The configuration for a multi-speaker text-to-speech request. This field is mutually exclusive
43+
* with `voice_config`.
4444
*/
4545
@JsonProperty("multiSpeakerVoiceConfig")
4646
public abstract Optional<MultiSpeakerVoiceConfig> multiSpeakerVoiceConfig();
@@ -112,8 +112,8 @@ public Builder clearLanguageCode() {
112112
/**
113113
* Setter for multiSpeakerVoiceConfig.
114114
*
115-
* <p>multiSpeakerVoiceConfig: Optional. The configuration for the multi-speaker setup. It is
116-
* mutually exclusive with the voice_config field. This field is not supported in Vertex AI.
115+
* <p>multiSpeakerVoiceConfig: The configuration for a multi-speaker text-to-speech request.
116+
* This field is mutually exclusive with `voice_config`.
117117
*/
118118
@JsonProperty("multiSpeakerVoiceConfig")
119119
public abstract Builder multiSpeakerVoiceConfig(
@@ -122,8 +122,8 @@ public abstract Builder multiSpeakerVoiceConfig(
122122
/**
123123
* Setter for multiSpeakerVoiceConfig builder.
124124
*
125-
* <p>multiSpeakerVoiceConfig: Optional. The configuration for the multi-speaker setup. It is
126-
* mutually exclusive with the voice_config field. This field is not supported in Vertex AI.
125+
* <p>multiSpeakerVoiceConfig: The configuration for a multi-speaker text-to-speech request.
126+
* This field is mutually exclusive with `voice_config`.
127127
*/
128128
@CanIgnoreReturnValue
129129
public Builder multiSpeakerVoiceConfig(

0 commit comments

Comments
 (0)