Skip to content

Commit cce0fe2

Browse files
authored
feat: Adds metrics for the amount of audio sent to each transcriber (#558)
1 parent 509a4f6 commit cce0fe2

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

src/main/java/org/jitsi/jigasi/stats/Statistics.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ public class Statistics
129129
*/
130130
public static final String TOTAL_TRANSCRIBER_G_MINUTES = "total_transcriber_g_minutes";
131131

132+
/**
133+
* The total number of milliseconds submitted to Google API for transcription.
134+
*/
135+
public static final String TOTAL_TRANSCRIBER_GGL_MILLIS = "total_transcriber_ggl_millis";
136+
137+
/**
138+
* The total number of milliseconds submitted to Oracle API for transcription.
139+
*/
140+
public static final String TOTAL_TRANSCRIBER_OCI_MILLIS = "total_transcriber_oci_millis";
141+
142+
/**
143+
* The total number of milliseconds submitted to Skynet/Whisper for transcription.
144+
*/
145+
public static final String TOTAL_TRANSCRIBER_WSP_MILLIS = "total_transcriber_wsp_millis";
146+
147+
/**
148+
* The total number of milliseconds submitted to Vosk for transcription.
149+
*/
150+
public static final String TOTAL_TRANSCRIBER_VSK_MILLIS = "total_transcriber_vsk_millis";
151+
132152
/**
133153
* The total number of requests submitted to the Google Cloud Speech API.
134154
*/
@@ -317,6 +337,34 @@ public class Statistics
317337
TOTAL_TRANSCRIBER_G_REQUESTS,
318338
"Total number of transcriber requests.");
319339

340+
/**
341+
* The total number of milliseconds submitted to Google API for transcription.
342+
*/
343+
private static LongGaugeMetric totalTranscriberGoogleMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
344+
TOTAL_TRANSCRIBER_GGL_MILLIS,
345+
"Total number of milliseconds sent to Google's API.");
346+
347+
/**
348+
* The total number of milliseconds submitted to Oracle Cloud API for transcription.
349+
*/
350+
private static LongGaugeMetric totalTranscriberOracleMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
351+
TOTAL_TRANSCRIBER_OCI_MILLIS,
352+
"Total number of milliseconds sent to OCI API.");
353+
354+
/**
355+
* The total number of milliseconds submitted to Skynet Whisper for transcription.
356+
*/
357+
private static LongGaugeMetric totalTranscriberWhisperMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
358+
TOTAL_TRANSCRIBER_WSP_MILLIS,
359+
"Total number of milliseconds sent to Skynet Whisper.");
360+
361+
/**
362+
* The total number of milliseconds submitted to Vosk for transcription.
363+
*/
364+
private static LongGaugeMetric totalTranscriberVoskMillis = JigasiMetricsContainer.INSTANCE.registerLongGauge(
365+
TOTAL_TRANSCRIBER_VSK_MILLIS,
366+
"Total number of milliseconds sent to Vosk.");
367+
320368
/**
321369
* Cumulative number of seconds of all conferences.
322370
*/
@@ -407,6 +455,10 @@ public static synchronized void sendJSON(
407455

408456
stats.put(TOTAL_TRANSCRIBER_G_REQUESTS, totalTrasnscriberRequests.get());
409457
stats.put(TOTAL_TRANSCRIBER_G_MINUTES, totalTranscriberMinutes.get());
458+
stats.put(TOTAL_TRANSCRIBER_GGL_MILLIS, totalTranscriberGoogleMillis.get());
459+
stats.put(TOTAL_TRANSCRIBER_OCI_MILLIS, totalTranscriberOracleMillis.get());
460+
stats.put(TOTAL_TRANSCRIBER_WSP_MILLIS, totalTranscriberWhisperMillis.get());
461+
stats.put(TOTAL_TRANSCRIBER_VSK_MILLIS, totalTranscriberVoskMillis.get());
410462

411463
stats.put(TOTAL_TRANSCRIBER_STARTED, totalTrasnscriberStarted.get());
412464
stats.put(TOTAL_TRANSCRIBER_STOPPED, totalTrasnscriberStopped.get());
@@ -636,6 +688,38 @@ public static void incrementTotalTranscriberMinutes(long value)
636688
totalTranscriberMinutes.addAndGet(value);
637689
}
638690

