Stop button in Speech in Php
Discuss coding issues, and scripts related to PHP and MySQL.
-
JanMolendijk
- Posts:282
- Location:Holland Rotterdam
Stop button in Speech in Php
How are all things going CoursesWeb now with Covid-19.
It is shamble for all lovely lady`s who have the name.
I hope all Governements gonna make-up with those woman.
This script is functional but how can I add a stop button ????
Hope you can help me out....
Code: Select all
<?php
@$submit = $_POST['process'];
@$word = $_POST['texttospeech'];
$voice = new COM("SAPI.SpVoice");
if($_SERVER["REQUEST_METHOD"] == "POST" and isset($submit) and !empty($word)){
$voice->Speak($word);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<title>PHP Text to Speech</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="img/fav.png" type="image/png">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div class="topmost">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-body">
<form method = "post">
<div class = "form-group">
<br>
<textarea class="form-control input-sm" rows="6" name="texttospeech" placeholder="Type your Text Here...">
<?php echo $users['post_text'];?>
</textarea>
<input type = "submit" class = "btn btn-primary" name="stop" value="stop">
</div>
<div class = "form-group">
<input type = "submit" class = "btn btn-primary btn-block" name="process" value="Speak">
</div>
</form>
<form method="post">
<input type="hidden" name="texttospeech" value="Congratulations, you run PHP text to Speech using Microsoft Speech API. Remember, this script will run only on Microsoft Windows">
<button type="submit" name="process" class="btn btn-danger btn-block">Click Me First</button>
</form>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>
Admin
Posts:805
All the voice speak is outputted directly in browser. I didn't find a way to pause it.
Try to use a JS script, here is an example.
Code: Select all
<textarea cols=40 rows=4 id='queueText'>
Press "Start queue text" to add text area content to the text reader. Press it multiple times to add text more than once.
Press "pause" to pause reading.
Press "play" to start or resume reading queued text from the speech synthesizer's fifo queue. Play mode is in effect at startup - but you could pause the reader before queuing text.
Press "cancel" to stop reading and empty the queue. It does not change pause versus play mode. If the reader is paused when cancel is clicked, it remains so afterwards.
This voice is the default voice in this browser, and may be different in another. More code is needed for voice selection.
Oh, and don't forget to cancel speech synthesis on window unload.
</textarea><br>
<button onclick='tr.queue(queueText.value)'>Start queue text</button>
<p>
<button onclick='tr.pause()'>Pause</button>
<button onclick='tr.play()'>Play</button>
<button onclick='tr.cancel()'>Cancel</button>
</p>
<script>
const tr = {
queue: null,
pause: null,
play: null,
cancel: null,
defaultRate: 1.1,
defaultPitch: 1,
// voice selection to do;
};
function createTextReader( tr) {
let synth = window.speechSynthesis; // abbreviation
let Utter = SpeechSynthesisUtterance; // abbreviation
// queue
tr.queue = (text, rate, pitch, voiceIndex) => {
let utter = new Utter();
utter.text = text;
utter.rate = rate || tr.defaultRate || 1;
utter.pitch = pitch || tr.defaultPitch || 1;
// voice selection to do
// if( voiceParam) ....
synth.speak( utter);
};
tr.pause = () => synth.pause();
tr.play = () => synth.resume();
tr.cancel = () => synth.cancel();
}
window.addEventListener( 'DOMContentLoaded', function (e) {
createTextReader( tr)}, false);
window.addEventListener('unload', e=>tr.cancel(), false);
</script>
That is a code from stackoverflow, I have no experience with such applications.
For more answers, search on the net for: SpeechSynthesisUtterance js pause button, or ask on stackoverflow.
Demo:
JanMolendijk
Posts:282
I could kiss you for this support all things working & I even have it now in Dutch
Thanks Coursesweb
Similar Topics
- Speech to text without https
General Forum
First post
Pleasant Coursesweb,
Is their anything posible without https for speech to text fill-in ?
Or must I turn my SSL document on the XAMPP-server ?
Last post
Hello,
I don't know about speech to text fill-in.
Anyway, I want to inform you that this forum will be closed for register or posting.
Any...
- local storage for speech is limited to round 30 words
JavaScript - jQuery - Ajax
First post
Pleasant Coursesweb,
The local storage for speech is limited to round 30 words.
But may also be limited to a number of characters ?
When I...
Last post
Marplo thanks for the suport.... Strange in Edge browser
the speech is unlimited but Chrome has big limits in speech.