diff --git a/src/constants.js b/src/constants.js index 9d9f91363..b01aa2e04 100644 --- a/src/constants.js +++ b/src/constants.js @@ -31,3 +31,7 @@ export const ADTEST_AVAILABLE = export const ADSENSE_CLIENT = 'ca-pub-7162313874228987'; export const ADD_SLOT_SETTINGS_TOP = '5250438005'; + +export const IS_BROWSING_FROM_APPLE = /iPad|iPhone|iPod|Mac/.test( + navigator.userAgent +); diff --git a/src/providers/SpeechProvider/tts.js b/src/providers/SpeechProvider/tts.js index 3660574b5..f847c2f22 100644 --- a/src/providers/SpeechProvider/tts.js +++ b/src/providers/SpeechProvider/tts.js @@ -3,7 +3,8 @@ import { isAndroid, isCordova } from '../../cordova-util'; import API from '../../api'; import { AZURE_SPEECH_SERVICE_REGION, - AZURE_SPEECH_SUBSCR_KEY + AZURE_SPEECH_SUBSCR_KEY, + IS_BROWSING_FROM_APPLE } from '../../constants'; import { getStore } from '../../store'; @@ -14,6 +15,8 @@ let synth = window.speechSynthesis; var azureSynthesizer; const audioElement = new Audio(); + +let appleFirstCloudPlay = IS_BROWSING_FROM_APPLE; var speakQueue = []; var platformVoices = []; @@ -49,7 +52,9 @@ const playQueue = () => { if (speakQueue.length) { const blob = new Blob([speakQueue[0].audioData], { type: 'audio/wav' }); audioElement.src = window.URL.createObjectURL(blob); - audioElement.play(); + audioElement.play().catch(err => { + console.error(err); + }); audioElement.onended = () => { window.URL.revokeObjectURL(audioElement.src); if (speakQueue.length) { @@ -191,6 +196,17 @@ const tts = { ) { const voice = this.getVoiceByVoiceURI(voiceURI); if (voice && voice.voiceSource === 'cloud') { + if (appleFirstCloudPlay) { + audioElement + .play() + .then(() => {}) + .catch(() => {}) + .finally(() => { + console.log('Apple user Agent is ready to reproduce cloud voices'); + }); + audioElement.pause(); + appleFirstCloudPlay = false; + } const speakAlertTimeoutId = setCloudSpeakAlertTimeout(); // set voice to speak azureSynthesizer.properties.setProperty(