Skip to content

Commit

Permalink
feat(transcription): Adds additional languages via metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Sep 10, 2024
1 parent c53ba86 commit 19ca20d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/org/jitsi/jigasi/JvbConference.java
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,14 @@ private void processRoomMetadataJson(String json)
JSONObject recordingObj = (JSONObject)metadataObj.getOrDefault("recording", new JSONObject());
((TranscriptionGatewaySession)this.gatewaySession).setBackendTranscribingEnabled(
(boolean)recordingObj.getOrDefault("isTranscribingEnabled", false));

JSONObject visitorsObj = (JSONObject)metadataObj.getOrDefault("visitors", new JSONObject());
String languages = (String)visitorsObj.get("transcribingLanguages");
if (StringUtils.isNotEmpty(languages))
{
((TranscriptionGatewaySession)this.gatewaySession)
.updateTranslateLanguages(languages.split(","));
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ 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<>();

/**
* Create a TranscriptionGatewaySession which can handle the transcription
* of a JVB conference
Expand Down Expand Up @@ -753,4 +759,22 @@ public void setBackendTranscribingEnabled(boolean backendTranscribingEnabled)

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

0 comments on commit 19ca20d

Please sign in to comment.