Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/app/pages/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { singleTextBlock } from '#app/models/blocks';
import ArticleMetadata from '#containers/ArticleMetadata';
import { RequestContext } from '#contexts/RequestContext';
import onClient from '#lib/utilities/onClient';
import headings from '#containers/Headings';
import visuallyHiddenHeadline from '#containers/VisuallyHiddenHeadline';
import gist from '#containers/Gist';
Expand Down Expand Up @@ -119,6 +120,8 @@
isTrustProjectParticipant,
showRelatedTopics,
brandName,
isoLang,
locale,
} = useContext(ServiceContext);

const { enabled: preloadLeadImageToggle } = useToggle('preloadLeadImage');
Expand Down Expand Up @@ -228,6 +231,54 @@
const promoImage = promoImageRawBlock?.model?.locator;

const showTopics = Boolean(showRelatedTopics && topics.length > 0);

const speak = () => {
if (onClient()) {
const synth = window.speechSynthesis;
const main = window.document.querySelector('main')
const utterThis = new SpeechSynthesisUtterance(main.innerText);

Check failure on line 239 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (22.x)

'main' is possibly 'null'.

Check failure on line 239 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

'main' is possibly 'null'.
console.log('isoLang', isoLang);
const voiceIndex = () => {
switch (isoLang) {
case 'es':
return 9;
break;
case 'fr':
return 15;
break;
default:
return 0;
break;
}
};
const voiceLocale = () => {
if (locale.length === 5) return locale;
return `${isoLang}-${isoLang.toUpperCase()}`;

Check failure on line 256 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (22.x)

'isoLang' is possibly 'null' or 'undefined'.

Check failure on line 256 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

'isoLang' is possibly 'null' or 'undefined'.
}

let allVoices = synth.getVoices();// this needs to be called after SpeechSynthesisUtterance
const voicesForLang = allVoices.filter(voice => voice.localService === true && voice.lang.indexOf(`${isoLang}-`) === 0);
console.log('voicesForLang', voicesForLang);

if (voicesForLang.length) utterThis.voice = voicesForLang[voiceIndex(isoLang)];

Check failure on line 263 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (22.x)

Expected 0 arguments, but got 1.

Check failure on line 263 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

Expected 0 arguments, but got 1.
utterThis.lang = voiceLocale();
console.log('voicesForLang[voiceIndex]', voicesForLang[voiceIndex(isoLang)]);

Check failure on line 265 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (22.x)

Expected 0 arguments, but got 1.

Check failure on line 265 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

Expected 0 arguments, but got 1.
utterThis.onend = function (event) {

Check failure on line 266 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (22.x)

'event' is declared but its value is never read.

Check failure on line 266 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

'event' is declared but its value is never read.
console.log("SpeechSynthesisUtterance.onend");
};

utterThis.onerror = function (event) {

Check failure on line 270 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (22.x)

'event' is declared but its value is never read.

Check failure on line 270 in src/app/pages/ArticlePage/ArticlePage.tsx

View workflow job for this annotation

GitHub Actions / build (22.x)

'event' is declared but its value is never read.
console.error("SpeechSynthesisUtterance.onerror");
};

synth.speak(utterThis);
}
}
// useEffect(() => {
// if (onClient()) {
//
// }
// });

return (
<div css={styles.pageWrapper}>
Expand Down Expand Up @@ -278,6 +329,7 @@
<div css={styles.grid}>
<div css={!isPGL ? styles.primaryColumn : styles.pglColumn}>
<main css={styles.mainContent} role="main">
<button onClick={speak}>🔊</button>
<Blocks
blocks={articleBlocks}
componentsToRender={componentsToRender}
Expand Down
Loading