Advertisement

How to Add a "Play Button" in Blogger Articles

There is a article content in some site, and you will see "play" button in that article. Now, how to add that "play button" in blogger articles ? You can follow steps given below to achieve this.

Add this section of code, where you want to show play button :

<!-- Play Button -->
<button onclick="readArticle()">▶ Play</button>

When you start a article section, then your code should look like this :

<!-- Blog Content -->
<div id="post-content">
  <h2>My Blog Post Title</h2>
  <p>This is a sample blog post. The play button should read this text aloud.</p>
</div>

Note : Just add this before your article start line : <div id="post-content">

Finally add this in your post or article section :

<!-- Text-to-Speech Script -->
<script>
function readArticle() {
    let text = document.getElementById("post-content").innerText;
    let speech = new SpeechSynthesisUtterance(text);
    speech.lang = 'en-US'; // Change language if needed
    speech.rate = 1.0; // Adjust speed (0.5 = slow, 2.0 = fast)
    speech.pitch = 1.0; // Adjust pitch (0.5 = low, 2.0 = high)
    window.speechSynthesis.speak(speech);
}
</script>

Now preview or publish your content and check if play button is showing and actually working or not. 





Post a Comment

0 Comments