//@*// https://responsivevoice.org*@ //select text voise //function getSelectionText() { // var text = ""; // if (window.getSelection) { // text = window.getSelection().toString(); // // for Internet Explorer 8 and below. For Blogger, you should use && instead of &&. // } else if (document.selection && document.selection.type != "Control") { // text = document.selection.createRange().text; // } // return text; //} //$(document).ready(function () { // when the document has completed loading // $(document).mouseup(function (e) { // attach the mouseup event for all div and pre tags // setTimeout(function () { // When clicking on a highlighted area, the value stays highlighted until after the mouseup event, and would therefore stil be captured by getSelection. This micro-timeout solves the issue. // responsiveVoice.cancel(); // stop anything currently being spoken // responsiveVoice.speak(getSelectionText()); //speak the text as returned by getSelectionText // }, 1); // }); //}); // Function to speak the fetched text function txtSpeak(text) { // Callback function for when voice starts function voiceStartCallback() { $('#volumeIcon').removeClass('bi-volume-mute').addClass('bi-volume-up'); } // Callback function for when voice ends function voiceEndCallback() { $('#volumeIcon').removeClass('bi-volume-up').addClass('bi-volume-mute'); } var parameters = { onstart: voiceStartCallback, onend: voiceEndCallback }; // Check if voice is playing if (responsiveVoice.isPlaying()) { responsiveVoice.cancel(); $('#volumeIcon').removeClass('bi-volume-up').addClass('bi-volume-mute'); } else { $('#volumeIcon').removeClass('bi-volume-mute').addClass('bi-volume-up'); // AJAX call to fetch the top 5 latest updates $.ajax({ url: '/Home/GetTop5LatestUpdates', type: 'GET', dataType: 'json', success: function (data) { if (data.length > 0) { // Construct the text to speak by concatenating titles var textToSpeak = "Here are the latest updates: "; for (var i = 0; i < data.length; i++) { textToSpeak += data[i].title + ". "; } // Call the responsiveVoice.speak function with the fetched text responsiveVoice.speak(textToSpeak, "UK English Female", parameters); } else { // Handle case when no data is returned console.log("No latest updates found."); } }, error: function (xhr, status, error) { console.error(error); } }); } }