This content originally appeared on DEV Community and was authored by Rupesh Sharma
How to Create Your Own Free Text-to-Speech Chrome Extension (Even a 5-Year-Old Can Do It!)
Written by Rupesh Sharma AKA @hackyrupesh
Hey there, friend! Have you ever wanted to make your very own Chrome extension that can read text out loud? Guess what? You can, and it's super fun and easy! By the end of this guide, you'll have your very own text-to-speech (TTS) Chrome extension that you can show off to your friends. We'll walk through everything step by step—like a buddy helping you out. Ready? Let's dive in!
🎨 Step 1: Gather Your Tools (What You Need)
Before we start, let’s make sure you have everything you need:
- A Computer (Any kind will do!)
- Google Chrome (Make sure it's installed on your computer)
- A Text Editor (Like Notepad, VS Code, or any other that you like)
- A Folder to keep all your extension files together.
🛠️ Step 2: Create the Files (Building Blocks of Our Extension)
We're going to create three simple files:
-
manifest.json
– This tells Chrome all about your extension. -
popup.html
– This is the small window that pops up when you click the extension icon. -
popup.js
– This file makes the magic happen with JavaScript.
📄 1. manifest.json
– Your Extension's ID Card
First, open your text editor and create a new file called manifest.json
. Copy and paste the following code into it:
{
"manifest_version": 3,
"name": "Super Simple Text-to-Speech",
"version": "1.0",
"description": "A friendly Chrome extension that reads text aloud.",
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
}
},
"permissions": ["activeTab"],
"icons": {
"128": "icon.png"
}
}
This file tells Chrome what your extension is, what it does, and what permissions it needs. We’ll also need an icon (icon.png
) for your extension—don’t worry, we’ll get to that in a moment!
📝 2. popup.html
– The Face of Your Extension
Next, create a file called popup.html
. This is the little window that pops up when you click your extension's icon. Here’s the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text-to-Speech</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
text-align: center;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Text-to-Speech</h1>
<textarea id="text" rows="5" cols="30" placeholder="Type something here..."></textarea>
<br><br>
<button id="speak">Speak</button>
<script src="popup.js"></script>
</body>
</html>
This file includes a simple text box where you can type what you want to hear and a button to make the text speak.
🧙♂️ 3. popup.js
– The Magic Behind the Scenes
Finally, create a file called popup.js
. This file will handle the text-to-speech part. Here’s the magic code:
document.getElementById('speak').addEventListener('click', function() {
const text = document.getElementById('text').value;
const utterance = new SpeechSynthesisUtterance(text);
speechSynthesis.speak(utterance);
});
This code grabs the text you type and uses the browser's built-in speech synthesis to read it out loud when you click the "Speak" button.
🌟 Step 3: Add an Icon (The Face of Your Extension)
Your extension needs an icon, right? Find or create a simple PNG image that represents your extension (128x128 pixels works best). Name it icon.png
and put it in the same folder as your other files. You can find free icons on websites like Iconfinder or Flaticon.
Example of what your icon might look like
🚀 Step 4: Load Your Extension into Chrome (Time to Test It!)
Now that you have all your files ready, let's load your extension into Chrome.
-
Open Chrome and go to
chrome://extensions/
. - Turn on Developer Mode (You’ll see a toggle in the top right corner).
- Click on "Load Unpacked" and select the folder where you saved your files.
And voilà! Your extension should now appear in the extensions bar. You should see your icon there.
🧪 Step 5: Test It Out! (Does It Work?)
Click on your new extension icon, type something into the text box, and hit "Speak." If everything’s working, you should hear your text read out loud!
Testing out the extension with a friendly message
🎉 Step 6: Share and Celebrate! (Show Off Your Creation)
Congrats, you’ve just built a working Chrome extension! How awesome is that? You can now share it with friends, or if you want, you can even publish it to the Chrome Web Store so everyone can use it!
🛠️ Resources and Tips (Helpful Links)
- Chrome Developer Documentation: Getting Started with Chrome Extensions
- Free Icons: Iconfinder, Flaticon
- Speech Synthesis API: MDN Web Docs
🏁 Final Thoughts
Building a Chrome extension is like creating your own little app for the browser. It’s a great way to learn more about HTML, CSS, and JavaScript while making something useful. Whether you’re 5 or 55, following these steps will help you create something amazing. Have fun, experiment, and keep coding!
Written by Rupesh Sharma AKA @hackyrupesh
This content originally appeared on DEV Community and was authored by Rupesh Sharma
Rupesh Sharma | Sciencx (2024-08-30T05:48:00+00:00) How to Create Your Own Text-to-Speech Chrome Extension. Retrieved from https://www.scien.cx/2024/08/30/how-to-create-your-own-text-to-speech-chrome-extension/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.