/    Sign up×
Community /Pin to ProfileBookmark

I am trying to create an object with TTS, please. It works as a function, but I cannot get it to work as an object.

`<BODY>

Enter Response: <input type=”text” id=”input”><br>
<button onclick=”MyFunction(input.value)”>Click Button</button>

<script>
function MyFunction(input) {
document.write(“<h1>You gave “+input+”</h1>”);

var x = input;

if (x == “w”) { speak(x); } // augument x is pass, originally from text box
}

const say = {
function speak(x) {

let msg = (“Hello” + x);
let speech = new SpeechSynthesisUtterance();
speech.lang = “en-US”; // Text Language
speech.text = msg; // The text you want to convert to speech
speech.volume = 1; // Volume
speech.rate = 1; // Speed
speech.pitch = 1; // Pitch
window.speechSynthesis.speak(speech);
}
}
};
// Display data from the object:
document.getElementById(“demo”).innerHTML = say.speak(x);

</script>
</BODY>`

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @zamber spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...