Skip to content

Commit d1ca685

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: Add voice activity detection signal.
PiperOrigin-RevId: 842366448
1 parent 0a8a26e commit d1ca685

File tree

7 files changed

+339
-0
lines changed

7 files changed

+339
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ ObjectNode liveClientSetupToMldev(JsonNode fromObject, ObjectNode parentObject)
728728
Common.getValueByPath(fromObject, new String[] {"proactivity"}));
729729
}
730730

731+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}))) {
732+
throw new IllegalArgumentException(
733+
"explicitVadSignal parameter is not supported in Gemini API.");
734+
}
735+
731736
return toObject;
732737
}
733738

@@ -814,6 +819,13 @@ ObjectNode liveClientSetupToVertex(JsonNode fromObject, ObjectNode parentObject)
814819
Common.getValueByPath(fromObject, new String[] {"proactivity"}));
815820
}
816821

822+
if (Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}) != null) {
823+
Common.setValueByPath(
824+
toObject,
825+
new String[] {"explicitVadSignal"},
826+
Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}));
827+
}
828+
817829
return toObject;
818830
}
819831

@@ -961,6 +973,11 @@ ObjectNode liveConnectConfigToMldev(JsonNode fromObject, ObjectNode parentObject
961973
Common.getValueByPath(fromObject, new String[] {"proactivity"}));
962974
}
963975

976+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}))) {
977+
throw new IllegalArgumentException(
978+
"explicitVadSignal parameter is not supported in Gemini API.");
979+
}
980+
964981
return toObject;
965982
}
966983

@@ -1105,6 +1122,13 @@ ObjectNode liveConnectConfigToVertex(JsonNode fromObject, ObjectNode parentObjec
11051122
Common.getValueByPath(fromObject, new String[] {"proactivity"}));
11061123
}
11071124

1125+
if (Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}) != null) {
1126+
Common.setValueByPath(
1127+
parentObject,
1128+
new String[] {"setup", "explicitVadSignal"},
1129+
Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}));
1130+
}
1131+
11081132
return toObject;
11091133
}
11101134

@@ -1337,6 +1361,13 @@ ObjectNode liveServerMessageFromVertex(JsonNode fromObject, ObjectNode parentObj
13371361
Common.getValueByPath(fromObject, new String[] {"sessionResumptionUpdate"}));
13381362
}
13391363

1364+
if (Common.getValueByPath(fromObject, new String[] {"voiceActivityDetectionSignal"}) != null) {
1365+
Common.setValueByPath(
1366+
toObject,
1367+
new String[] {"voiceActivityDetectionSignal"},
1368+
Common.getValueByPath(fromObject, new String[] {"voiceActivityDetectionSignal"}));
1369+
}
1370+
13401371
return toObject;
13411372
}
13421373

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ ObjectNode liveConnectConfigToMldev(JsonNode fromObject, ObjectNode parentObject
395395
Common.getValueByPath(fromObject, new String[] {"proactivity"}));
396396
}
397397

