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

Add metrics for the amount of audio sent to each transcriber #558

Merged
merged 1 commit into from
Oct 10, 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
84 changes: 84 additions & 0 deletions src/main/java/org/jitsi/jigasi/stats/Statistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ public class Statistics
*/
public static final String TOTAL_TRANSCRIBER_G_MINUTES = "total_transcriber_g_minutes";

/**
* The total number of milliseconds submitted to Google API for transcription.
*/
public static final String TOTAL_TRANSCRIBER_GGL_MILLIS = "total_transcriber_ggl_millis";

/**
* The total number of milliseconds submitted to Oracle API for transcription.
*/
public static final String TOTAL_TRANSCRIBER_OCI_MILLIS = "total_transcriber_oci_millis";

/**
* The total number of milliseconds submitted to Skynet/Whisper for transcription.
*/
public static final String TOTAL_TRANSCRIBER_WSP_MILLIS = "total_transcriber_wsp_millis";

/**
* The total number of milliseconds submitted to Vosk for transcription.
*/
public static final String TOTAL_TRANSCRIBER_VSK_MILLIS = "total_transcriber_vsk_millis";

/**
* The total number of requests submitted to the Google Cloud Speech API.
*/
Expand Down Expand Up @@ -317,6 +337,34 @@ public class Statistics
TOTAL_TRANSCRIBER_G_REQUESTS,
"Total number of transcriber requests.");

/**
* The total number of milliseconds submitted to Google API for transcription.
*/
private static LongGaugeMetric totalTranscriberGoogleMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
TOTAL_TRANSCRIBER_GGL_MILLIS,
"Total number of milliseconds sent to Google's API.");

/**
* The total number of milliseconds submitted to Oracle Cloud API for transcription.
*/
private static LongGaugeMetric totalTranscriberOracleMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
TOTAL_TRANSCRIBER_OCI_MILLIS,
"Total number of milliseconds sent to OCI API.");

/**
* The total number of milliseconds submitted to Skynet Whisper for transcription.
*/
private static LongGaugeMetric totalTranscriberWhisperMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
TOTAL_TRANSCRIBER_WSP_MILLIS,
"Total number of milliseconds sent to Skynet Whisper.");

/**
* The total number of milliseconds submitted to Vosk for transcription.
*/
private static LongGaugeMetric totalTranscriberVoskMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
TOTAL_TRANSCRIBER_VSK_MILLIS,
"Total number of milliseconds sent to Vosk.");

/**
* Cumulative number of seconds of all conferences.
*/
Expand Down Expand Up @@ -407,6 +455,10 @@ public static synchronized void sendJSON(

stats.put(TOTAL_TRANSCRIBER_G_REQUESTS, totalTrasnscriberRequests.get());
stats.put(TOTAL_TRANSCRIBER_G_MINUTES, totalTranscriberMinutes.get());
stats.put(TOTAL_TRANSCRIBER_GGL_MILLIS, totalTranscriberGoogleMillis.get());
stats.put(TOTAL_TRANSCRIBER_OCI_MILLIS, totalTranscriberOracleMillis.get());
stats.put(TOTAL_TRANSCRIBER_WSP_MILLIS, totalTranscriberWhisperMillis.get());
stats.put(TOTAL_TRANSCRIBER_VSK_MILLIS, totalTranscriberVoskMillis.get());

stats.put(TOTAL_TRANSCRIBER_STARTED, totalTrasnscriberStarted.get());
stats.put(TOTAL_TRANSCRIBER_STOPPED, totalTrasnscriberStopped.get());
Expand Down Expand Up @@ -636,6 +688,38 @@ public static void incrementTotalTranscriberMinutes(long value)
totalTranscriberMinutes.addAndGet(value);
}

/**
* Increment the value of total number of milliseconds sent to Google API for transcription.
*/
public static void incrementTotalTranscriberGoogleMillis(long value)
{
totalTranscriberGoogleMillis.addAndGet(value);
}

/**
* Increment the value of total number of milliseconds sent to Oracle API for transcription.
*/
public static void incrementTotalTranscriberOracleMillis(long value)
{
totalTranscriberOracleMillis.addAndGet(value);
}

/**
* Increment the value of total number of milliseconds sent to Skynet Whisper for transcription.
*/
public static void incrementTotalTranscriberWhisperMillis(long value)
{
totalTranscriberWhisperMillis.addAndGet(value);
}

/**
* Increment the value of total number of milliseconds sent to Vosk for transcription.
*/
public static void incrementTotalTranscriberVoskMillis(long value)
{
totalTranscriberVoskMillis.addAndGet(value);
}

/**
* Increment the value of total number of transcriber request.
*/
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/jitsi/jigasi/transcription/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jitsi.xmpp.extensions.jitsimeet.*;
import org.jitsi.utils.logging.*;
import org.jivesoftware.smack.packet.*;
import org.jitsi.jigasi.stats.*;

import javax.media.format.*;
import java.nio.*;
Expand Down Expand Up @@ -152,6 +153,8 @@ public class Participant
*/
private SilenceFilter silenceFilter = null;

private String transcriptionServiceName;

/**
* Create a participant with a given name and audio stream
*
Expand All @@ -173,6 +176,7 @@ public class Participant
{
this.transcriber = transcriber;
this.identifier = identifier;
this.transcriptionServiceName = transcriber.getTranscriptionService().getClass().getSimpleName();

if (filterAudio)
{
Expand Down Expand Up @@ -661,6 +665,35 @@ else if (silenceFilter.newSpeech())
});
}

private void incrementSentStats(int byteCount)
{
int divider = EXPECTED_AUDIO_LENGTH;

if (transcriptionServiceName.equals("WhisperTranscriptionService")
|| transcriptionServiceName.equals("OracleTranscriptionService"))
{
// the byte count for each 20ms packet if the audio format is 16kHz mono
divider = 640;
}

long millis = byteCount / divider * 20;

switch (transcriptionServiceName) {
case "WhisperTranscriptionService":
Statistics.incrementTotalTranscriberWhisperMillis(millis);
break;
case "OracleTranscriptionService":
Statistics.incrementTotalTranscriberOracleMillis(millis);
break;
case "VoskTranscriptionService":
Statistics.incrementTotalTranscriberVoskMillis(millis);
break;
case "GoogleCloudTranscriptionService":
Statistics.incrementTotalTranscriberGoogleMillis(millis);
break;
}
}

/**
* Send the specified audio to the TranscriptionService.
* <p>
Expand All @@ -681,6 +714,7 @@ private void sendRequest(byte[] audio)
if (session != null && !session.ended())
{
session.sendRequest(request);
incrementSentStats(audio.length);
}
else if (transcriber.getTranscriptionService().supportsStreamRecognition())
// re-establish prematurely ended streaming session
Expand All @@ -704,6 +738,7 @@ else if (transcriber.getTranscriptionService().supportsStreamRecognition())
transcriber.getTranscriptionService().sendSingleRequest(
request,
this::notify);
incrementSentStats(audio.length);
}
});
}
Expand Down
Loading