691+
/**
692+
* Increment the value of total number of milliseconds sent to Google API for transcription.
693+
*/
694+
public static void incrementTotalTranscriberGoogleMillis(long value)
695+
{
696+
totalTranscriberGoogleMillis.addAndGet(value);
697+
}
698+
699+
/**
700+
* Increment the value of total number of milliseconds sent to Oracle API for transcription.
701+
*/
702+
public static void incrementTotalTranscriberOracleMillis(long value)
703+
{
704+
totalTranscriberOracleMillis.addAndGet(value);
705+
}
706+
707+
/**
708+
* Increment the value of total number of milliseconds sent to Skynet Whisper for transcription.
709+
*/
710+
public static void incrementTotalTranscriberWhisperMillis(long value)
711+
{
712+
totalTranscriberWhisperMillis.addAndGet(value);
713+
}
714+
715+
/**
716+
* Increment the value of total number of milliseconds sent to Vosk for transcription.
717+
*/
718+
public static void incrementTotalTranscriberVoskMillis(long value)
719+
{
720+
totalTranscriberVoskMillis.addAndGet(value);
721+
}
722+
639723
/**
640724
* Increment the value of total number of transcriber request.
641725
*/

src/main/java/org/jitsi/jigasi/transcription/Participant.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.jitsi.xmpp.extensions.jitsimeet.*;
2424
import org.jitsi.utils.logging.*;
2525
import org.jivesoftware.smack.packet.*;
26+
import org.jitsi.jigasi.stats.*;
2627

2728
import javax.media.format.*;
2829
import java.nio.*;
@@ -152,6 +153,8 @@ public class Participant
152153
*/
153154
private SilenceFilter silenceFilter = null;
154155

156+
private String transcriptionServiceName;
157+
155158
/**
156159
* Create a participant with a given name and audio stream
157160
*
@@ -173,6 +176,7 @@ public class Participant
173176
{
174177
this.transcriber = transcriber;
175178
this.identifier = identifier;
179+
this.transcriptionServiceName = transcriber.getTranscriptionService().getClass().getSimpleName();
176180

177181
if (filterAudio)
178182
{
@@ -661,6 +665,35 @@ else if (silenceFilter.newSpeech())
661665
});
662666
}
663667

668+
private void incrementSentStats(int byteCount)
669+
{
670+
int divider = EXPECTED_AUDIO_LENGTH;
671+
672+
if (transcriptionServiceName.equals("WhisperTranscriptionService")
673+
|| transcriptionServiceName.equals("OracleTranscriptionService"))
674+
{
675+
// the byte count for each 20ms packet if the audio format is 16kHz mono
676+
divider = 640;
677+
}
678+
679+
long millis = byteCount / divider * 20;
680+
681+
switch (transcriptionServiceName) {
682+
case "WhisperTranscriptionService":
683+
Statistics.incrementTotalTranscriberWhisperMillis(millis);
684+
break;
685+
case "OracleTranscriptionService":
686+
Statistics.incrementTotalTranscriberOracleMillis(millis);
687+
break;
688+
case "VoskTranscriptionService":
689+
Statistics.incrementTotalTranscriberVoskMillis(millis);
690+
break;
691+
case "GoogleCloudTranscriptionService":
692+
Statistics.incrementTotalTranscriberGoogleMillis(millis);
693+
break;
694+
}
695+
}
696+
664697
/**
665698
* Send the specified audio to the TranscriptionService.
666699
* <p>
@@ -681,6 +714,7 @@ private void sendRequest(byte[] audio)
681714
if (session != null && !session.ended())
682715
{
683716
session.sendRequest(request);
717+
incrementSentStats(audio.length);
684718
}
685719
else if (transcriber.getTranscriptionService().supportsStreamRecognition())
686720
// re-establish prematurely ended streaming session
@@ -704,6 +738,7 @@ else if (transcriber.getTranscriptionService().supportsStreamRecognition())
704738
transcriber.getTranscriptionService().sendSingleRequest(
705739
request,
706740
this::notify);
741+
incrementSentStats(audio.length);
707742
}
708743
});
709744
}

0 commit comments

Comments
 (0)