Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-readers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": patch
---

Fix transcription attributes not converting correctly
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +36,8 @@ internal fun AgentAttributes.Companion.fromJsonObject(jsonObject: JsonObject) =
jsonSerializer.decodeFromJsonElement<AgentAttributes>(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<String, JsonElement>): AgentAttributes {
Expand All @@ -46,6 +49,8 @@ fun AgentAttributes.Companion.fromMap(map: Map<String, JsonElement>): 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<String, String>): AgentAttributes {
Expand Down Expand Up @@ -75,6 +80,8 @@ internal fun TranscriptionAttributes.Companion.fromJsonObject(jsonObject: JsonOb
jsonSerializer.decodeFromJsonElement<TranscriptionAttributes>(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<String, JsonElement>): TranscriptionAttributes {
Expand All @@ -86,6 +93,8 @@ fun TranscriptionAttributes.Companion.fromMap(map: Map<String, JsonElement>): 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<String, String>): TranscriptionAttributes {
Expand All @@ -107,5 +116,5 @@ fun TranscriptionAttributes.Companion.fromStringMap(map: Map<String, String>): T
val TRANSCRIPTION_ATTRIBUTES_CONVERSION = mapOf<String, (String?) -> 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<JsonArray>(json) } },
"lk.transcription_final" to { json -> json?.let { JsonPrimitive(json.toBooleanStrictOrNull()) } },
)
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading