fix(captions): check for voices

Avoid enable audio transcription if the browser's vendor does not provide
voices data.

This should prevent false positives for browsers such as Chromium and
Brave.
This commit is contained in:
Pedro Beschorner Marin 2022-04-11 10:45:09 -03:00 committed by Arthurk12
parent e131925370
commit 5671bd7d3c

View File

@ -8,9 +8,19 @@ const DEFAULT_LANGUAGE = 'pt-BR';
const ENABLED = Meteor.settings.public.app.enableAudioCaptions;
const THROTTLE_TIMEOUT = 1000;
const hasVendorSupport = () => {
if (window.speechSynthesis && typeof window.speechSynthesis.getVoices === 'function') {
const voices = window.speechSynthesis.getVoices();
if (Array.isArray(voices)) return voices.length > 0;
}
return false;
};
const SpeechRecognitionAPI = window.SpeechRecognition || window.webkitSpeechRecognition;
const hasSpeechRecognitionSupport = () => typeof SpeechRecognitionAPI !== 'undefined';
const hasSpeechRecognitionSupport = () => typeof SpeechRecognitionAPI !== 'undefined' && hasVendorSupport();
const initSpeechRecognition = (locale = DEFAULT_LANGUAGE) => {
if (hasSpeechRecognitionSupport()) {