Skip to content

Commit c825e76

Browse files
authored
Fix TranscriptionAttributes not being converted correctly (#889)
* Fix TranscriptionAttributes not being converted correctly * changesets and spotless
1 parent ff5d662 commit c825e76

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"client-sdk-android": patch
3+
---
4+
5+
Fix transcription attributes not converting correctly

livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.livekit.android.room.types
1818

1919
import androidx.annotation.VisibleForTesting
20+
import kotlinx.serialization.SerializationException
2021
import kotlinx.serialization.decodeFromString
2122
import kotlinx.serialization.json.Json
2223
import kotlinx.serialization.json.JsonArray
@@ -35,6 +36,8 @@ internal fun AgentAttributes.Companion.fromJsonObject(jsonObject: JsonObject) =
3536
jsonSerializer.decodeFromJsonElement<AgentAttributes>(jsonObject)
3637

3738
/**
39+
* @throws [SerializationException] if the given JSON element is not a valid JSON input
40+
* @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance
3841
* @suppress
3942
*/
4043
fun AgentAttributes.Companion.fromMap(map: Map<String, JsonElement>): AgentAttributes {
@@ -46,6 +49,8 @@ fun AgentAttributes.Companion.fromMap(map: Map<String, JsonElement>): AgentAttri
4649
}
4750

4851
/**
52+
* @throws [SerializationException] if the given JSON element is not a valid JSON input
53+
* @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance
4954
* @suppress
5055
*/
5156
fun AgentAttributes.Companion.fromStringMap(map: Map<String, String>): AgentAttributes {
@@ -75,6 +80,8 @@ internal fun TranscriptionAttributes.Companion.fromJsonObject(jsonObject: JsonOb
7580
jsonSerializer.decodeFromJsonElement<TranscriptionAttributes>(jsonObject)
7681

7782
/**
83+
* @throws [SerializationException] if the given JSON element is not a valid JSON input
84+
* @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance
7885
* @suppress
7986
*/
8087
fun TranscriptionAttributes.Companion.fromMap(map: Map<String, JsonElement>): TranscriptionAttributes {
@@ -86,6 +93,8 @@ fun TranscriptionAttributes.Companion.fromMap(map: Map<String, JsonElement>): Tr
8693
}
8794

8895
/**
96+
* @throws [SerializationException] if the given JSON element is not a valid JSON input
97+
* @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance
8998
* @suppress
9099
*/
91100
fun TranscriptionAttributes.Companion.fromStringMap(map: Map<String, String>): TranscriptionAttributes {
@@ -107,5 +116,5 @@ fun TranscriptionAttributes.Companion.fromStringMap(map: Map<String, String>): T
107116
val TRANSCRIPTION_ATTRIBUTES_CONVERSION = mapOf<String, (String?) -> JsonElement?>(
108117
"lk.segment_id" to { json -> JsonPrimitive(json) },
109118
"lk.transcribed_track_id" to { json -> JsonPrimitive(json) },
110-
"lk.transcription_final" to { json -> json?.let { jsonSerializer.decodeFromString<JsonArray>(json) } },
119+
"lk.transcription_final" to { json -> json?.let { JsonPrimitive(json.toBooleanStrictOrNull()) } },
111120
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2026 LiveKit, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.livekit.android.room.types
18+
19+
import org.junit.Assert.assertEquals
20+
import org.junit.Test
21+
22+
class TranscriptionAttributesTest {
23+
24+
@Test
25+
fun simpleConversion() {
26+
val attributes = mapOf(
27+
"lk.transcribed_track_id" to "track_id",
28+
"lk.transcription_final" to "false",
29+
"lk.segment_id" to "segment_id",
30+
)
31+
32+
val transcriptionAttributes = TranscriptionAttributes.fromStringMap(attributes)
33+
34+
assertEquals("track_id", transcriptionAttributes.lkTranscribedTrackID)
35+
assertEquals(false, transcriptionAttributes.lkTranscriptionFinal)
36+
assertEquals("segment_id", transcriptionAttributes.lkSegmentID)
37+
}
38+
}

0 commit comments

Comments
 (0)