Skip to content

Commit

Permalink
Implemented remote tenant-aware transcriber configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rpurdel committed Sep 13, 2023
1 parent 6a5467b commit 45a4c8c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 19 deletions.
8 changes: 5 additions & 3 deletions jigasi-home/sip-communicator.properties
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ org.jitsi.jigasi.xmpp.acc.USE_DEFAULT_STUN_SERVER=false
# org.jitsi.jigasi.transcription.SEND_JSON=true
# org.jitsi.jigasi.transcription.SEND_TXT=false

# Tenant-aware transcription service
# org.jitsi.jigasi.transcription.customService={"tenant1": "org.jitsi.jigasi.transcription.WhisperTranscriptionService", "tenant2": "org.jitsi.jigasi.transcription.VoskTranscriptionService"}

# Vosk server
# org.jitsi.jigasi.transcription.customService=org.jitsi.jigasi.transcription.VoskTranscriptionService
# org.jitsi.jigasi.transcription.vosk.websocket_url={"en": "ws://localhost:2700", "fr": "ws://localhost:2710"}
Expand All @@ -218,6 +215,11 @@ org.jitsi.jigasi.xmpp.acc.USE_DEFAULT_STUN_SERVER=false
# org.jitsi.jigasi.transcription.whisper.private_key_name=<A_UNIQUE_ID_FOR_THE_KEY_NO_SPACES>
# org.jitsi.jigasi.transcription.whisper.websocket_url=ws://localhost:8000/ws/

# Tenant-aware transcription service URL
# Allows defining which transcription service to use by doing a remote call.
# Expects '{"transcriber": "some-valid-transcriber"}'
# https://<domain>/tenant-added-when-starting-transcription
# org.jitsi.jigasi.transcription.remoteTranscriptionConfigUrl=<https://domain>

# LibreTranslate server
# org.jitsi.jigasi.transcription.translationService=org.jitsi.jigasi.transcription.LibreTranslateTranslationService
Expand Down
67 changes: 51 additions & 16 deletions src/main/java/org/jitsi/jigasi/TranscriptionGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
package org.jitsi.jigasi;

import org.jitsi.jigasi.transcription.*;
import org.jitsi.jigasi.transcription.action.*;
import org.jitsi.utils.logging.*;
import org.jitsi.jigasi.transcription.action.ActionServicesHandler;
import org.jitsi.utils.logging.Logger;
import org.json.*;
import org.osgi.framework.*;
import org.osgi.framework.BundleContext;

import java.io.*;
import java.net.*;

/**
* A Gateway which creates a TranscriptionGatewaySession when it has an outgoing
Expand All @@ -45,6 +48,12 @@ public class TranscriptionGateway
private static final String CUSTOM_TRANSCRIPTION_SERVICE_PROP
= "org.jitsi.jigasi.transcription.customService";

/**
* Property for the class name of a custom transcription service.
*/
private static final String REMOTE_TRANSCRIPTION_CONFIG_URL
= "org.jitsi.jigasi.transcription.remoteTranscriptionConfigUrl";

/**
* Class which manages the desired {@link TranscriptPublisher} and
* {@link TranscriptionResultPublisher}
Expand Down Expand Up @@ -91,29 +100,55 @@ public void stop()
*/
private String getCustomTranscriptionServiceClass(String tenant)
{
String customTranscriptionServiceProp
String remoteTranscriptionConfigUrl
= JigasiBundleActivator.getConfigurationService()
.getString(
CUSTOM_TRANSCRIPTION_SERVICE_PROP,
REMOTE_TRANSCRIPTION_CONFIG_URL,
null);
if (customTranscriptionServiceProp.strip().startsWith("{"))

if (remoteTranscriptionConfigUrl != null)
{
if (tenant == null)
{
return null;
}
String transcriberClass = null;
try
{
JSONObject obj = new JSONObject(customTranscriptionServiceProp);
return obj.getString(tenant);
URL url = new URL(remoteTranscriptionConfigUrl + "/" + tenant);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
int responseCode = conn.getResponseCode();
if (responseCode == 200)
{
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder responseBody = new StringBuilder();
while ((inputLine = inputStream.readLine()) != null)
{
responseBody.append(inputLine);
}
inputStream.close();
logger.info("+++++++++ Received json " + responseBody);
JSONObject obj = new JSONObject(responseBody.toString());
transcriberClass = obj.getString("transcriber");
logger.info("+++++++++ Using " + transcriberClass + " as the transcriber class.");
}
else
{
logger.warn("+++++++++ Got HTTP status code " + responseCode);
}
conn.disconnect();
return transcriberClass;
}
catch (JSONException ex)
catch (Exception ex)
{
logger.warn("Could not find '" + tenant + "' tenant in custom transcription service JSON property.");
return null;
logger.error("+++++++++++++ Could not retrieve transcriber from remote URL." + ex);
}
}
return customTranscriptionServiceProp;

return JigasiBundleActivator.getConfigurationService()
.getString(
CUSTOM_TRANSCRIPTION_SERVICE_PROP,
null);
}

@Override
Expand Down

0 comments on commit 45a4c8c

Please sign in to comment.