Skip to content

Commit 66e7cd4

Browse files
MarkDaoustcopybara-github
authored andcommitted
chore: Tests for ReplicatedVoiceConfig
PiperOrigin-RevId: 841593648
1 parent 6fade7b commit 66e7cd4

5 files changed

Lines changed: 92 additions & 24 deletions

File tree

‎Google.GenAI/LiveConverters.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,16 +1230,16 @@ internal JsonNode SessionResumptionConfigToMldev(JsonNode fromObject, JsonObject
12301230
internal JsonNode SpeechConfigToVertex(JsonNode fromObject, JsonObject parentObject) {
12311231
JsonObject toObject = new JsonObject();
12321232

1233-
if (Common.GetValueByPath(fromObject, new string[] { "languageCode" }) != null) {
1234-
Common.SetValueByPath(toObject, new string[] { "languageCode" },
1235-
Common.GetValueByPath(fromObject, new string[] { "languageCode" }));
1236-
}
1237-
12381233
if (Common.GetValueByPath(fromObject, new string[] { "voiceConfig" }) != null) {
12391234
Common.SetValueByPath(toObject, new string[] { "voiceConfig" },
12401235
Common.GetValueByPath(fromObject, new string[] { "voiceConfig" }));
12411236
}
12421237

1238+
if (Common.GetValueByPath(fromObject, new string[] { "languageCode" }) != null) {
1239+
Common.SetValueByPath(toObject, new string[] { "languageCode" },
1240+
Common.GetValueByPath(fromObject, new string[] { "languageCode" }));
1241+
}
1242+
12431243
if (!Common.IsZero(
12441244
Common.GetValueByPath(fromObject, new string[] { "multiSpeakerVoiceConfig" }))) {
12451245
throw new NotSupportedException(

‎Google.GenAI/Models.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,16 +3443,16 @@ internal JsonNode SegmentImageSourceToVertex(JsonNode fromObject, JsonObject par
34433443
internal JsonNode SpeechConfigToVertex(JsonNode fromObject, JsonObject parentObject) {
34443444
JsonObject toObject = new JsonObject();
34453445

3446-
if (Common.GetValueByPath(fromObject, new string[] { "languageCode" }) != null) {
3447-
Common.SetValueByPath(toObject, new string[] { "languageCode" },
3448-
Common.GetValueByPath(fromObject, new string[] { "languageCode" }));
3449-
}
3450-
34513446
if (Common.GetValueByPath(fromObject, new string[] { "voiceConfig" }) != null) {
34523447
Common.SetValueByPath(toObject, new string[] { "voiceConfig" },
34533448
Common.GetValueByPath(fromObject, new string[] { "voiceConfig" }));
34543449
}
34553450

3451+
if (Common.GetValueByPath(fromObject, new string[] { "languageCode" }) != null) {
3452+
Common.SetValueByPath(toObject, new string[] { "languageCode" },
3453+
Common.GetValueByPath(fromObject, new string[] { "languageCode" }));
3454+
}
3455+
34563456
if (!Common.IsZero(
34573457
Common.GetValueByPath(fromObject, new string[] { "multiSpeakerVoiceConfig" }))) {
34583458
throw new NotSupportedException(
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
/// <summary>
26+
/// ReplicatedVoiceConfig is used to configure replicated voice.
27+
/// </summary>
28+
29+
public record ReplicatedVoiceConfig {
30+
/// <summary>
31+
/// The mime type of the replicated voice.
32+
/// </summary>
33+
[JsonPropertyName("mimeType")]
34+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
35+
public string ? MimeType { get; set; }
36+
37+
/// <summary>
38+
/// The sample audio of the replicated voice.
39+
/// </summary>
40+
[JsonPropertyName("voiceSampleAudio")]
41+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
42+
public byte[]
43+
? VoiceSampleAudio {
44+
get; set;
45+
}
46+
47+
/// <summary>
48+
/// Deserializes a JSON string to a ReplicatedVoiceConfig object.
49+
/// </summary>
50+
/// <param name="jsonString">The JSON string to deserialize.</param>
51+
/// <param name="options">Optional JsonSerializerOptions.</param>
52+
/// <returns>The deserialized ReplicatedVoiceConfig object, or null if deserialization
53+
/// fails.</returns>
54+
public static ReplicatedVoiceConfig
55+
? FromJson(string jsonString, JsonSerializerOptions? options = null) {
56+
try {
57+
return JsonSerializer.Deserialize<ReplicatedVoiceConfig>(jsonString, options);
58+
} catch (JsonException e) {
59+
Console.Error.WriteLine($"Error deserializing JSON: {e.ToString()}");
60+
return null;
61+
}
62+
}
63+
}
64+
}

‎Google.GenAI/types/SpeechConfig.cs‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,22 @@
2222
using Google.GenAI.Serialization;
2323

2424
namespace Google.GenAI.Types {
25-
/// <summary>
26-
/// The speech generation config.
27-
/// </summary>
2825

2926
public record SpeechConfig {
3027
/// <summary>
31-
/// Optional. Language code (ISO 639. e.g. en-US) for the speech synthesization.
28+
/// Configuration for the voice of the response.
3229
/// </summary>
33-
[JsonPropertyName("languageCode")]
30+
[JsonPropertyName("voiceConfig")]
3431
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
35-
public string ? LanguageCode { get; set; }
32+
public VoiceConfig ? VoiceConfig { get; set; }
3633

3734
/// <summary>
38-
/// The configuration for the speaker to use.
35+
/// Optional. Language code (ISO 639. e.g. en-US) for the speech synthesization.
3936
/// </summary>
40-
[JsonPropertyName("voiceConfig")]
37+
[JsonPropertyName("languageCode")]
4138
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
42-
public VoiceConfig
43-
? VoiceConfig {
39+
public string
40+
? LanguageCode {
4441
get; set;
4542
}
4643

‎Google.GenAI/types/VoiceConfig.cs‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,24 @@
2222
using Google.GenAI.Serialization;
2323

2424
namespace Google.GenAI.Types {
25-
/// <summary>
26-
/// The configuration for the voice to use.
27-
/// </summary>
2825

2926
public record VoiceConfig {
27+
/// <summary>
28+
/// If true, the model will use a replicated voice for the response.
29+
/// </summary>
30+
[JsonPropertyName("replicatedVoiceConfig")]
31+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
32+
public ReplicatedVoiceConfig ? ReplicatedVoiceConfig { get; set; }
33+
3034
/// <summary>
3135
/// The configuration for the prebuilt voice to use.
3236
/// </summary>
3337
[JsonPropertyName("prebuiltVoiceConfig")]
3438
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
35-
public PrebuiltVoiceConfig ? PrebuiltVoiceConfig { get; set; }
39+
public PrebuiltVoiceConfig
40+
? PrebuiltVoiceConfig {
41+
get; set;
42+
}
3643

3744
/// <summary>
3845
/// Deserializes a JSON string to a VoiceConfig object.

0 commit comments

Comments
 (0)