Skip to content

Commit

Permalink
fix(whisper): set the timestamps from jigasi (#542)
Browse files Browse the repository at this point in the history
* fix: prefer setting the timestamps from jigasi

* fix: set the ts hashmap to null on disconnect

* fix: remove unused variable

* Fix logging message

* fix conflicts
  • Loading branch information
rpurdel authored Aug 22, 2024
1 parent babd518 commit c53ba86
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.jitsi.jigasi.transcription;

import com.fasterxml.uuid.*;
import org.eclipse.jetty.websocket.api.*;
import org.eclipse.jetty.websocket.api.annotations.*;
import org.eclipse.jetty.websocket.client.*;
Expand All @@ -42,10 +43,14 @@ public class WhisperWebsocket

private Map<String, Set<TranscriptionListener>> participantListeners = new ConcurrentHashMap<>();

private Map<String, Instant> participantTranscriptionStarts = new ConcurrentHashMap<>();

private Map<String, UUID> participantTranscriptionIds= new ConcurrentHashMap<>();

private static final int maxRetryAttempts = 10;


/* Transcription language requested by the user who requested the transcription */
/* Transcription language requested by the user who started the transcription */
public String transcriptionTag = "en-US";

private final static Logger logger
Expand Down Expand Up @@ -209,6 +214,8 @@ public void onClose(int statusCode, String reason)
wsSession = null;
participants = null;
participantListeners = null;
participantTranscriptionStarts = null;
participantTranscriptionIds = null;
try
{
if (ws != null)
Expand Down Expand Up @@ -239,13 +246,24 @@ public void onMessage(String msg)
}

result = obj.getString("text");
UUID id = UUID.fromString(obj.getString("id"));
Instant transcriptionStart = Instant.ofEpochMilli(obj.getLong("ts"));
float stability = obj.getFloat("variance");
if (logger.isDebugEnabled())
{
logger.debug("Received final: " + result);
logger.debug("Received result: " + result);
}

Instant startTranscription = participantTranscriptionStarts.getOrDefault(participantId, null);
UUID transcriptionId = participantTranscriptionIds.getOrDefault(participantId, null);

if (startTranscription == null)
{
Date now = new Date();
startTranscription = now.toInstant();
transcriptionId = Generators.timeBasedReorderedGenerator().generate();
participantTranscriptionIds.put(participantId, transcriptionId);
participantTranscriptionStarts.put(participantId, startTranscription);
}

Set<TranscriptionListener> partListeners = participantListeners.getOrDefault(participantId, null);
if (!result.isEmpty() && partListeners != null)
{
Expand All @@ -261,15 +279,20 @@ public void onMessage(String msg)
}
TranscriptionResult tsResult = new TranscriptionResult(
participant,
id,
transcriptionStart,
transcriptionId,
startTranscription,
partial,
getLanguage(participant),
stability,
new TranscriptionAlternative(result));
l.notify(tsResult);
}
}
if (!partial)
{
participantTranscriptionStarts.remove(participantId);
participantTranscriptionIds.remove(participantId);
}
}


Expand Down

0 comments on commit c53ba86

Please sign in to comment.