From 26779fdf1e8848936d5205a3261c179da7b64ecb Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 23 Jul 2025 12:15:53 +0000 Subject: [PATCH] Fix(AI): Route audio to speaker instead of earpiece The AudioHelper was configured to use `USAGE_VOICE_COMMUNICATION`, which routes audio through the earpiece. This is not ideal for the text-to-speech functionality of the AI SDK. This change updates the `AudioAttributes` to use `USAGE_MEDIA` and `CONTENT_TYPE_SPEECH` to route the audio to the device's speaker. --- .../main/kotlin/com/google/firebase/ai/type/AudioHelper.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/AudioHelper.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/AudioHelper.kt index 4db66ae6c3e..6cde4c1b14d 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/AudioHelper.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/AudioHelper.kt @@ -163,7 +163,10 @@ internal class AudioHelper( fun build(): AudioHelper { val playbackTrack = AudioTrack( - AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION).build(), + AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_MEDIA) + .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH) + .build(), AudioFormat.Builder() .setSampleRate(24000) .setChannelMask(AudioFormat.CHANNEL_OUT_MONO)