Skip to content

Commit 49d480c

Browse files
committed
use voice instead of voices
1 parent 5e3c47c commit 49d480c

File tree

5 files changed

+91
-28
lines changed

5 files changed

+91
-28
lines changed

firebase-ai/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
* [fixed] Fixed `FirebaseAI.getInstance` StackOverflowException (#6971)
44
* [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API.
5-
* [changed] **Breaking Change**: Updated `Voices` to accept a voice name as an attribute
5+
* [changed] Introduced the `Voice` class, which accepts a voice name, and deprecated the `Voices` class.
6+
* [changed] **Breaking Change**: Updated `SpeechConfig` to take in `Voice` class instead of `Voices` class.
7+
* **Action Required:** Update all references of `SpeechConfig` initialization to use `Voice` class.
68

9+
710
# 16.0.0
811
* [feature] Initial release of the Firebase AI SDK (`firebase-ai`). This SDK *replaces* the previous
912
Vertex AI in Firebase SDK (`firebase-vertexai`) to accommodate the evolving set of supported

firebase-ai/api.txt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,9 @@ package com.google.firebase.ai.type {
863863
}
864864

865865
@com.google.firebase.ai.type.PublicPreviewAPI public final class SpeechConfig {
866-
ctor public SpeechConfig(com.google.firebase.ai.type.Voices voice);
867-
method public com.google.firebase.ai.type.Voices getVoice();
868-
property public final com.google.firebase.ai.type.Voices voice;
866+
ctor public SpeechConfig(com.google.firebase.ai.type.Voice voice);
867+
method public com.google.firebase.ai.type.Voice getVoice();
868+
property public final com.google.firebase.ai.type.Voice voice;
869869
}
870870

871871
public abstract class StringFormat {
@@ -914,20 +914,25 @@ package com.google.firebase.ai.type {
914914
property public final int totalTokenCount;
915915
}
916916

917-
@com.google.firebase.ai.type.PublicPreviewAPI public final class Voices {
918-
ctor public Voices(String voiceName);
917+
@com.google.firebase.ai.type.PublicPreviewAPI public final class Voice {
918+
ctor public Voice(String voiceName);
919919
method public String getVoiceName();
920920
property public final String voiceName;
921-
field public static final com.google.firebase.ai.type.Voices AOEDE;
922-
field public static final com.google.firebase.ai.type.Voices CHARON;
923-
field public static final com.google.firebase.ai.type.Voices.Companion Companion;
924-
field public static final com.google.firebase.ai.type.Voices FENRIR;
925-
field public static final com.google.firebase.ai.type.Voices KORE;
926-
field public static final com.google.firebase.ai.type.Voices PUCK;
927-
field public static final com.google.firebase.ai.type.Voices UNSPECIFIED;
928921
}
929922

930-
public static final class Voices.Companion {
923+
@Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class Voices {
924+
method @Deprecated public int getOrdinal();
925+
property @Deprecated public final int ordinal;
926+
field @Deprecated public static final com.google.firebase.ai.type.Voices AOEDE;
927+
field @Deprecated public static final com.google.firebase.ai.type.Voices CHARON;
928+
field @Deprecated public static final com.google.firebase.ai.type.Voices.Companion Companion;
929+
field @Deprecated public static final com.google.firebase.ai.type.Voices FENRIR;
930+
field @Deprecated public static final com.google.firebase.ai.type.Voices KORE;
931+
field @Deprecated public static final com.google.firebase.ai.type.Voices PUCK;
932+
field @Deprecated public static final com.google.firebase.ai.type.Voices UNSPECIFIED;
933+
}
934+
935+
@Deprecated public static final class Voices.Companion {
931936
}
932937

933938
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import kotlinx.serialization.Serializable
2323
@PublicPreviewAPI
2424
public class SpeechConfig(
2525
/** The voice to be used for the server's speech response. */
26-
public val voice: Voices
26+
public val voice: Voice
2727
) {
2828

2929
@Serializable
3030
internal data class Internal(@SerialName("voice_config") val voiceConfig: VoiceConfigInternal) {
3131
@Serializable
3232
internal data class VoiceConfigInternal(
33-
@SerialName("prebuilt_voice_config") val prebuiltVoiceConfig: Voices.Internal,
33+
@SerialName("prebuilt_voice_config") val prebuiltVoiceConfig: Voice.Internal,
3434
)
3535
}
3636

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
* http://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+
package com.google.firebase.ai.type
18+
19+
import kotlinx.serialization.SerialName
20+
import kotlinx.serialization.Serializable
21+
22+
/**
23+
* Various voices supported by the server. The list of all voices can be found
24+
* [here](https://cloud.google.com/text-to-speech/docs/chirp3-hd)
25+
*/
26+
@PublicPreviewAPI
27+
public class Voice public constructor(public val voiceName: String) {
28+
29+
@Serializable internal data class Internal(@SerialName("voice_name") val voiceName: String)
30+
31+
internal fun toInternal(): Internal {
32+
return Internal(this.voiceName)
33+
}
34+
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,38 @@ package com.google.firebase.ai.type
1919
import kotlinx.serialization.SerialName
2020
import kotlinx.serialization.Serializable
2121

22-
/**
23-
* Various voices supported by the server. The list of all voices can be found
24-
* [here](https://cloud.google.com/text-to-speech/docs/chirp3-hd)
25-
*/
22+
/** Various voices supported by the server */
23+
@Deprecated("Please use the Voice class instead.")
2624
@PublicPreviewAPI
27-
public class Voices public constructor(public val voiceName: String) {
25+
public class Voices private constructor(public val ordinal: Int) {
2826

2927
@Serializable internal data class Internal(@SerialName("voice_name") val voiceName: String)
3028

29+
@Serializable
30+
internal enum class InternalEnum {
31+
CHARON,
32+
AOEDE,
33+
FENRIR,
34+
KORE,
35+
PUCK;
36+
internal fun toPublic() =
37+
when (this) {
38+
CHARON -> Voices.CHARON
39+
AOEDE -> Voices.AOEDE
40+
FENRIR -> Voices.FENRIR
41+
KORE -> Voices.KORE
42+
else -> Voices.PUCK
43+
}
44+
}
45+
3146
internal fun toInternal(): Internal {
32-
return Internal(this.voiceName)
47+
return when (this) {
48+
CHARON -> Internal(InternalEnum.CHARON.name)
49+
AOEDE -> Internal(InternalEnum.AOEDE.name)
50+
FENRIR -> Internal(InternalEnum.FENRIR.name)
51+
KORE -> Internal(InternalEnum.KORE.name)
52+
else -> Internal(InternalEnum.PUCK.name)
53+
}
3354
}
3455

3556
public companion object {
@@ -38,21 +59,21 @@ public class Voices public constructor(public val voiceName: String) {
3859
*
3960
* Will use the default voice of the model.
4061
*/
41-
@JvmField public val UNSPECIFIED: Voices = Voices("Puck")
62+
@JvmField public val UNSPECIFIED: Voices = Voices(0)
4263

4364
/** Represents the Charon voice. */
44-
@JvmField public val CHARON: Voices = Voices("Charon")
65+
@JvmField public val CHARON: Voices = Voices(1)
4566

4667
/** Represents the Aoede voice. */
47-
@JvmField public val AOEDE: Voices = Voices("Aoede")
68+
@JvmField public val AOEDE: Voices = Voices(2)
4869

4970
/** Represents the Fenrir voice. */
50-
@JvmField public val FENRIR: Voices = Voices("Fenrir")
71+
@JvmField public val FENRIR: Voices = Voices(3)
5172

5273
/** Represents the Kore voice. */
53-
@JvmField public val KORE: Voices = Voices("Kore")
74+
@JvmField public val KORE: Voices = Voices(4)
5475

5576
/** Represents the Puck voice. */
56-
@JvmField public val PUCK: Voices = Voices("Puck")
77+
@JvmField public val PUCK: Voices = Voices(5)
5778
}
5879
}

0 commit comments

Comments
 (0)