Skip to content

Commit

Permalink
Merge pull request #1412 from tomivm/fix/synth-cancel-IOS-only
Browse files Browse the repository at this point in the history
Fix/synth cancel before play only on Safari or Apple touch devices
  • Loading branch information
martinbedouret authored Mar 13, 2023
2 parents b30c305 + f1ded7f commit 2251bf7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ 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
);
const userAgent = navigator.userAgent;

export const IS_BROWSING_FROM_APPLE = /iPad|iPhone|iPod|Mac/.test(userAgent);

export const IS_BROWSING_FROM_APPLE_TOUCH =
IS_BROWSING_FROM_APPLE && 'ontouchend' in document;

export const IS_BROWSING_FROM_SAFARI =
userAgent.indexOf('Safari') > -1 &&
userAgent.indexOf('Chrome') === -1 &&
!navigator.userAgent.match(/crios/i) &&
!navigator.userAgent.match(/fxios/i) &&
!navigator.userAgent.match(/Opera|OPT\//);
7 changes: 5 additions & 2 deletions src/providers/SpeechProvider/tts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import API from '../../api';
import {
AZURE_SPEECH_SERVICE_REGION,
AZURE_SPEECH_SUBSCR_KEY,
IS_BROWSING_FROM_APPLE
IS_BROWSING_FROM_APPLE,
IS_BROWSING_FROM_APPLE_TOUCH,
IS_BROWSING_FROM_SAFARI
} from '../../constants';
import { getStore } from '../../store';

Expand Down Expand Up @@ -267,7 +269,8 @@ const tts = {
msg.rate = rate;
msg.volume = volume;
msg.onend = onend;
synth.cancel();
if (IS_BROWSING_FROM_SAFARI || IS_BROWSING_FROM_APPLE_TOUCH)
synth.cancel();
synth.speak(msg);
}
}
Expand Down

0 comments on commit 2251bf7

Please sign in to comment.