srivatsavdamaraju commited on
Commit
2681cfd
·
verified ·
1 Parent(s): aacab0e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +187 -18
index.html CHANGED
@@ -1,19 +1,188 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Speech Tools with Video Background</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ background-color: black;
11
+ overflow: hidden; /* Prevents scrollbars */
12
+ height: 100vh;
13
+ position: relative; /* Positioning context for absolute elements */
14
+ color: #0A74DA; /* Radium Blue color for text */
15
+ font-family: Arial, sans-serif; /* Font style */
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ flex-direction: column; /* Stack content vertically */
20
+ }
21
+ video {
22
+ position: fixed; /* Fixed position for video */
23
+ top: 50%;
24
+ left: 50%;
25
+ transform: translate(-50%, -50%); /* Center the video */
26
+ width: 100%;
27
+ height: auto;
28
+ z-index: -1; /* Sends video behind other content */
29
+ }
30
+ .text-overlay {
31
+ position: absolute; /* Absolute positioning for text */
32
+ bottom: 200px; /* Distance from the bottom of the viewport */
33
+ left: 50%;
34
+ transform: translateX(-50%); /* Center text horizontally */
35
+ font-size: 24px; /* Size of the text */
36
+ padding: 10px; /* Padding around the text */
37
+ text-align: center; /* Center text horizontally */
38
+ z-index: 1; /* Ensure text is above the video */
39
+ color: #0A74DA; /* Match text color to the body color */
40
+ }
41
+ .container {
42
+ max-width: 600px;
43
+ margin: auto;
44
+ position: relative;
45
+ z-index: 2; /* Ensure container is above the video */
46
+ }
47
+ button {
48
+ margin-top: 10px;
49
+ }
50
+ select {
51
+ margin-top: 10px;
52
+ }
53
+ .error-para {
54
+ color: red;
55
+ }
56
+ </style>
57
+ </head>
58
+ <body>
59
+ <video id="background-video" autoplay muted loop>
60
+ <source src="videos/original-b507b736387559b36766da23936f214d.mp4" type="video/mp4">
61
+ Your browser does not support the video tag.
62
+ </video>
63
+
64
+ <div class="text-overlay">
65
+ </div>
66
+
67
+ <div class="container">
68
+ <div class="app-container">
69
+ <div class="headings-container">
70
+ <h1>Speech Tools</h1>
71
+ </div>
72
+
73
+ <!-- Text to Speech Converter -->
74
+ <div class="interaction-container">
75
+ <h3>Convert Speech to Text and Play Audio</h3>
76
+ <p class="error-para"></p>
77
+ <button class="btn" id="convertBtn" disabled>Play Converted Sound</button>
78
+ </div>
79
+
80
+ <!-- Speech Recognition -->
81
+ <div>
82
+ <label for="language-select">Select Language:</label>
83
+ <select id="language-select">
84
+ <option value="en-US">English</option>
85
+ <option value="hi-IN">Hindi</option>
86
+ <option value="te-IN">Telugu</option>
87
+ </select>
88
+ <button onclick="startContinuousRecognition()">Start Continuous Recognition</button>
89
+ <div>
90
+ <h3>Recognition Result:</h3>
91
+ <p id="result"></p>
92
+ </div>
93
+ <div class="api-response" id="api-response">
94
+ <h3>API Response:</h3>
95
+ <pre id="api-response-content"></pre>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ </div>
100
+
101
+ <script>
102
+ // Text to Speech
103
+ let speechSynth = window.speechSynthesis;
104
+ let isPlaying = false;
105
+ let lastText = ''; // Track last spoken text
106
+
107
+ function convertTextToSpeech(text) {
108
+ if (!isPlaying && text.trim().length && text !== lastText) {
109
+ const utterance = new SpeechSynthesisUtterance(text);
110
+ const languageCode = document.getElementById('language-select').value;
111
+ utterance.lang = languageCode;
112
+ utterance.onstart = () => { isPlaying = true; };
113
+ utterance.onend = () => {
114
+ isPlaying = false;
115
+ lastText = text; // Update last spoken text
116
+ };
117
+ speechSynth.speak(utterance);
118
+ }
119
+ }
120
+
121
+ // Speech Recognition
122
+ let recognition = null;
123
+ const wakeWord = 'lucy';
124
+
125
+ function startContinuousRecognition() {
126
+ if (recognition) {
127
+ recognition.stop();
128
+ }
129
+ recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
130
+ const languageCode = document.getElementById('language-select').value;
131
+
132
+ recognition.lang = languageCode;
133
+ recognition.continuous = true;
134
+ recognition.interimResults = false;
135
+ recognition.maxAlternatives = 1;
136
+
137
+ recognition.onresult = function(event) {
138
+ const result = event.results[0][0].transcript.toLowerCase();
139
+ document.getElementById('result').innerText = result;
140
+
141
+ if (result.includes(wakeWord)) {
142
+ document.getElementById('result').innerText = 'Wake word detected. Listening...';
143
+ } else {
144
+ fetchApiResponse(result); // Fetch API response with recognized text
145
+ }
146
+ };
147
+
148
+ recognition.onerror = function(event) {
149
+ console.error('Speech recognition error:', event.error);
150
+ };
151
+
152
+ recognition.onend = function() {
153
+ // Optional: Uncomment the next line if you want to restart recognition after it stops
154
+ // recognition.start();
155
+ };
156
+
157
+ recognition.start();
158
+ }
159
+
160
+ function fetchApiResponse(query) {
161
+ const apiUrl = `https://srivatsavdamaraju2-l-u-c-i.hf.space/ask/${encodeURIComponent(query)}`;
162
+ fetch(apiUrl)
163
+ .then(response => response.json())
164
+ .then(data => {
165
+ const apiResponseText = data.gvp_bot_response; // Extract the relevant text
166
+ document.getElementById('api-response-content').textContent = JSON.stringify(data, null, 2);
167
+ convertTextToSpeech(apiResponseText); // Use the API response text for TTS
168
+ })
169
+ .catch(error => {
170
+ console.error('Error fetching API response:', error);
171
+ });
172
+ }
173
+
174
+ // Load voices for text-to-speech
175
+ window.speechSynthesis.onvoiceschanged = function() {
176
+ const voices = window.speechSynthesis.getVoices();
177
+ // Optionally, you can set a default voice here
178
+ };
179
+
180
+ // Stop TTS on page unload
181
+ window.addEventListener('beforeunload', function() {
182
+ if (speechSynth.speaking) {
183
+ speechSynth.cancel(); // Stop all ongoing speech synthesis
184
+ }
185
+ });
186
+ </script>
187
+ </body>
188
  </html>