Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple javascript funciton integration #340

Open
kressly opened this issue Oct 23, 2024 · 5 comments
Open

simple javascript funciton integration #340

kressly opened this issue Oct 23, 2024 · 5 comments

Comments

@kressly
Copy link

kressly commented Oct 23, 2024

Hi
I tried the demo which worked but it seems almost impossible to create a simple javascript function so that i can use this awesome script outside of the demo, no matter how i tried it failed. I do not use npm and for days i tried to crate a function like speak_now(text_to_speak) and even though i copied what i saw in the demo, once outside the demo it did not work. Can u please show how to use this by doing a simple javascript integration without using npm ?

@andre-dietrich
Copy link
Contributor

Hi, we are using it and it works like charm, here is an example, which makes use of easy-speach and responsive voice:

https://github.com/LiaScript/LiaScript/blob/development/src/typescript/liascript/service/TTS.ts

@kressly
Copy link
Author

kressly commented Oct 23, 2024

Thank you so much for responding fast. But i visited the link you sent and copied the content, but please when i download the entire package,
1 - which of the js files should i include then add those functions ?
2 - if i want it to speak something like Hello world, which of these function will enable me to do it please ? i see a lot of code and i am new to this.

i really appreciate ur help

@jankapunkt
Copy link
Member

jankapunkt commented Oct 23, 2024

Hi @kressly

If you downloaded the package as zip, then take a look into the dist folder. There are various files for different environments. If you want to use the file locally / manually, I suggest to use EasySpeech.iife.js which has the best support for browsers.

A minimal example could look like this:

<html>
<head>
  <script src="dist/EasySpeech.iife.js"></script>
</head>
<body>
  <button onclick="EasySpeech.speak({ text: 'hello'})">Speak</button>
  <script>EasySpeech.init()</script>
</body>
</html>

From here you can further improve the code to your needs.
Note: you can also use the EasySpeech.js file instead and load the script with type "module", see here for more info: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type#module

Edit: if your application is entirely offline then please test before in offline mode, because some voices are only loaded by the browser afterwards and when an internet connection is available, this varies by browser and operating system though.

@kressly
Copy link
Author

kressly commented Oct 24, 2024

thank you so much for your help, i actually copied the code u sent and added the script insertion yet when i click on speak, it says noting. in the console log i see

Uncaught (in promise) SpeechSynthesisErrorEventisTrusted: truebubbles: falsecancelBubble: falsecancelable: falsecharIndex: 0charLength: 0composed: falsecurrentTarget: SpeechSynthesisUtterance {voiceURI: 'Microsoft David - English (United States)', text: 'hello', lang: 'en-US', voice: SpeechSynthesisVoice, volume: 1, …}defaultPrevented: falseelapsedTime: 8.899999618530273error: "synthesis-failed"eventPhase: 0name: ""returnValue: truesrcElement: SpeechSynthesisUtterance {voiceURI: 'Microsoft David - English (United States)', text: 'hello', lang: 'en-US', voice: SpeechSynthesisVoice, volume: 1, …}target: SpeechSynthesisUtterance {voiceURI: 'Microsoft David - English (United States)', text: 'hello', lang: 'en-US', voice: SpeechSynthesisVoice, volume: 1, …}timeStamp: 2057type: "error"utterance: SpeechSynthesisUtterance {voiceURI: 'Microsoft David - English (United States)', text: 'hello', lang: 'en-US', voice: SpeechSynthesisVoice, volume: 1, …}[[Prototype]]: SpeechSynthesisErrorEvent

and here is what the code i used looks like

<script src="js/easy-speech-master/dist/EasySpeech.iife.js"></script> Speak <script>EasySpeech.init()</script>

however when i open the demo that is in the downloaded file, it works but i need someting that wil work as a function

@jankapunkt
Copy link
Member

synthesis-failed is an error event I have never seen before. Does this only occur when you use the Microsoft David voice or with any other voice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants