I call a function:
$(document).on('click', '#home', function() {
runfunction2('', ''); // for stopping speech
runfunction( 956, 0 );
})
from this function I call another function with speech. (https://github.com/vilic/cordova-plugin-tts)
function runfunction( post_id, step ){
runfunction2('example text', 'starttimer', post_id, step );
}
function runfunction3( text, end, post_id, step ){
TTS.speak({
text: text,
locale: 'de-DE',
rate: 1.5
}, function () {
if ( end == "startrec" ) {
console.log("startrec gestartet");
mediaPlay3.play();
setTimeout(function() {
mediaPlay3.stop();
startRecognition( post_id, step );
}, 1000);
setTimeout( function(){
// Do something after 3 second
stopRecognition();
} , 4000 );
} else if ( end == "newtry" ){
console.log("newtry gestartet");
mediaPlay3.play();
setTimeout(function() {
mediaPlay3.stop();
startRecognition( post_id, step );
}, 1000);
setTimeout( function(){
// Do something after 3 second
stopRecognition();
} , 4000);
} else if ( end == "starttimer" ){
timer(post_id, step );
} else {
//
}
}
If I click during the process the home-button again I want to start it from the beginning. The problem is that the first function is not yet finished and is running in the background (still calling the second function). But I want to cancel it all and let everything run from the beginning. How is that possible?