Skip to content

Commit

Permalink
Merge pull request #94 from Gaurav0203Shetty/text-speech
Browse files Browse the repository at this point in the history
text to speech
  • Loading branch information
shrey141102 authored Dec 6, 2023
2 parents 23e7a46 + 674c31d commit b7d04ed
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 0 deletions.
Binary file added Text-to-speech/.DS_Store
Binary file not shown.
Binary file added Text-to-speech/Images/.DS_Store
Binary file not shown.
Binary file added Text-to-speech/Images/dropdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Text-to-speech/Images/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Text-to-speech/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Text to speech-

A basic text to speech converter made using HTML, CSS and JS which features different voices!

Feel free to make any changes by pull request.}
20 changes: 20 additions & 0 deletions Text-to-speech/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text-to-speech</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="hero">
<h1>Text to speech <span>converter</span></h1>
<textarea placeholder="Write text here..."></textarea>
<div class="row">
<select></select>
<button><img src="./Images/play.png" alt="Error">Listen</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions Text-to-speech/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let speech = new SpeechSynthesisUtterance();
let voices = [];
let voiceSelect = document.querySelector("select");

window.speechSynthesis.onvoiceschanged = () => {
voices = window.speechSynthesis.getVoices();
speech.voice = voices[0];
voices.forEach((voice, i) => (voiceSelect.options[i] = new Option(voice.name, i)));
};

voiceSelect.addEventListener("change", () => {
speech.voice = voices[voiceSelect.value];
});

document.querySelector("button").addEventListener("click", () => {
speech.text = document.querySelector("textarea").value;
window.speechSynthesis.speak(speech);
});
89 changes: 89 additions & 0 deletions Text-to-speech/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
*{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
box-sizing: border-box;
}

.hero{
width: 100%;
min-height: 100vh;
background: linear-gradient(270deg, #b8e663, #4831D4);
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
color: #fff;
}

.hero h1{
font-size: 45px;
font-weight: 500;
margin-top: -50px;
margin-bottom: 50px;
}

.hero h1 span{
color: #b8e663;
}

textarea{
width: 600px;
height: 250px;
background: #403d84;
color: #fff;
font-size: 15px;
border: 0;
outline: 0;
padding: 20px;
border-radius: 10px;
resize: none;
margin-bottom: 30px;
}

textarea::placeholder{
font-size: 16px;
color: #ddd;
}

.row{
width: 600px;
display: flex;
align-items: center;
gap: 20px;
}

button{
background: #90dd02;
color: black;
font-size: 16px;
padding: 10px 30px;
border-radius: 35px;
border: 0;
outline: 0;
cursor: pointer;
display: flex;
align-items: center;
}

button img{
width: 25px;
margin-right: 10px;
}

select{
flex: 1;
color: black;
background: #90dd02;
height: 50px;
padding: 0 20px;
outline: 0;
border: 0;
border-radius: 35px;
appearance: none;
background-image: url(./Images/dropdown.png);
background-repeat: no-repeat;
background-size: 15px;
background-position-x:calc(100% - 20px);
background-position-y:20px;
}

0 comments on commit b7d04ed

Please sign in to comment.