Skip to content

Commit 17342c7

Browse files
authored
Merge pull request #161 from virejdasani/texttospeech-virejdasani-branch
Add new project: Text To Speech
2 parents 06fbd14 + c8c40ea commit 17342c7

File tree

11 files changed

+622
-0
lines changed

11 files changed

+622
-0
lines changed

TextToSpeech/VirejDasani/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [Offline Text To Speech](https://virejdasani.github.io/OfflineTextToSpeech/)
2+
3+
- Developed by [Virej Dasani](https://virejdasani.github.io/)
4+
5+
- [Live Website](https://virejdasani.github.io/OfflineTextToSpeech/)
6+
7+
![](https://raw.githubusercontent.com/virejdasani/OfflineTextToSpeech/main/assets/bannerBG.png)
175 KB
Loading
88.8 KB
Loading
Lines changed: 19 additions & 0 deletions
Loading
Lines changed: 16 additions & 0 deletions
Loading
Lines changed: 26 additions & 0 deletions
Loading
Lines changed: 19 additions & 0 deletions
Loading
773 KB
Loading
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
9+
<!-- Global site tag (gtag.js) - Google Analytics -->
10+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-L85RJPZEHX"></script>
11+
<script>
12+
window.dataLayer = window.dataLayer || [];
13+
14+
function gtag() {
15+
dataLayer.push(arguments);
16+
}
17+
gtag('js', new Date());
18+
19+
gtag('config', 'G-L85RJPZEHX');
20+
</script>
21+
22+
<link rel="icon" href="assets/icon.png" />
23+
24+
<link rel="stylesheet" href="style.css">
25+
26+
<title>Offline Text To Speech</title>
27+
</head>
28+
29+
<body>
30+
<div class="main">
31+
32+
<!-- ----------------------------------------------------------------------- -->
33+
<!-- Section 1 -->
34+
<!-- ----------------------------------------------------------------------- -->
35+
<div id="section-1" class="section-alignment">
36+
37+
<!-- Top content -->
38+
<h2 id="landing-header">Offline Text To Speech</h2>
39+
<div class="padding-semi-large"></div>
40+
41+
<p id="landing-header">Offline Text To
42+
Speech is now available as a browser extension!</p>
43+
<p><a href="https://virejdasani.github.io/OfflineTextToSpeech-Extension/">Download it here</a></p>
44+
<div class="padding"></div>
45+
46+
<textarea type="text" id="textInput" rows="8" placeholder="Enter text here to speak it"></textarea>
47+
48+
<div class="padding-semi-large"></div>
49+
50+
<!-- -------------------------- App store buttons -------------------------- -->
51+
52+
<div id="app-store-buttons">
53+
<button id="speakTextButton" class="button-standard" onclick="speakInputText()">Speak Text<img class="icon-link"
54+
src="./assets/icons/speakIcon.svg"></button>
55+
56+
<p>|</p>
57+
58+
<button id="pauseButton" class="button-standard" onclick="pauseSpeech()">Pause<img class="icon-link-small"
59+
src="./assets/icons/pauseIcon.svg"></button>
60+
61+
<p>|</p>
62+
63+
<button class="button-standard" onclick="stopSpeech()">Stop<img class="icon-link-small"
64+
src="./assets/icons/stopIcon.svg"></button>
65+
66+
</div>
67+
68+
<div id="dropdowns">
69+
<div class="optionsDiv">
70+
<select name="voiceOptions" id="voiceOptions" onchange="changeVoice(this.value)">
71+
<option value="voice1">Daniel's voice</option>
72+
<option value="voice7">Samantha's voice</option>
73+
<option value="voice3">Alex's voice</option>
74+
<option value="voice6">Olivia's voice</option>
75+
<option value="voice2">Raj's voice</option>
76+
<option value="voice4">Fiona's voice</option>
77+
<option value="voice5">Fred's voice</option>
78+
<option value="voice8">Tessa's voice</option>
79+
<option value="voice9">Victoria's voice</option>
80+
</select>
81+
</div>
82+
83+
<div class="optionsDiv">
84+
<select name="speedOptions" id="speedOptions" onchange="changeVoiceSpeed(this.value)">
85+
<option value="speed1">1x speed</option>
86+
<option value="speed0.75">0.75x speed</option>
87+
<option value="speed0.5">0.5x speed</option>
88+
<option value="speed1.25">1.25x speed</option>
89+
<option value="speed1.5">1.5x speed</option>
90+
<option value="speed1.75">1.75x speed</option>
91+
<option value="speed2">2x speed</option>
92+
93+
</select>
94+
</div>
95+
</div>
96+
97+
<div id="indicators">
98+
99+
<div id="repo-links">
100+
<a class="indicator" href="https://virejdasani.github.io" target="_blank">Developed by Virej Dasani</a>
101+
102+
<p class="indicator indicator-separator"></p>
103+
104+
<a class="indicator" href="https://github.com/virejdasani/OfflinetextToSpeech" target="_blank">GitHub</a>
105+
</div>
106+
107+
</div>
108+
</div>
109+
110+
</div>
111+
112+
<script src="index.js"></script>
113+
</body>
114+
115+
</html>

TextToSpeech/VirejDasani/index.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// This is so that if speech is still playing from previous session, it stops on page load
2+
speechSynthesis.cancel();
3+
4+
var isSpeaking = false;
5+
6+
// Initialize the speech synthesis
7+
var speech = new SpeechSynthesisUtterance();
8+
speech.rate = 1;
9+
speech.pitch = 1;
10+
speech.volume = 1;
11+
speech.voice = speechSynthesis.getVoices()[0];
12+
13+
function speakInputText() {
14+
isSpeaking = true;
15+
16+
speech.text = document.getElementById("textInput").value;
17+
speechSynthesis.speak(speech);
18+
}
19+
20+
function pauseSpeech() {
21+
if (isSpeaking) {
22+
isSpeaking = false;
23+
speechSynthesis.pause();
24+
document.getElementById(
25+
"pauseButton"
26+
).innerHTML = `Resume<img class="icon-link-small"
27+
src="./assets/icons/resumeIcon.svg">`;
28+
} else {
29+
isSpeaking = true;
30+
speechSynthesis.resume();
31+
document.getElementById(
32+
"pauseButton"
33+
).innerHTML = `Pause<img class="icon-link-small"
34+
src="./assets/icons/pauseIcon.svg">`;
35+
}
36+
}
37+
38+
function stopSpeech() {
39+
isSpeaking = false;
40+
speechSynthesis.cancel();
41+
}
42+
43+
function changeVoice(voice) {
44+
if (voice == "voice1") {
45+
// console.log((speech.voice = speechSynthesis.getVoices()[8]));
46+
speech.voice = speechSynthesis.getVoices()[8];
47+
} else if (voice == "voice2") {
48+
// console.log((speech.voice = speechSynthesis.getVoices()[0]));
49+
speech.voice = speechSynthesis.getVoices()[0];
50+
} else if (voice == "voice3") {
51+
// console.log((speech.voice = speechSynthesis.getVoices()[1]));
52+
speech.voice = speechSynthesis.getVoices()[1];
53+
} else if (voice == "voice4") {
54+
// console.log((speech.voice = speechSynthesis.getVoices()[11]));
55+
speech.voice = speechSynthesis.getVoices()[11];
56+
} else if (voice == "voice5") {
57+
// console.log((speech.voice = speechSynthesis.getVoices()[12]));
58+
speech.voice = speechSynthesis.getVoices()[12];
59+
} else if (voice == "voice6") {
60+
// console.log((speech.voice = speechSynthesis.getVoices()[18]));
61+
speech.voice = speechSynthesis.getVoices()[18];
62+
} else if (voice == "voice7") {
63+
// console.log((speech.voice = speechSynthesis.getVoices()[33]));
64+
speech.voice = speechSynthesis.getVoices()[33];
65+
} else if (voice == "voice8") {
66+
// console.log((speech.voice = speechSynthesis.getVoices()[37]));
67+
speech.voice = speechSynthesis.getVoices()[37];
68+
} else if (voice == "voice9") {
69+
// console.log((speech.voice = speechSynthesis.getVoices()[41]));
70+
speech.voice = speechSynthesis.getVoices()[41];
71+
}
72+
73+
// for (let i = 0; i < 100; i++) {
74+
// console.log((speech.voice = speechSynthesis.getVoices()[i]));
75+
// }
76+
}
77+
78+
function changeVoiceSpeed(voiceSpeed) {
79+
// For some reason, speed below 0.5 doesn't work
80+
if (voiceSpeed == "speed2") {
81+
speech.rate = 2;
82+
} else if (voiceSpeed == "speed1.75") {
83+
speech.rate = 1.75;
84+
} else if (voiceSpeed == "speed1.5") {
85+
speech.rate = 1.5;
86+
} else if (voiceSpeed == "speed1.25") {
87+
speech.rate = 1.25;
88+
} else if (voiceSpeed == "speed1") {
89+
speech.rate = 1;
90+
} else if (voiceSpeed == "speed0.75") {
91+
speech.rate = 0.75;
92+
} else if (voiceSpeed == "speed0.5") {
93+
speech.rate = 0.5;
94+
}
95+
}

0 commit comments

Comments
 (0)