Text To Speech

⌘K
  1. Home
  2. Docs
  3. Text To Speech
  4. Filters & Actions
  5. Apply Frontend Filters and Actions ( Pro Version )

Apply Frontend Filters and Actions ( Pro Version )

wp.hooks.addFilter('ttsProPlayerOptions', 'textToSpeech', function(obj) {
	return {
		 ...obj,
		autoplay: true
	};
});

wp.hooks.addFilter('ttsProLink', 'textToSpeech', function(val) {
	return '';
});

wp.hooks.addFilter('ttsSetSelectedLanguageFromDom', 'textToSpeech', function(val) {
	return true;
});

wp.hooks.addFilter('ttsProApplyNumberFormat', 'texttospeech', function(value) {
	return true;
})

wp.hooks.addFilter('ttsProGetContentFromDOM', 'texttospeech', function(val) {
	return false;
});

wp.hooks.addFilter('ttsProPlayerDesign', 'textToSpeech', function(obj) {
	return {
		 speed: {selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 1.75]}
	};
});


 Apply this splitting long sentences.
wp.hooks.addFilter('ttsProSplitLongSentences', 'textToSpeech', function(val){
	return true;
})



If you need do something before downloading the MP3 file like add a form to submit or need to do something like this you can apply this filter.

wp.hooks.addFilter('ttsProPlayerDesign', 'texttospeech', function(defaultDesing, otherData) {
	let finalDesign = {...defaultDesing}
	
	finalDesign.listeners =  {
                        download: function (e) {
                            e.preventDefault();
                            console.log(e)
                            if (confirm('Are you sure? fron filter')) {
				const a = document.createElement('a');
				a.href = otherData.url;
				let pathname = new URL(otherData.url).pathname;
				pathname = pathname.substring(pathname.lastIndexOf('/') + 1)
				console.log(pathname)
				a.download = pathname || 'audio.mp3';
				document.body.appendChild(a);
				a.click();
				document.body.removeChild(a);
								
				if (otherData.playerClass.analytics) {
					otherData.playerClass.analytics.trackDownload();
				}
                            }
                        },
                    }
	
	return finalDesign;
	
})

to customize player, suppose you don't want the download option in the player

wp.hooks.addFilter('ttsProPlayerDesign', 'textToSpeech', function(obj) {
	return {
		... obj  ,
		controls: [
			'play',
			'progress',
			'volume',
                        'download', // remove this to remove the download option from player.
			'settings'
		]
	}
});

How can we help?