You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import i18next from 'i18next';
  2. import { IReduxState } from '../app/types';
  3. import { IConfig } from '../base/config/configType';
  4. import { isJwtFeatureEnabled } from '../base/jwt/functions';
  5. import { isLocalParticipantModerator } from '../base/participants/functions';
  6. import JITSI_TO_BCP47_MAP from './jitsi-bcp47-map.json';
  7. import logger from './logger';
  8. import TRANSCRIBER_LANGS from './transcriber-langs.json';
  9. const DEFAULT_TRANSCRIBER_LANG = 'en-US';
  10. /**
  11. * Determine which language to use for transcribing.
  12. *
  13. * @param {*} config - Application config.
  14. * @returns {string}
  15. */
  16. export function determineTranscriptionLanguage(config: IConfig) {
  17. const { transcription } = config;
  18. // if transcriptions are not enabled nothing to determine
  19. if (!transcription?.enabled) {
  20. return undefined;
  21. }
  22. // Depending on the config either use the language that the app automatically detected or the hardcoded
  23. // config BCP47 value.
  24. // Jitsi language detections uses custom language tags, but the transcriber expects BCP-47 compliant tags,
  25. // we use a mapping file to convert them.
  26. const bcp47Locale = transcription?.useAppLanguage ?? true
  27. ? JITSI_TO_BCP47_MAP[i18next.language as keyof typeof JITSI_TO_BCP47_MAP]
  28. : transcription?.preferredLanguage;
  29. // Check if the obtained language is supported by the transcriber
  30. let safeBCP47Locale = TRANSCRIBER_LANGS[bcp47Locale as keyof typeof TRANSCRIBER_LANGS] && bcp47Locale;
  31. if (!safeBCP47Locale) {
  32. safeBCP47Locale = DEFAULT_TRANSCRIBER_LANG;
  33. logger.warn(`Transcriber language ${bcp47Locale} is not supported, using default ${DEFAULT_TRANSCRIBER_LANG}`);
  34. }
  35. logger.info(`Transcriber language set to ${safeBCP47Locale}`);
  36. return safeBCP47Locale;
  37. }
  38. /**
  39. * Returns whether there is transcribing.
  40. *
  41. * @param {IReduxState} state - The redux state to search in.
  42. * @returns {boolean}
  43. */
  44. export function isTranscribing(state: IReduxState) {
  45. return state['features/transcribing'].isTranscribing;
  46. }
  47. /**
  48. * Returns true if there is a recorder transcription session running.
  49. * NOTE: If only the subtitles are running this function will return false.
  50. *
  51. * @param {Object} state - The redux state to search in.
  52. * @returns {boolean}
  53. */
  54. export function isRecorderTranscriptionsRunning(state: IReduxState) {
  55. const { metadata } = state['features/base/conference'];
  56. return isTranscribing(state) && Boolean(metadata?.recording?.isTranscribingEnabled);
  57. }
  58. /**
  59. * Checks whether the participant can start the transcription.
  60. *
  61. * @param {IReduxState} state - The redux state.
  62. * @returns {boolean} - True if the participant can start the transcription.
  63. */
  64. export function canAddTranscriber(state: IReduxState) {
  65. const { transcription } = state['features/base/config'];
  66. const isModerator = isLocalParticipantModerator(state);
  67. const isTranscribingAllowed = isJwtFeatureEnabled(state, 'transcription', isModerator, false);
  68. return Boolean(transcription?.enabled) && isTranscribingAllowed;
  69. }