Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat: Add an option to render speaker ID for transcriptions. (#17390)

bgrozevb584e555d590
diff --git a/config.js b/config.js
index f0e1947919..d5fa3ac8b7 100644
--- a/config.js
+++ b/config.js
@@ -531,6 +531,10 @@ var config = {
// // subtitles on stage and the "Show subtitles on stage" checkbox in the settings.
// // Note: Starting transcriptions from the recording dialog will still work.
// disableClosedCaptions: false,
+ //
+ // // When the backend provides diarization by setting a "speaker" field, append [Speaker N] for transcription
+ // // events from non-0 speakers.
+ // renderTranscriptDetails: false
// },
diff --git a/react/features/base/config/configType.ts b/react/features/base/config/configType.ts
index 283bceadf3..37e47876d0 100644
--- a/react/features/base/config/configType.ts
+++ b/react/features/base/config/configType.ts
@@ -700,6 +700,7 @@ export interface IConfig {
disableClosedCaptions?: boolean;
enabled?: boolean;
preferredLanguage?: string;
+ renderTranscriptDetails?: boolean;
translationLanguages?: Array<string>;
translationLanguagesHead?: Array<string>;
useAppLanguage?: boolean;
diff --git a/react/features/subtitles/middleware.ts b/react/features/subtitles/middleware.ts
index 58738a9e56..8cc0c40243 100644
--- a/react/features/subtitles/middleware.ts
+++ b/react/features/subtitles/middleware.ts
@@ -156,6 +156,23 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
};
const { timestamp } = json;
const participantId = participant.id;
+ const speaker = json.speaker;
+ const renderTranscriptDetails = state['features/base/config'].transcription?.renderTranscriptDetails;
+ let detailsPrefix = '';
+
+ if (renderTranscriptDetails) {
+ const parts = [];
+
+ if (speaker != null) {
+ parts.push(`Speaker ${speaker}`);
+ }
+ if (json.language) {
+ parts.push(json.language);
+ }
+ if (parts.length > 0) {
+ detailsPrefix = `[${parts.join(', ')}] `;
+ }
+ }
// Handle transcript messages
const language = state['features/base/conference'].conference
@@ -170,7 +187,8 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
return next(action);
}
- const translation = json.text?.trim();
+ const translationText = json.text?.trim();
+ const translation = translationText ? `${detailsPrefix}${translationText}` : translationText;
if (isCCTabEnabled(state)) {
dispatch(storeSubtitle({
@@ -191,7 +209,7 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
// enabled.
newTranscriptMessage = {
clearTimeOut: undefined,
- final: json.text?.trim(),
+ final: translation,
participant
};
}
@@ -202,6 +220,7 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
// translations are disabled.
const { text } = json.transcript[0];
+ const displayText = `${detailsPrefix}${text}`;
// First, notify the external API.
if (!(isInterim && skipInterimTranscriptions)) {
@@ -253,7 +272,7 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
id: transcriptMessageID,
participantId,
language: json.language,
- text,
+ text: displayText,
interim: isInterim,
timestamp,
isTranscription: true
@@ -290,17 +309,17 @@ function _endpointMessageReceived(store: IStore, next: Function, action: AnyActi
// If this is final result, update the state as a final result
// and start a count down to remove the subtitle from the state
if (!json.is_interim) {
- newTranscriptMessage.final = text;
+ newTranscriptMessage.final = displayText;
} else if (json.stability > STABLE_TRANSCRIPTION_FACTOR) {
// If the message has a high stability, we can update the
// stable field of the state and remove the previously
// unstable results
- newTranscriptMessage.stable = text;
+ newTranscriptMessage.stable = displayText;
} else {
// Otherwise, this result has an unstable result, which we
// add to the state. The unstable result will be appended
// after the stable part.
- newTranscriptMessage.unstable = text;
+ newTranscriptMessage.unstable = displayText;
}
}