Skip to content

Commit 6ff3f01

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: Add voice activity detection signal.
PiperOrigin-RevId: 842366448
1 parent f2e199d commit 6ff3f01

6 files changed

Lines changed: 154 additions & 0 deletions

File tree

Google.GenAI/LiveConverters.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ internal JsonNode LiveClientSetupToMldev(JsonNode fromObject, JsonObject parentO
619619
Common.GetValueByPath(fromObject, new string[] { "proactivity" }));
620620
}
621621

622+
if (!Common.IsZero(Common.GetValueByPath(fromObject, new string[] { "explicitVadSignal" }))) {
623+
throw new NotSupportedException(
624+
"explicitVadSignal parameter is not supported in Gemini API.");
625+
}
626+
622627
return toObject;
623628
}
624629

@@ -691,6 +696,12 @@ internal JsonNode LiveClientSetupToVertex(JsonNode fromObject, JsonObject parent
691696
Common.GetValueByPath(fromObject, new string[] { "proactivity" }));
692697
}
693698

699+
if (Common.GetValueByPath(fromObject, new string[] { "explicitVadSignal" }) != null) {
700+
Common.SetValueByPath(
701+
toObject, new string[] { "explicitVadSignal" },
702+
Common.GetValueByPath(fromObject, new string[] { "explicitVadSignal" }));
703+
}
704+
694705
return toObject;
695706
}
696707

@@ -819,6 +830,11 @@ internal JsonNode LiveConnectConfigToMldev(JsonNode fromObject, JsonObject paren
819830
Common.GetValueByPath(fromObject, new string[] { "proactivity" }));
820831
}
821832

833+
if (!Common.IsZero(Common.GetValueByPath(fromObject, new string[] { "explicitVadSignal" }))) {
834+
throw new NotSupportedException(
835+
"explicitVadSignal parameter is not supported in Gemini API.");
836+
}
837+
822838
return toObject;
823839
}
824840

@@ -946,6 +962,12 @@ internal JsonNode LiveConnectConfigToVertex(JsonNode fromObject, JsonObject pare
946962
Common.GetValueByPath(fromObject, new string[] { "proactivity" }));
947963
}
948964

965+
if (Common.GetValueByPath(fromObject, new string[] { "explicitVadSignal" }) != null) {
966+
Common.SetValueByPath(
967+
parentObject, new string[] { "setup", "explicitVadSignal" },
968+
Common.GetValueByPath(fromObject, new string[] { "explicitVadSignal" }));
969+
}
970+
949971
return toObject;
950972
}
951973

@@ -1135,6 +1157,13 @@ internal JsonNode LiveServerMessageFromVertex(JsonNode fromObject, JsonObject pa
11351157
Common.GetValueByPath(fromObject, new string[] { "sessionResumptionUpdate" }));
11361158
}
11371159

1160+
if (Common.GetValueByPath(fromObject, new string[] { "voiceActivityDetectionSignal" }) !=
1161+
null) {
1162+
Common.SetValueByPath(
1163+
toObject, new string[] { "voiceActivityDetectionSignal" },
1164+
Common.GetValueByPath(fromObject, new string[] { "voiceActivityDetectionSignal" }));
1165+
}
1166+
11381167
return toObject;
11391168
}
11401169

Google.GenAI/types/LiveClientSetup.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ public ProactivityConfig
131131
get; set;
132132
}
133133

134+
/// <summary>
135+
/// Configures the explicit VAD signal. If enabled, the client will send vad_signal to indicate
136+
/// the start and end of speech. This allows the server to process the audio more efficiently.
137+
/// </summary>
138+
[JsonPropertyName("explicitVadSignal")]
139+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
140+
public bool
141+
? ExplicitVadSignal {
142+
get; set;
143+
}
144+
134145
/// <summary>
135146
/// Deserializes a JSON string to a LiveClientSetup object.
136147
/// </summary>

Google.GenAI/types/LiveConnectConfig.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ public ProactivityConfig
241241
get; set;
242242
}
243243

244+
/// <summary>
245+
/// Configures the explicit VAD signal. If enabled, the client will send vad_signal to indicate
246+
/// the start and end of speech. This allows the server to process the audio more efficiently.
247+
/// </summary>
248+
[JsonPropertyName("explicitVadSignal")]
249+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
250+
public bool
251+
? ExplicitVadSignal {
252+
get; set;
253+
}
254+
244255
/// <summary>
245256
/// Deserializes a JSON string to a LiveConnectConfig object.
246257
/// </summary>

Google.GenAI/types/LiveServerMessage.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ public LiveServerSessionResumptionUpdate
9696
get; set;
9797
}
9898

99+
/// <summary>
100+
/// Voice activity detection signal.
101+
/// </summary>
102+
[JsonPropertyName("voiceActivityDetectionSignal")]
103+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
104+
public VoiceActivityDetectionSignal
105+
? VoiceActivityDetectionSignal {
106+
get; set;
107+
}
108+
99109
/// <summary>
100110
/// Deserializes a JSON string to a LiveServerMessage object.
101111
/// </summary>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
using System.Text.Json.Serialization;
20+
21+
namespace Google.GenAI.Types {
22+
/// <summary>
23+
/// The type of the VAD signal.
24+
/// </summary>
25+
[JsonConverter(typeof(JsonStringEnumConverter))]
26+
public enum VadSignalType {
27+
/// <summary>
28+
/// The default is VAD_SIGNAL_TYPE_UNSPECIFIED.
29+
/// </summary>
30+
[JsonPropertyName("VAD_SIGNAL_TYPE_UNSPECIFIED")] VAD_SIGNAL_TYPE_UNSPECIFIED,
31+
32+
/// <summary>
33+
/// Start of sentence signal.
34+
/// </summary>
35+
[JsonPropertyName("VAD_SIGNAL_TYPE_SOS")] VAD_SIGNAL_TYPE_SOS,
36+
37+
/// <summary>
38+
/// End of sentence signal.
39+
/// </summary>
40+
[JsonPropertyName("VAD_SIGNAL_TYPE_EOS")] VAD_SIGNAL_TYPE_EOS
41+
}
42+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
using System;
20+
using System.Text.Json;
21+
using System.Text.Json.Serialization;
22+
using Google.GenAI.Serialization;
23+
24+
namespace Google.GenAI.Types {
25+
26+
public record VoiceActivityDetectionSignal {
27+
/// <summary>
28+
/// The type of the VAD signal.
29+
/// </summary>
30+
[JsonPropertyName("vadSignalType")]
31+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
32+
public VadSignalType ? VadSignalType { get; set; }
33+
34+
/// <summary>
35+
/// Deserializes a JSON string to a VoiceActivityDetectionSignal object.
36+
/// </summary>
37+
/// <param name="jsonString">The JSON string to deserialize.</param>
38+
/// <param name="options">Optional JsonSerializerOptions.</param>
39+
/// <returns>The deserialized VoiceActivityDetectionSignal object, or null if deserialization
40+
/// fails.</returns>
41+
public static VoiceActivityDetectionSignal
42+
? FromJson(string jsonString, JsonSerializerOptions? options = null) {
43+
try {
44+
return JsonSerializer.Deserialize<VoiceActivityDetectionSignal>(jsonString, options);
45+
} catch (JsonException e) {
46+
Console.Error.WriteLine($"Error deserializing JSON: {e.ToString()}");
47+
return null;
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)