{"id":29015,"date":"2017-01-23T23:01:45","date_gmt":"2017-01-23T15:01:45","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=29015"},"modified":"2017-10-27T00:07:16","modified_gmt":"2017-10-26T16:07:16","slug":"text-to-speech","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/","title":{"rendered":"How to Add Text-to-Speech Feature on Any Web Page"},"content":{"rendered":"<p>The <strong>text-to-speech<\/strong> feature refers to the <strong>spoken narration of a text<\/strong> displayed on a device. At present, devices such as laptops, tablets, and mobile phones <strong>already have this feature<\/strong>. Any application running on these devices, such as a web browser, can <strong>make use of it<\/strong>, and <strong>extend its functionality<\/strong>. The narration feature can be a suitable aid for an application that <strong>displays plentiful text<\/strong>, as it <strong>offers the option of listening<\/strong> to website visitors.<\/p>\n<h2>The Web Speech API<\/h2>\n<p>The <strong><a target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_Speech_API\">Web Speech JavaScript API<\/a><\/strong> is the gateway to <strong>access the Text-to-Speech feature by a web browser<\/strong>. So, if you want to introduce text-to-speech functionality on a text-heavy web page, and allow your readers to listen to the content, you can make use of this handy API, or, to be more specific, its <strong><a target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\"><code>SpeechSynthesis<\/code><\/a> interface<\/strong>.<\/p>\n<h2>Initial code & support check<\/h2>\n<p>To get started, let\u2019s create a web page with <strong>me sample text to be narrated<\/strong>, and <strong>three buttons<\/strong>.<\/p>\n<pre>\r\n&lt;div&gt;\r\n    &lt;button id=play&gt;&lt;\/button&gt;\r\n    &lt;button id=pause&gt;&lt;\/button&gt;\r\n    &lt;button id=stop&gt;&lt;\/button&gt;\r\n&lt;\/div&gt;\r\n&lt;article&gt;\r\n    &lt;h1&gt;The Hare With Many Friends&lt;\/h1&gt;\r\n    &lt;img src=\"hare-and-friends.jpg\"&gt;\r\n    &lt;p&gt;A hare was very popular with...&lt;\/p&gt;\r\n    &lt;p&gt;But he declined, stating that...&lt;\/p&gt;\r\n    &lt;!-- More text... --&gt;\r\n    &lt;blockquote&gt;Moral of the story...&lt;\/blockquote&gt;\r\n&lt;\/article&gt;\r\n<\/pre>\n<p>The buttons will be the <strong>controls for the narration<\/strong>. Now we need to make sure if the <abbr title=\"User Agent\">UA<\/abbr> supports the <code>SpeechSynthesis<\/code> interface. To do so, we quickly check with JavaScript if the <strong><code>window<\/code> object has the <code>'speechSynthesis'<\/code> property<\/strong>, or not.<\/p>\n<pre>\r\nonload = function() {\r\n  if ('speechSynthesis' in window) {\r\n      \/* speech synthesis supported *\/\r\n  }\r\n  else {\r\n      \/* speech synthesis not supported *\/\r\n  }\r\n}\r\n<\/pre>\n<p>If <code>speechSynthesis<\/code> is available, first we <strong>create a reference for <code>speechSynthesis<\/code><\/strong> that we assign to the <code>synth<\/code> variable. We also <strong>initiate a flag<\/strong> with the <code>false<\/code> value (we\u2019ll see its purpose later in the post), and we <strong>create references & click event handlers<\/strong> for the three buttons (Play, Pause, Stop) as well.<\/p>\n<p class=\"note\"> <strong>Recommended Reading:<\/strong>\n  <a href=\"https:\/\/www.hongkiat.com\/blog\/dom-manipulation-javascript-methods\/\">15 JavaScript Methods For DOM Manipulation for Web Developers<\/a><\/p>\n<p>When the user clicks one of the buttons, its respective function (<code>onClickPlay()<\/code>, <code>onClickPause()<\/code>, <code>onClickStop()<\/code>) will be called.<\/p>\n<pre>\r\nif ('speechSynthesis' in window){\r\n    var synth = speechSynthesis;\r\n    var flag = false;\r\n\r\n    \/* references to the buttons *\/\r\n    var playEle = document.querySelector('#play');\r\n    var pauseEle = document.querySelector('#pause');\r\n    var stopEle = document.querySelector('#stop');\r\n\r\n    \/* click event handlers for the buttons *\/\r\n    playEle.addEventListener('click', onClickPlay);\r\n    pauseEle.addEventListener('click', onClickPause);\r\n    stopEle.addEventListener('click', onClickStop);\r\n\r\n    function onClickPlay() {\r\n    }\r\n    function onClickPause() {\r\n    }\r\n    function onClickStop() {\r\n    }\r\n}\r\n<\/pre>\n<h2>Create the custom functions<\/h2>\n<p>Now let\u2019s <strong>build the click functions<\/strong> of the three individual buttons that will be called by the event handlers.<\/p>\n<h3>1. Play\/Resume<\/h3>\n<p>When the Play button is clicked, first we <strong>check the <code>flag<\/code><\/strong>. If it\u2019s <code>false<\/code>, we set it to <code>true<\/code>, so if any time the button is clicked later, the code inside the <strong>first <code>if<\/code> condition won\u2019t execute<\/strong> (not until the flag is <code>false<\/code> again).<\/p>\n<p>Then we <strong>create a new instance of the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesisUtterance\" target=\"_blank\"><code>SpeechSynthesisUtterance<\/code><\/a><\/strong> interface that holds information about the speech, like, the text to be read, speech volume, voice spoken in, speed, pitch and language of the speech. We add the article text <strong>as parameter of the constructor<\/strong>, and assign it to the <code>utterance<\/code> variable.<\/p>\n<pre>\r\nfunction onClickPlay() {\r\n    if(!flag){\r\n        flag = true;\r\n        utterance = new SpeechSynthesisUtterance(\r\n              document.querySelector('article').textContent);\r\n        utterance.voice = synth.getVoices()[0];\r\n        utterance.onend = function(){\r\n            flag = false;\r\n        };\r\n        synth.speak(utterance);\r\n    }\r\n    if(synth.paused) { \/* unpause\/resume narration *\/\r\n        synth.resume();\r\n    }\r\n}\r\n<\/pre>\n<p>We use the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/getVoices\" target=\"_blank\">SpeechSynthesis.getVoices()<\/a><\/code> method to <strong>designate a voice for the speech<\/strong> from the voices available in the user\u2019s device. As this method returns an array of all the available voice options in a device, we <strong>assign the first available device voice<\/strong> by using the <code>utterance.voice = synth.getVoices()[0];<\/code> statement.<\/p>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesisUtterance\/onend\" target=\"_blank\"><code>onend<\/code><\/a> property represents an event handler that is <strong>executed when the speech is finished<\/strong>. Inside of it, we change the value of the <code>flag<\/code> variable <strong>back to false<\/strong> so that the code that starts the speech <strong>can be executed<\/strong> when the button is <strong>clicked again<\/strong>.<\/p>\n<p>Then we call the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/speak\" target=\"_blank\"><code>SpeechSynthesis.speak()<\/code><\/a> method in order to <strong>start the narration<\/strong>. We also need to check <strong>if the narration is paused<\/strong>, for which we use the read-only <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/paused\" target=\"_blank\">SpeechSynthesis.paused<\/a><\/code> property. If the narration is paused, we need to <strong>resume the narration<\/strong> on the button click, which we can acheive by using the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/resume\" target=\"_blank\">SpeechSynthesis.resume()<\/a><\/code> method.<\/p>\n<h3>2. Pause<\/h3>\n<p>Now let\u2019s create the <code>onClickPause()<\/code> function in which we first check <strong>if the narration is ongoing and not paused<\/strong>. We can test these conditions by making use of the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/speaking\" target=\"_blank\">SpeechSynthesis.speaking<\/a><\/code> and the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/paused\" target=\"_blank\">SpeechSynthesis.paused<\/a><\/code> properties.  If both conditions are true, our <code>onClickPause()<\/code> function <strong>pauses the speech<\/strong> by calling the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/pause\" target=\"_blank\">SpeechSynthesis.pause()<\/a><\/code> method.<\/p>\n<pre>\r\nfunction onClickPause() {\r\n    if(synth.speaking && !synth.paused){ \/* pause narration *\/\r\n        synth.pause();\r\n    }\r\n}\r\n<\/pre>\n<h3>3. Stop<\/h3>\n<p>The <code>onClickStop()<\/code> function is <strong>built similarly to <code>onClickPause()<\/code><\/strong>. If the speech is ongoing, we <strong>stop it<\/strong> by calling the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/SpeechSynthesis\/cancel\" target=\"_blank\">SpeechSynthesis.cancel()<\/a><\/code> method that <strong>removes all utterances<\/strong>.<\/p>\n<pre>\r\nfunction onClickStop() {\r\n    if(synth.speaking){ \/* stop narration *\/\r\n        \/* for safari *\/\r\n        flag = false;\r\n        synth.cancel();\r\n    }\r\n}\r\n<\/pre>\n<p>Note that on the cancellation of speech, the <strong><code>onend<\/code> event is automatically fired<\/strong>, and we had already added the flag reset code inside of it. However, <strong>there\u2019s a bug in the Safari browser<\/strong> that prevents this event from firing, that\u2019s why we resetted the flag in the <code>onClickStop()<\/code> function. You don\u2019t have to do it if you don\u2019t want to support Safari.<\/p>\n<h2>Browser support<\/h2>\n<p>All latest versions of modern browsers <strong>have full or partial support<\/strong> for the speech synthesis API. Webkit browsers don\u2019t play speech from multiple tabs, pausing is buggy (works but buggy), and speech isn\u2019t reset when the user reloads the page in Webkit browsers.<\/p>\n<h2>Working demo<\/h2>\n<p>Have a look at the live <a target=\"_blank\" href=\"https:\/\/hongkiat.github.io\/js-speech-synthesis\/\">demo<\/a> below, or check out the full code on <a target=\"_blank\" href=\"https:\/\/github.com\/hongkiat\/js-speech-synthesis\/\">Github<\/a>.<\/p>\n<p data-height=\"705\" data-theme-id=\"0\" data-slug-hash=\"RoJwVX\" data-default-tab=\"result\" data-user=\"hkdc\" data-embed-version=\"2\" data-pen-title=\"\u00f0\u0178-\u00a3 Text to Speech - JavaScript\" class=\"codepen\">See the Pen <a href=\"https:\/\/codepen.io\/\/hkdc\/pen\/RoJwVX\/\" rel=\"nofollow\">\u00f0\u0178-\u00a3 Text to Speech \u2013 JavaScript<\/a> by HONGKIAT (<a href=\"https:\/\/codepen.io\/\/hkdc\" rel=\"nofollow\">@hkdc<\/a>) on <a href=\"https:\/\/codepen.io\/\" rel=\"nofollow\">CodePen<\/a>.<\/p>\n<p><script async src=\"https:\/\/production-assets.codepen.io\/assets\/embed\/ei.js\"><\/script><\/p>","protected":false},"excerpt":{"rendered":"<p>The text-to-speech feature refers to the spoken narration of a text displayed on a device. At present, devices such as laptops, tablets, and mobile phones already have this feature. Any application running on these devices, such as a web browser, can make use of it, and extend its functionality. The narration feature can be a&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[511],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Add Text-to-Speech Feature on Any Web Page - Hongkiat<\/title>\n<meta name=\"description\" content=\"The text-to-speech feature refers to the spoken narration of a text displayed on a device. At present, devices such as laptops, tablets, and mobile phones\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Add Text-to-Speech Feature on Any Web Page\" \/>\n<meta property=\"og:description\" content=\"The text-to-speech feature refers to the spoken narration of a text displayed on a device. At present, devices such as laptops, tablets, and mobile phones\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-23T15:01:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-26T16:07:16+00:00\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"How to Add Text-to-Speech Feature on Any Web Page\",\"datePublished\":\"2017-01-23T15:01:45+00:00\",\"dateModified\":\"2017-10-26T16:07:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/\"},\"wordCount\":732,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"Web Developers\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/\",\"name\":\"How to Add Text-to-Speech Feature on Any Web Page - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2017-01-23T15:01:45+00:00\",\"dateModified\":\"2017-10-26T16:07:16+00:00\",\"description\":\"The text-to-speech feature refers to the spoken narration of a text displayed on a device. At present, devices such as laptops, tablets, and mobile phones\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/text-to-speech\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Add Text-to-Speech Feature on Any Web Page\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Add Text-to-Speech Feature on Any Web Page - Hongkiat","description":"The text-to-speech feature refers to the spoken narration of a text displayed on a device. At present, devices such as laptops, tablets, and mobile phones","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/","og_locale":"en_US","og_type":"article","og_title":"How to Add Text-to-Speech Feature on Any Web Page","og_description":"The text-to-speech feature refers to the spoken narration of a text displayed on a device. At present, devices such as laptops, tablets, and mobile phones","og_url":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2017-01-23T15:01:45+00:00","article_modified_time":"2017-10-26T16:07:16+00:00","author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"How to Add Text-to-Speech Feature on Any Web Page","datePublished":"2017-01-23T15:01:45+00:00","dateModified":"2017-10-26T16:07:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/"},"wordCount":732,"commentCount":0,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["Web Developers"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/text-to-speech\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/","url":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/","name":"How to Add Text-to-Speech Feature on Any Web Page - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2017-01-23T15:01:45+00:00","dateModified":"2017-10-26T16:07:16+00:00","description":"The text-to-speech feature refers to the spoken narration of a text displayed on a device. At present, devices such as laptops, tablets, and mobile phones","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/text-to-speech\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/text-to-speech\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Add Text-to-Speech Feature on Any Web Page"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-7xZ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=29015"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29015\/revisions"}],"predecessor-version":[{"id":39174,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29015\/revisions\/39174"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=29015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=29015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=29015"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=29015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}