diff --git a/lib/src/core/room.dart b/lib/src/core/room.dart index 181b87aa..ab44cc8a 100644 --- a/lib/src/core/room.dart +++ b/lib/src/core/room.dart @@ -116,6 +116,9 @@ class Room extends DisposableChangeNotifier with EventsEmittable { RegionUrlProvider? _regionUrlProvider; String? _regionUrl; + // Agents + final Map _transcriptionReceivedTimes = {}; + Room({ @Deprecated('deprecated, please use connectOptions in room.connect()') ConnectOptions connectOptions = const ConnectOptions(), @@ -790,24 +793,31 @@ class Room extends DisposableChangeNotifier with EventsEmittable { void _onTranscriptionEvent(EngineTranscriptionReceivedEvent event) { final participant = getParticipantByIdentity( event.transcription.transcribedParticipantIdentity); - if (participant == null) { + if (participant == null || event.transcription.segments.isEmpty) { return; } final publication = participant.getTrackPublicationBySid(event.transcription.trackId); - var segments = event.transcription.segments.map((e) { + var segments = event.transcription.segments.map((segment) { return TranscriptionSegment( - text: e.text, - id: e.id, - startTime: DateTime.fromMillisecondsSinceEpoch(e.startTime.toInt()), - endTime: DateTime.fromMillisecondsSinceEpoch(e.endTime.toInt()), - isFinal: e.final_5, - language: e.language, + text: segment.text, + id: segment.id, + firstReceivedTime: + _transcriptionReceivedTimes[segment.id] ?? DateTime.now(), + lastReceivedTime: DateTime.now(), + isFinal: segment.final_5, + language: segment.language, ); }).toList(); + for (var segment in segments) { + segment.isFinal + ? _transcriptionReceivedTimes.remove(segment.id) + : _transcriptionReceivedTimes[segment.id] = DateTime.now(); + } + final transcription = TranscriptionEvent( participant: participant, publication: publication, diff --git a/lib/src/events.dart b/lib/src/events.dart index 001d67a6..04ef406e 100644 --- a/lib/src/events.dart +++ b/lib/src/events.dart @@ -462,15 +462,15 @@ class ParticipantPermissionsUpdatedEvent with RoomEvent, ParticipantEvent { class TranscriptionSegment { final String id; final String text; - final DateTime startTime; - final DateTime endTime; + final DateTime firstReceivedTime; + final DateTime lastReceivedTime; final bool isFinal; final String language; const TranscriptionSegment({ required this.id, required this.text, - required this.startTime, - required this.endTime, + required this.firstReceivedTime, + required this.lastReceivedTime, required this.isFinal, required this.language, });