2023-09-21 21:48:00 +08:00
|
|
|
import { unique } from 'radash';
|
|
|
|
import { setAudioCaptionEnable } from '/imports/ui/core/local-states/useAudioCaptionEnable';
|
|
|
|
import { isLiveTranscriptionEnabled } from '/imports/ui/services/features';
|
|
|
|
|
|
|
|
export const isAudioTranscriptionEnabled = () => isLiveTranscriptionEnabled();
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
export const isWebSpeechApi = () => {
|
|
|
|
const PROVIDER = window.meetingClientSettings.public.app.audioCaptions.provider;
|
|
|
|
return PROVIDER === 'webspeech';
|
|
|
|
};
|
2023-09-21 21:48:00 +08:00
|
|
|
|
|
|
|
export const getSpeechVoices = () => {
|
2024-05-29 21:26:11 +08:00
|
|
|
const LANGUAGES = window.meetingClientSettings.public.app.audioCaptions.language.available;
|
|
|
|
|
2023-09-21 21:48:00 +08:00
|
|
|
if (!isWebSpeechApi()) return LANGUAGES;
|
|
|
|
|
|
|
|
return unique(
|
|
|
|
window
|
|
|
|
.speechSynthesis
|
|
|
|
.getVoices()
|
|
|
|
.map((v) => v.lang)
|
|
|
|
.filter((v) => LANGUAGES.includes(v)),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setAudioCaptions = (value: boolean) => {
|
|
|
|
setAudioCaptionEnable(value);
|
|
|
|
// @ts-ignore - Exist while we have meteor in the project
|
|
|
|
Session.set('audioCaptions', value);
|
|
|
|
};
|
|
|
|
|
2024-06-04 04:14:32 +08:00
|
|
|
// SpeechLocale or CaptionLocale
|
|
|
|
export const setUserLocaleProperty = (value: string, setUserLocaleCallback: (a: string, b: string) => void) => {
|
2024-05-29 21:26:11 +08:00
|
|
|
const PROVIDER = window.meetingClientSettings.public.app.audioCaptions.provider;
|
2024-06-04 04:14:32 +08:00
|
|
|
setUserLocaleCallback(value, PROVIDER);
|
2023-09-21 21:48:00 +08:00
|
|
|
};
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
export const useFixedLocale = () => {
|
|
|
|
const FORCE_LOCALE = window.meetingClientSettings.public.app.audioCaptions.language.forceLocale;
|
|
|
|
return isAudioTranscriptionEnabled() && FORCE_LOCALE;
|
|
|
|
};
|
2023-09-21 21:48:00 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
getSpeechVoices,
|
|
|
|
isAudioTranscriptionEnabled,
|
2024-06-04 04:14:32 +08:00
|
|
|
setUserLocaleProperty,
|
2023-09-21 21:48:00 +08:00
|
|
|
setAudioCaptions,
|
|
|
|
isWebSpeechApi,
|
|
|
|
useFixedLocale,
|
|
|
|
};
|