diff --git a/package.json b/package.json index d91915e..d2db8e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "1.9.3", + "version": "1.9.4", "author": "lingdocs.com", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "homepage": "https://verbs.lingdocs.com", diff --git a/src/components/vp-explorer/VPExplorer.tsx b/src/components/vp-explorer/VPExplorer.tsx index f563d26..9c65f71 100644 --- a/src/components/vp-explorer/VPExplorer.tsx +++ b/src/components/vp-explorer/VPExplorer.tsx @@ -18,6 +18,7 @@ import InlinePs from "../InlinePs"; import { psStringEquals } from "../../lib/p-text-helpers"; import classNames from "classnames"; import { randFromArray } from "../../lib/misc-helpers"; +import playAudio from "../../lib/play-audio"; // import { useReward } from 'react-rewards'; const kingEmoji = "👑"; @@ -144,6 +145,8 @@ export function VPExplorer(props: { function checkQuizAnswer(a: T.PsString) { if (!quizState) return; if (isInAnswer(a, quizState.answer)) { + const toPlay = randFromArray([true, false, false]); + if (toPlay) playAudio(`correct-${randFromArray([1,2,3])}`); setShowCheck(true); setTimeout(() => { handleResetQuiz(); @@ -156,6 +159,7 @@ export function VPExplorer(props: { setCurrentCorrectEmoji(randFromArray(correctEmoji)); }, checkDuration * 2); } else { + playAudio(`wrong-${randFromArray([1,2])}`); navigator.vibrate(250); setQuizState({ ...quizState, diff --git a/src/lib/play-audio.ts b/src/lib/play-audio.ts new file mode 100644 index 0000000..68365a6 --- /dev/null +++ b/src/lib/play-audio.ts @@ -0,0 +1,11 @@ +export default function playAudio(a: string) { + if (!a) return; + let audio = new Audio(`https://verbs.lingdocs.com/sounds/${a}.mp3`); + audio.addEventListener("ended", () => { + audio.remove(); + audio.srcObject = null; + }); + audio.play().catch((e) => { + console.error(e); + }); +} \ No newline at end of file