xxxxxxxxxx
function readOutLoud(message) {
var speech = new SpeechSynthesisUtterance();
// Set the text and voice attributes.
speech.text = message;
speech.volume = 1;
speech.rate = 1;
speech.pitch = 1;
window.speechSynthesis.speak(speech);
}
xxxxxxxxxx
var msg = new SpeechSynthesisUtterance();
msg.text = "Hello World";
window.speechSynthesis.speak(msg);
xxxxxxxxxx
function say(m) {
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voice = voices[10];
msg.voiceURI = "native";
msg.volume = 1;
msg.rate = 1;
msg.pitch = 0.8;
msg.text = m;
msg.lang = 'en-US';
speechSynthesis.speak(msg);
}
xxxxxxxxxx
const speak = (msg) => {
const sp = new SpeechSynthesisUtterance(msg);
[sp.voice] = speechSynthesis.getVoices();
speechSynthesis.speak(sp);
}
speak('Hi, Welcome to Javascript Text to Speech. It is really awesome.');
xxxxxxxxxx
function speak(text, rate = 1, pitch = 1, volume = 1, voiceIndex = 0) {
const synth = window.speechSynthesis;
const voices = synth.getVoices();
const utterance = new SpeechSynthesisUtterance(text);
utterance.voice = voices[voiceIndex];
utterance.rate = rate;
utterance.pitch = pitch;
utterance.volume = volume;
synth.speak(utterance);
}
xxxxxxxxxx
<h2>Text to Speech</h2>
<textarea id="txt" cols="30" rows="5"></textarea><br>
<button id="btn">speak</button>
<script>
let txt = document.getElementById('txt');
let btn = document.getElementById('btn');
btn.addEventListener("click", function () {
let text = txt.value;
let utterance = new SpeechSynthesisUtterance(text);
// utterance.lang = "tr";
speechSynthesis.speak(utterance);
});
</script>
You can copy the following code in your HTML/JS code.
xxxxxxxxxx
$('#pause-record-btn').on('click', function(e) {
recognition.stop();
});
xxxxxxxxxx
$('#start-record-btn').on('click', function(e) {
recognition.start();
});
xxxxxxxxxx
var mobileRepeatBug = (current == 1 && transcript == event.results[0][0].transcript);
if(!mobileRepeatBug) {
noteContent += transcript;
noteTextarea.val(noteContent);
}