Skip to content
2 changes: 1 addition & 1 deletion firebase-ai/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

version=17.4.0
version=99.9.9
latestReleasedVersion=17.3.0
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -270,6 +271,7 @@ internal constructor(
Json.encodeToString(
BidiGenerateContentRealtimeInputSetup(mediaChunks.map { (it.toInternal()) }).toInternal()
)
println("Sending $jsonString")
session.send(Frame.Text(jsonString))
}
}
Expand Down Expand Up @@ -372,6 +374,7 @@ internal constructor(
if (it.interrupted) {
playBackQueue.clear()
} else {
println("Sending audio parts")
val audioParts = it.content?.parts?.filterIsInstance<InlineDataPart>().orEmpty()
for (part in audioParts) {
playBackQueue.add(part.inlineData)
Expand All @@ -387,7 +390,7 @@ internal constructor(
}
}
}
.launchIn(scope)
.launchIn(CoroutineScope(Dispatchers.IO))
}

/**
Expand All @@ -398,7 +401,7 @@ internal constructor(
* Launched asynchronously on [scope].
*/
private fun listenForModelPlayback(enableInterruptions: Boolean = false) {
scope.launch {
CoroutineScope(Dispatchers.IO).launch {
while (isActive) {
val playbackData = playBackQueue.poll()
if (playbackData == null) {
Expand All @@ -414,7 +417,7 @@ internal constructor(
* no echo cancellation
*/
// TODO(b/408223520): Conditionally pause when param is added
if (enableInterruptions != true) {
if (!enableInterruptions) {
audioHelper?.pauseRecording()
}
audioHelper?.playAudio(playbackData)
Expand Down
Loading