398+
if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"explicitVadSignal"}))) {
399+
throw new IllegalArgumentException(
400+
"explicitVadSignal parameter is not supported in Gemini API.");
401+
}
402+
398403
return toObject;
399404
}
400405

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public abstract class LiveClientSetup extends JsonSerializable {
9595
@JsonProperty("proactivity")
9696
public abstract Optional<ProactivityConfig> proactivity();
9797

98+
/**
99+
* Configures the explicit VAD signal. If enabled, the client will send vad_signal to indicate the
100+
* start and end of speech. This allows the server to process the audio more efficiently.
101+
*/
102+
@JsonProperty("explicitVadSignal")
103+
public abstract Optional<Boolean> explicitVadSignal();
104+
98105
/** Instantiates a builder for LiveClientSetup. */
99106
@ExcludeFromGeneratedCoverageReport
100107
public static Builder builder() {
@@ -432,6 +439,26 @@ public Builder clearProactivity() {
432439
return proactivity(Optional.empty());
433440
}
434441

442+
/**
443+
* Setter for explicitVadSignal.
444+
*
445+
* <p>explicitVadSignal: Configures the explicit VAD signal. If enabled, the client will send
446+
* vad_signal to indicate the start and end of speech. This allows the server to process the
447+
* audio more efficiently.
448+
*/
449+
@JsonProperty("explicitVadSignal")
450+
public abstract Builder explicitVadSignal(boolean explicitVadSignal);
451+
452+
@ExcludeFromGeneratedCoverageReport
453+
abstract Builder explicitVadSignal(Optional<Boolean> explicitVadSignal);
454+
455+
/** Clears the value of explicitVadSignal field. */
456+
@ExcludeFromGeneratedCoverageReport
457+
@CanIgnoreReturnValue
458+
public Builder clearExplicitVadSignal() {
459+
return explicitVadSignal(Optional.empty());
460+
}
461+
435462
public abstract LiveClientSetup build();
436463
}
437464

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ public abstract class LiveConnectConfig extends JsonSerializable {
154154
@JsonProperty("proactivity")
155155
public abstract Optional<ProactivityConfig> proactivity();
156156

157+
/**
158+
* Configures the explicit VAD signal. If enabled, the client will send vad_signal to indicate the
159+
* start and end of speech. This allows the server to process the audio more efficiently.
160+
*/
161+
@JsonProperty("explicitVadSignal")
162+
public abstract Optional<Boolean> explicitVadSignal();
163+
157164
/** Instantiates a builder for LiveConnectConfig. */
158165
@ExcludeFromGeneratedCoverageReport
159166
public static Builder builder() {
@@ -762,6 +769,26 @@ public Builder clearProactivity() {
762769
return proactivity(Optional.empty());
763770
}
764771

772+
/**
773+
* Setter for explicitVadSignal.
774+
*
775+
* <p>explicitVadSignal: Configures the explicit VAD signal. If enabled, the client will send
776+
* vad_signal to indicate the start and end of speech. This allows the server to process the
777+
* audio more efficiently.
778+
*/
779+
@JsonProperty("explicitVadSignal")
780+
public abstract Builder explicitVadSignal(boolean explicitVadSignal);
781+
782+
@ExcludeFromGeneratedCoverageReport
783+
abstract Builder explicitVadSignal(Optional<Boolean> explicitVadSignal);
784+
785+
/** Clears the value of explicitVadSignal field. */
786+
@ExcludeFromGeneratedCoverageReport
787+
@CanIgnoreReturnValue
788+
public Builder clearExplicitVadSignal() {
789+
return explicitVadSignal(Optional.empty());
790+
}
791+
765792
public abstract LiveConnectConfig build();
766793
}
767794

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public abstract class LiveServerMessage extends JsonSerializable {
6464
@JsonProperty("sessionResumptionUpdate")
6565
public abstract Optional<LiveServerSessionResumptionUpdate> sessionResumptionUpdate();
6666

67+
/** Voice activity detection signal. */
68+
@JsonProperty("voiceActivityDetectionSignal")
69+
public abstract Optional<VoiceActivityDetectionSignal> voiceActivityDetectionSignal();
70+
6771
/** Instantiates a builder for LiveServerMessage. */
6872
@ExcludeFromGeneratedCoverageReport
6973
public static Builder builder() {
@@ -290,6 +294,37 @@ public Builder clearSessionResumptionUpdate() {
290294
return sessionResumptionUpdate(Optional.empty());
291295
}
292296

297+
/**
298+
* Setter for voiceActivityDetectionSignal.
299+
*
300+
* <p>voiceActivityDetectionSignal: Voice activity detection signal.
301+
*/
302+
@JsonProperty("voiceActivityDetectionSignal")
303+
public abstract Builder voiceActivityDetectionSignal(
304+
VoiceActivityDetectionSignal voiceActivityDetectionSignal);
305+
306+
/**
307+
* Setter for voiceActivityDetectionSignal builder.
308+
*
309+
* <p>voiceActivityDetectionSignal: Voice activity detection signal.
310+
*/
311+
@CanIgnoreReturnValue
312+
public Builder voiceActivityDetectionSignal(
313+
VoiceActivityDetectionSignal.Builder voiceActivityDetectionSignalBuilder) {
314+
return voiceActivityDetectionSignal(voiceActivityDetectionSignalBuilder.build());
315+
}
316+
317+
@ExcludeFromGeneratedCoverageReport
318+
abstract Builder voiceActivityDetectionSignal(
319+
Optional<VoiceActivityDetectionSignal> voiceActivityDetectionSignal);
320+
321+
/** Clears the value of voiceActivityDetectionSignal field. */
322+
@ExcludeFromGeneratedCoverageReport
323+
@CanIgnoreReturnValue
324+
public Builder clearVoiceActivityDetectionSignal() {
325+
return voiceActivityDetectionSignal(Optional.empty());
326+
}
327+
293328
public abstract LiveServerMessage build();
294329
}
295330

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonValue;
23+
import com.google.common.base.Ascii;
24+
import java.util.Objects;
25+
26+
/** The type of the VAD signal. */
27+
public class VadSignalType {
28+
29+
/** Enum representing the known values for VadSignalType. */
30+
public enum Known {
31+
/** The default is VAD_SIGNAL_TYPE_UNSPECIFIED. */
32+
VAD_SIGNAL_TYPE_UNSPECIFIED,
33+
34+
/** Start of sentence signal. */
35+
VAD_SIGNAL_TYPE_SOS,
36+
37+
/** End of sentence signal. */
38+
VAD_SIGNAL_TYPE_EOS
39+
}
40+
41+
private Known vadSignalTypeEnum;
42+
private final String value;
43+
44+
@JsonCreator
45+
public VadSignalType(String value) {
46+
this.value = value;
47+
for (Known vadSignalTypeEnum : Known.values()) {
48+
if (Ascii.equalsIgnoreCase(vadSignalTypeEnum.toString(), value)) {
49+
this.vadSignalTypeEnum = vadSignalTypeEnum;
50+
break;
51+
}
52+
}
53+
if (this.vadSignalTypeEnum == null) {
54+
this.vadSignalTypeEnum = Known.VAD_SIGNAL_TYPE_UNSPECIFIED;
55+
}
56+
}
57+
58+
public VadSignalType(Known knownValue) {
59+
this.vadSignalTypeEnum = knownValue;
60+
this.value = knownValue.toString();
61+
}
62+
63+
@ExcludeFromGeneratedCoverageReport
64+
@Override
65+
@JsonValue
66+
public String toString() {
67+
return this.value;
68+
}
69+
70+
@ExcludeFromGeneratedCoverageReport
71+
@SuppressWarnings("PatternMatchingInstanceof")
72+
@Override
73+
public boolean equals(Object o) {
74+
if (this == o) {
75+
return true;
76+
}
77+
if (o == null) {
78+
return false;
79+
}
80+
81+
if (!(o instanceof VadSignalType)) {
82+
return false;
83+
}
84+
85+
VadSignalType other = (VadSignalType) o;
86+
87+
if (this.vadSignalTypeEnum != Known.VAD_SIGNAL_TYPE_UNSPECIFIED
88+
&& other.vadSignalTypeEnum != Known.VAD_SIGNAL_TYPE_UNSPECIFIED) {
89+
return this.vadSignalTypeEnum == other.vadSignalTypeEnum;
90+
} else if (this.vadSignalTypeEnum == Known.VAD_SIGNAL_TYPE_UNSPECIFIED
91+
&& other.vadSignalTypeEnum == Known.VAD_SIGNAL_TYPE_UNSPECIFIED) {
92+
return this.value.equals(other.value);
93+
}
94+
return false;
95+
}
96+
97+
@ExcludeFromGeneratedCoverageReport
98+
@Override
99+
public int hashCode() {
100+
if (this.vadSignalTypeEnum != Known.VAD_SIGNAL_TYPE_UNSPECIFIED) {
101+
return this.vadSignalTypeEnum.hashCode();
102+
} else {
103+
return Objects.hashCode(this.value);
104+
}
105+
}
106+
107+
@ExcludeFromGeneratedCoverageReport
108+
public Known knownEnum() {
109+
return this.vadSignalTypeEnum;
110+
}
111+
}

0 commit comments

Comments
 (0)