From 4156ee66bacc1e53b695fcb146a5963a2a43d455 Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Tue, 27 May 2025 15:56:08 -0400 Subject: [PATCH 1/6] update voice --- .../google/firebase/ai/type/SpeechConfig.kt | 2 +- .../com/google/firebase/ai/type/Voices.kt | 44 +++++-------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt index 8a25b47893f..9ba5b49ce6b 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt @@ -23,7 +23,7 @@ import kotlinx.serialization.Serializable @PublicPreviewAPI public class SpeechConfig( /** The voice to be used for the server's speech response. */ - public val voice: Voices + public val voice: Voices, ) { @Serializable diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt index ad26db572bc..92d03598a74 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt @@ -19,37 +19,17 @@ package com.google.firebase.ai.type import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -/** Various voices supported by the server */ +/** + * Various voices supported by the server. The list of all voices can be found + * [here](https://cloud.google.com/text-to-speech/docs/chirp3-hd) + */ @PublicPreviewAPI -public class Voices private constructor(public val ordinal: Int) { +public class Voices public constructor(public val voiceName: String) { @Serializable internal data class Internal(@SerialName("voice_name") val voiceName: String) - @Serializable - internal enum class InternalEnum { - CHARON, - AOEDE, - FENRIR, - KORE, - PUCK; - internal fun toPublic() = - when (this) { - CHARON -> Voices.CHARON - AOEDE -> Voices.AOEDE - FENRIR -> Voices.FENRIR - KORE -> Voices.KORE - else -> Voices.PUCK - } - } - internal fun toInternal(): Internal { - return when (this) { - CHARON -> Internal(InternalEnum.CHARON.name) - AOEDE -> Internal(InternalEnum.AOEDE.name) - FENRIR -> Internal(InternalEnum.FENRIR.name) - KORE -> Internal(InternalEnum.KORE.name) - else -> Internal(InternalEnum.PUCK.name) - } + return Internal(this.voiceName) } public companion object { @@ -58,21 +38,21 @@ public class Voices private constructor(public val ordinal: Int) { * * Will use the default voice of the model. */ - @JvmField public val UNSPECIFIED: Voices = Voices(0) + @JvmField public val UNSPECIFIED: Voices = Voices("Puck") /** Represents the Charon voice. */ - @JvmField public val CHARON: Voices = Voices(1) + @JvmField public val CHARON: Voices = Voices("Charon") /** Represents the Aoede voice. */ - @JvmField public val AOEDE: Voices = Voices(2) + @JvmField public val AOEDE: Voices = Voices("Aoede") /** Represents the Fenrir voice. */ - @JvmField public val FENRIR: Voices = Voices(3) + @JvmField public val FENRIR: Voices = Voices("Fenrir") /** Represents the Kore voice. */ - @JvmField public val KORE: Voices = Voices(4) + @JvmField public val KORE: Voices = Voices("Kore") /** Represents the Puck voice. */ - @JvmField public val PUCK: Voices = Voices(5) + @JvmField public val PUCK: Voices = Voices("Puck") } } From e60b9749b724095f5972ad7e0a1d9a4eedacb632 Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Tue, 27 May 2025 15:57:12 -0400 Subject: [PATCH 2/6] update --- .../src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt index 9ba5b49ce6b..8a25b47893f 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt @@ -23,7 +23,7 @@ import kotlinx.serialization.Serializable @PublicPreviewAPI public class SpeechConfig( /** The voice to be used for the server's speech response. */ - public val voice: Voices, + public val voice: Voices ) { @Serializable From 5e3c47c81db876b159f5450db1fc5a24d12460b4 Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 28 May 2025 14:58:37 -0400 Subject: [PATCH 3/6] update firebase ai --- firebase-ai/CHANGELOG.md | 3 ++- firebase-ai/api.txt | 5 +++-- firebase-ai/gradle.properties | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index 241a23f0f63..3cf1626c2fc 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -1,7 +1,8 @@ # Unreleased * [fixed] Fixed `FirebaseAI.getInstance` StackOverflowException (#6971) -* [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API. +* [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API. +* [changed] **Breaking Change**: Updated `Voices` to accept a voice name as an attribute # 16.0.0 * [feature] Initial release of the Firebase AI SDK (`firebase-ai`). This SDK *replaces* the previous diff --git a/firebase-ai/api.txt b/firebase-ai/api.txt index c9d55f52295..b22707eaabc 100644 --- a/firebase-ai/api.txt +++ b/firebase-ai/api.txt @@ -915,8 +915,9 @@ package com.google.firebase.ai.type { } @com.google.firebase.ai.type.PublicPreviewAPI public final class Voices { - method public int getOrdinal(); - property public final int ordinal; + ctor public Voices(String voiceName); + method public String getVoiceName(); + property public final String voiceName; field public static final com.google.firebase.ai.type.Voices AOEDE; field public static final com.google.firebase.ai.type.Voices CHARON; field public static final com.google.firebase.ai.type.Voices.Companion Companion; diff --git a/firebase-ai/gradle.properties b/firebase-ai/gradle.properties index b9f800fb7d6..1c7c87996dd 100644 --- a/firebase-ai/gradle.properties +++ b/firebase-ai/gradle.properties @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -version=16.0.1 +version=16.1.0 latestReleasedVersion=16.0.0 From 49d480cbd617f11c8ca5ce3bc5ee3dc0171538be Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 28 May 2025 15:18:12 -0400 Subject: [PATCH 4/6] use voice instead of voices --- firebase-ai/CHANGELOG.md | 5 ++- firebase-ai/api.txt | 31 +++++++------ .../google/firebase/ai/type/SpeechConfig.kt | 4 +- .../com/google/firebase/ai/type/Voice.kt | 34 ++++++++++++++ .../com/google/firebase/ai/type/Voices.kt | 45 ++++++++++++++----- 5 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voice.kt diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index 3cf1626c2fc..3244c980674 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -2,8 +2,11 @@ * [fixed] Fixed `FirebaseAI.getInstance` StackOverflowException (#6971) * [fixed] Fixed an issue that was causing the SDK to send empty `FunctionDeclaration` descriptions to the API. -* [changed] **Breaking Change**: Updated `Voices` to accept a voice name as an attribute +* [changed] Introduced the `Voice` class, which accepts a voice name, and deprecated the `Voices` class. +* [changed] **Breaking Change**: Updated `SpeechConfig` to take in `Voice` class instead of `Voices` class. + * **Action Required:** Update all references of `SpeechConfig` initialization to use `Voice` class. + # 16.0.0 * [feature] Initial release of the Firebase AI SDK (`firebase-ai`). This SDK *replaces* the previous Vertex AI in Firebase SDK (`firebase-vertexai`) to accommodate the evolving set of supported diff --git a/firebase-ai/api.txt b/firebase-ai/api.txt index b22707eaabc..5645b466110 100644 --- a/firebase-ai/api.txt +++ b/firebase-ai/api.txt @@ -863,9 +863,9 @@ package com.google.firebase.ai.type { } @com.google.firebase.ai.type.PublicPreviewAPI public final class SpeechConfig { - ctor public SpeechConfig(com.google.firebase.ai.type.Voices voice); - method public com.google.firebase.ai.type.Voices getVoice(); - property public final com.google.firebase.ai.type.Voices voice; + ctor public SpeechConfig(com.google.firebase.ai.type.Voice voice); + method public com.google.firebase.ai.type.Voice getVoice(); + property public final com.google.firebase.ai.type.Voice voice; } public abstract class StringFormat { @@ -914,20 +914,25 @@ package com.google.firebase.ai.type { property public final int totalTokenCount; } - @com.google.firebase.ai.type.PublicPreviewAPI public final class Voices { - ctor public Voices(String voiceName); + @com.google.firebase.ai.type.PublicPreviewAPI public final class Voice { + ctor public Voice(String voiceName); method public String getVoiceName(); property public final String voiceName; - field public static final com.google.firebase.ai.type.Voices AOEDE; - field public static final com.google.firebase.ai.type.Voices CHARON; - field public static final com.google.firebase.ai.type.Voices.Companion Companion; - field public static final com.google.firebase.ai.type.Voices FENRIR; - field public static final com.google.firebase.ai.type.Voices KORE; - field public static final com.google.firebase.ai.type.Voices PUCK; - field public static final com.google.firebase.ai.type.Voices UNSPECIFIED; } - public static final class Voices.Companion { + @Deprecated @com.google.firebase.ai.type.PublicPreviewAPI public final class Voices { + method @Deprecated public int getOrdinal(); + property @Deprecated public final int ordinal; + field @Deprecated public static final com.google.firebase.ai.type.Voices AOEDE; + field @Deprecated public static final com.google.firebase.ai.type.Voices CHARON; + field @Deprecated public static final com.google.firebase.ai.type.Voices.Companion Companion; + field @Deprecated public static final com.google.firebase.ai.type.Voices FENRIR; + field @Deprecated public static final com.google.firebase.ai.type.Voices KORE; + field @Deprecated public static final com.google.firebase.ai.type.Voices PUCK; + field @Deprecated public static final com.google.firebase.ai.type.Voices UNSPECIFIED; + } + + @Deprecated public static final class Voices.Companion { } } diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt index 8a25b47893f..12de21caff3 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/SpeechConfig.kt @@ -23,14 +23,14 @@ import kotlinx.serialization.Serializable @PublicPreviewAPI public class SpeechConfig( /** The voice to be used for the server's speech response. */ - public val voice: Voices + public val voice: Voice ) { @Serializable internal data class Internal(@SerialName("voice_config") val voiceConfig: VoiceConfigInternal) { @Serializable internal data class VoiceConfigInternal( - @SerialName("prebuilt_voice_config") val prebuiltVoiceConfig: Voices.Internal, + @SerialName("prebuilt_voice_config") val prebuiltVoiceConfig: Voice.Internal, ) } diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voice.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voice.kt new file mode 100644 index 00000000000..7053fc986cf --- /dev/null +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voice.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.firebase.ai.type + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Various voices supported by the server. The list of all voices can be found + * [here](https://cloud.google.com/text-to-speech/docs/chirp3-hd) + */ +@PublicPreviewAPI +public class Voice public constructor(public val voiceName: String) { + + @Serializable internal data class Internal(@SerialName("voice_name") val voiceName: String) + + internal fun toInternal(): Internal { + return Internal(this.voiceName) + } +} diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt index 92d03598a74..1f982c09a59 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt @@ -19,17 +19,38 @@ package com.google.firebase.ai.type import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -/** - * Various voices supported by the server. The list of all voices can be found - * [here](https://cloud.google.com/text-to-speech/docs/chirp3-hd) - */ +/** Various voices supported by the server */ +@Deprecated("Please use the Voice class instead.") @PublicPreviewAPI -public class Voices public constructor(public val voiceName: String) { +public class Voices private constructor(public val ordinal: Int) { @Serializable internal data class Internal(@SerialName("voice_name") val voiceName: String) + @Serializable + internal enum class InternalEnum { + CHARON, + AOEDE, + FENRIR, + KORE, + PUCK; + internal fun toPublic() = + when (this) { + CHARON -> Voices.CHARON + AOEDE -> Voices.AOEDE + FENRIR -> Voices.FENRIR + KORE -> Voices.KORE + else -> Voices.PUCK + } + } + internal fun toInternal(): Internal { - return Internal(this.voiceName) + return when (this) { + CHARON -> Internal(InternalEnum.CHARON.name) + AOEDE -> Internal(InternalEnum.AOEDE.name) + FENRIR -> Internal(InternalEnum.FENRIR.name) + KORE -> Internal(InternalEnum.KORE.name) + else -> Internal(InternalEnum.PUCK.name) + } } public companion object { @@ -38,21 +59,21 @@ public class Voices public constructor(public val voiceName: String) { * * Will use the default voice of the model. */ - @JvmField public val UNSPECIFIED: Voices = Voices("Puck") + @JvmField public val UNSPECIFIED: Voices = Voices(0) /** Represents the Charon voice. */ - @JvmField public val CHARON: Voices = Voices("Charon") + @JvmField public val CHARON: Voices = Voices(1) /** Represents the Aoede voice. */ - @JvmField public val AOEDE: Voices = Voices("Aoede") + @JvmField public val AOEDE: Voices = Voices(2) /** Represents the Fenrir voice. */ - @JvmField public val FENRIR: Voices = Voices("Fenrir") + @JvmField public val FENRIR: Voices = Voices(3) /** Represents the Kore voice. */ - @JvmField public val KORE: Voices = Voices("Kore") + @JvmField public val KORE: Voices = Voices(4) /** Represents the Puck voice. */ - @JvmField public val PUCK: Voices = Voices("Puck") + @JvmField public val PUCK: Voices = Voices(5) } } From 94c6f333a3a59f2a69008f0343c97b27854c79e7 Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 28 May 2025 16:06:16 -0400 Subject: [PATCH 5/6] use replace with --- .../src/main/kotlin/com/google/firebase/ai/type/Voices.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt index 1f982c09a59..d5e1f738dc2 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Voices.kt @@ -20,7 +20,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable /** Various voices supported by the server */ -@Deprecated("Please use the Voice class instead.") +@Deprecated("Please use the Voice class instead.", ReplaceWith("Voice")) @PublicPreviewAPI public class Voices private constructor(public val ordinal: Int) { From 7c6691856e6d3cfd8dbc2cd88929946cc82c8947 Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 28 May 2025 16:17:59 -0400 Subject: [PATCH 6/6] fix tests --- .../java/com/google/firebase/ai/JavaCompileTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java b/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java index 0c32921d5db..559c4ac8a04 100644 --- a/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java +++ b/firebase-ai/src/testUtil/java/com/google/firebase/ai/JavaCompileTests.java @@ -61,7 +61,7 @@ import com.google.firebase.ai.type.SpeechConfig; import com.google.firebase.ai.type.TextPart; import com.google.firebase.ai.type.UsageMetadata; -import com.google.firebase.ai.type.Voices; +import com.google.firebase.ai.type.Voice; import com.google.firebase.concurrent.FirebaseExecutors; import java.util.ArrayList; import java.util.Calendar; @@ -137,7 +137,7 @@ private LiveGenerationConfig getLiveConfig() { .setFrequencyPenalty(1.0F) .setPresencePenalty(2.0F) .setResponseModality(ResponseModality.AUDIO) - .setSpeechConfig(new SpeechConfig(Voices.AOEDE)) + .setSpeechConfig(new SpeechConfig(new Voice("AOEDE"))) .build(); }