I'm trying to add a sound to my chrome extension. It is my understanding it must be done in a service worker and that is where I have it:
chrome.tts.speak("Hit has been queued",{"lang": "en-US","rate":2.0});
However, when this executes I get this error:
caught error - Cannot read properties of undefined (reading 'speak')
It almost looks like a syntax error in the argument list but I don't see it. Can someone spot what I'm doing wrong? TIA
Updated HTML page without running as an extension
<!doctype html>
<html lang="en">
<head>
<title>
Alert
</title>
</head>
<body>
<script>
chrome.tts.speak("Hit added to queue",{"lang":"US-en","rate":2.0});
</script>
</body>
</html>
Updated per suggestion
alert.html
<!doctype html>
<html lang="en">
<head>
<title>
Alert
</title>
</head>
<body>
<script type="application/x-javascript" src="alert.js">
</script>
</body>
</html>
alert.js
chrome.tts.speak("Hit added to queue",{"lang":"US-en","rate":2.0});