Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set the timestamps from jigasi #542

Merged
merged 5 commits into from
Aug 22, 2024
Merged
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
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
Loading