diff --git a/.changeset/strong-readers-matter.md b/.changeset/strong-readers-matter.md new file mode 100644 index 000000000..3ffb18a5c --- /dev/null +++ b/.changeset/strong-readers-matter.md @@ -0,0 +1,5 @@ +--- +"client-sdk-android": patch +--- + +Fix transcription attributes not converting correctly diff --git a/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt b/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt index f8a3944b7..63fae1f02 100644 --- a/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt +++ b/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt @@ -17,6 +17,7 @@ package io.livekit.android.room.types import androidx.annotation.VisibleForTesting +import kotlinx.serialization.SerializationException import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray @@ -35,6 +36,8 @@ internal fun AgentAttributes.Companion.fromJsonObject(jsonObject: JsonObject) = jsonSerializer.decodeFromJsonElement(jsonObject) /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun AgentAttributes.Companion.fromMap(map: Map): AgentAttributes { @@ -46,6 +49,8 @@ fun AgentAttributes.Companion.fromMap(map: Map): AgentAttri } /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun AgentAttributes.Companion.fromStringMap(map: Map): AgentAttributes { @@ -75,6 +80,8 @@ internal fun TranscriptionAttributes.Companion.fromJsonObject(jsonObject: JsonOb jsonSerializer.decodeFromJsonElement(jsonObject) /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun TranscriptionAttributes.Companion.fromMap(map: Map): TranscriptionAttributes { @@ -86,6 +93,8 @@ fun TranscriptionAttributes.Companion.fromMap(map: Map): Tr } /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun TranscriptionAttributes.Companion.fromStringMap(map: Map): TranscriptionAttributes { @@ -107,5 +116,5 @@ fun TranscriptionAttributes.Companion.fromStringMap(map: Map): T val TRANSCRIPTION_ATTRIBUTES_CONVERSION = mapOf JsonElement?>( "lk.segment_id" to { json -> JsonPrimitive(json) }, "lk.transcribed_track_id" to { json -> JsonPrimitive(json) }, - "lk.transcription_final" to { json -> json?.let { jsonSerializer.decodeFromString(json) } }, + "lk.transcription_final" to { json -> json?.let { JsonPrimitive(json.toBooleanStrictOrNull()) } }, ) diff --git a/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt b/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt new file mode 100644 index 000000000..9cc5ec557 --- /dev/null +++ b/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2026 LiveKit, Inc. + * + * 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 io.livekit.android.room.types + +import org.junit.Assert.assertEquals +import org.junit.Test + +class TranscriptionAttributesTest { + + @Test + fun simpleConversion() { + val attributes = mapOf( + "lk.transcribed_track_id" to "track_id", + "lk.transcription_final" to "false", + "lk.segment_id" to "segment_id", + ) + + val transcriptionAttributes = TranscriptionAttributes.fromStringMap(attributes) + + assertEquals("track_id", transcriptionAttributes.lkTranscribedTrackID) + assertEquals(false, transcriptionAttributes.lkTranscriptionFinal) + assertEquals("segment_id", transcriptionAttributes.lkSegmentID) + } +}