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';
|
|
|
|
|
2024-03-22 03:41:32 +08:00
|
|
|
const CONFIG = window.meetingClientSettings.public.app.audioCaptions;
|
2023-09-21 21:48:00 +08:00
|
|
|
const PROVIDER = CONFIG.provider;
|
|
|
|
const LANGUAGES = CONFIG.language.available;
|
|
|
|
|
|
|
|
export const isAudioTranscriptionEnabled = () => isLiveTranscriptionEnabled();
|
|
|
|
|
|
|
|
export const isWebSpeechApi = () => PROVIDER === 'webspeech';
|
|
|
|
|
|
|
|
export const getSpeechVoices = () => {
|
|
|
|
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-01-15 20:28:45 +08:00
|
|
|
export const setSpeechLocale = (value: string, setUserSpeechLocale: (a: string, b: string) => void) => {
|
2024-04-20 03:35:39 +08:00
|
|
|
setUserSpeechLocale(value, CONFIG.provider);
|
2023-09-21 21:48:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const useFixedLocale = () => isAudioTranscriptionEnabled() && CONFIG.language.forceLocale;
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getSpeechVoices,
|
|
|
|
isAudioTranscriptionEnabled,
|
|
|
|
setSpeechLocale,
|
|
|
|
setAudioCaptions,
|
|
|
|
isWebSpeechApi,
|
|
|
|
useFixedLocale,
|
|
|
|
};
|