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

feat(transcription): Adds additional languages via metadata. #545

Merged
merged 3 commits into from
Sep 13, 2024
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
16 changes: 14 additions & 2 deletions src/main/java/org/jitsi/jigasi/JvbConference.java
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,8 @@ else if (ChatRoomMemberPresenceChangeEvent.MEMBER_UPDATED
+ " " + member.getContactAddress());

CallPeer peer;
if (jvbCall != null && (peer = jvbCall.getCallPeers().next()) instanceof MediaAwareCallPeer)
if (jvbCall != null && jvbCall.getCallPeerCount() > 0
&& (peer = jvbCall.getCallPeers().next()) instanceof MediaAwareCallPeer)
{
MediaAwareCallPeer<?, ?, ?> peerMedia = (MediaAwareCallPeer<?, ?, ?>) peer;
peerMedia.getConferenceMembers().forEach(confMember ->
Expand Down Expand Up @@ -2212,10 +2213,21 @@ private void processRoomMetadataJson(String json)

if (data.get("type").equals("room_metadata"))
{
TranscriptionGatewaySession transcriptionSession = (TranscriptionGatewaySession)this.gatewaySession;

JSONObject metadataObj = (JSONObject)data.getOrDefault("metadata", new JSONObject());
JSONObject recordingObj = (JSONObject)metadataObj.getOrDefault("recording", new JSONObject());
((TranscriptionGatewaySession)this.gatewaySession).setBackendTranscribingEnabled(
transcriptionSession.setBackendTranscribingEnabled(
(boolean)recordingObj.getOrDefault("isTranscribingEnabled", false));

JSONObject visitorsObj = (JSONObject)metadataObj.getOrDefault("visitors", new JSONObject());
String languages = (String)visitorsObj.get("transcribingLanguages");
if (StringUtils.isNotEmpty(languages))
{
transcriptionSession.updateTranslateLanguages(languages.split(","));
}
transcriptionSession.setVisitorsCountRequestingTranscription(
Integer.parseInt((String)visitorsObj.get("transcribingCount")));
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jitsi/jigasi/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public class Main
"org.jivesoftware.smackx.si",
"org.jivesoftware.smackx.vcardtemp",
"org.jivesoftware.smackx.xhtmlim",
"org.jivesoftware.smackx.xdata",
"org.jivesoftware.smackx.eme",
"org.jivesoftware.smackx.iqprivate",
"org.jivesoftware.smackx.bookmarks",
Expand Down
43 changes: 42 additions & 1 deletion src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public class TranscriptionGatewaySession
*/
private int numberOfScheduledParticipantsLeaving = 0;

/**
* The currently used additional languages for translation.
* Used for visitors to announce the languages used by visitors.
*/
private List<String> additionalLanguages = new ArrayList<>();

/**
* The number of visitors that are requesting transcriptions.
*/
private int numberOfVisitorsRequestingTranscription = 0;

/**
* Create a TranscriptionGatewaySession which can handle the transcription
* of a JVB conference
Expand Down Expand Up @@ -359,7 +370,9 @@ void notifyChatRoomMemberUpdated(ChatRoomMember chatMember, Presence presence)

private boolean isTranscriptionRequested()
{
return transcriber.isAnyParticipantRequestingTranscription() || isBackendTranscribingEnabled;
return transcriber.isAnyParticipantRequestingTranscription()
|| isBackendTranscribingEnabled
|| this.numberOfVisitorsRequestingTranscription > 0;
}

private void maybeStopTranscription()
Expand Down Expand Up @@ -753,4 +766,32 @@ public void setBackendTranscribingEnabled(boolean backendTranscribingEnabled)

this.maybeStopTranscription();
}

/**
* @param count The count of visitors that are requesting transcriptions.
*/
public void setVisitorsCountRequestingTranscription(int count)
{
this.numberOfVisitorsRequestingTranscription = count;

this.maybeStopTranscription();
}

/**
* To update all participant languages with the additional that are provided.
* @param additionalLanguages languages to add to those from the participants.
*/
void updateTranslateLanguages(String[] additionalLanguages)
{
List<String> oldLangs = this.additionalLanguages;
this.additionalLanguages = Arrays.asList(additionalLanguages);

// remove unused streams
oldLangs.stream().filter(s -> !this.additionalLanguages.contains(s))
.forEach(lang -> this.transcriber.getTranslationManager().removeLanguage(lang));

// add new languages
this.additionalLanguages.stream().filter(s -> !oldLangs.contains(s))
.forEach(lang -> this.transcriber.getTranslationManager().addLanguage(lang));
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/jitsi/jigasi/transcription/Transcriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,14 @@ public TranscriptionService getTranscriptionService()
return transcriptionService;
}

/**
* @return the {@link TranslationManager}.
*/
public TranslationManager getTranslationManager()
{
return this.translationManager;
}

/**
* Notifies all of the listeners of this {@link Transcriber} of a new
* {@link TranscriptionResult} which was received.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,15 @@ private List<TranslationResult> getTranslations(
{
for (String targetLanguage : translationLanguages)
{
String sourceLang = result.getParticipant().getSourceLanguage();
if (sourceLang != null && sourceLang.equals(targetLanguage))
{
continue;
}

String translatedText = translationService.translate(
alternatives.iterator().next().getTranscription(),
result.getParticipant().getSourceLanguage(),
sourceLang,
targetLanguage);

translatedResults.add(new TranslationResult(
Expand Down
Loading