-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoicerecordpoc.html
139 lines (120 loc) · 4.15 KB
/
voicerecordpoc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<title>Speech to Text Demo</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
body {
display: flex;
justify-content: center;
align-items: flex-start;
height: 100vh;
padding-top: 10vh;
margin: 0;
background: #ffffff;
font-family: Arial, sans-serif;
}
form {
background: #f2f2f2;
padding: 2rem;
border-radius: 10px;
box-shadow: 0px 10px 20px -5px rgba(0, 0, 0, 0.1);
width: 400px;
height: 300px;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
}
button {
color: #ffffff;
background-color: rgba(70, 130, 180, 0.6);
border: none;
padding: 0.5rem 0.8rem;
margin-top: 1rem;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
outline: none;
display: inline-flex;
align-items: center;
justify-content: center;
}
button:hover {
background-color: rgba(70, 130, 180, 0.8);
}
label {
color: #000;
display: inline-block;
}
.fa-microphone {
margin-right: 10px;
}
#language {
margin-bottom: 20px;
}
@keyframes flashing {
0% { color: #000; }
50% { color: rgba(70, 130, 180, 0.8); }
100% { color: #000; }
}
.recording {
animation: flashing 1s infinite;
}
label[for="language"] {
margin-bottom: 10px; /* Space between label and dropdown */
}
#language {
margin-bottom: 20px;
border-radius: 5px; /* Rounded corners */
padding: 0.3rem; /* Slight padding for aesthetics */
}
</style>
</head>
<body>
<form action="#" method="POST">
<h1>Speech to Text Demo</h1>
<label for="language">Choose a language:</label>
<select id="language">
<option value="en-US">English (US)</option>
<option value="ru-RU">Русский (Russian)</option>
<option value="zh-CN">中文 (Chinese)</option>
<option value="hi-IN">हिन्दी (Hindi)</option>
<option value="de-DE">Deutsch (German)</option>
<option value="es-ES">Español (Spanish)</option>
<option value="fr-FR">Français (French)</option>
<option value="ar-SA">العربية (Arabic)</option>
</select>
<br>
<label for="speech-input">
<i class="fas fa-microphone"></i>
Say something:
</label>
<br>
<button type="button" id="start-recognition-btn">Start Recognition</button>
</form>
<script>
const SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;
const recognition = new SpeechRecognition();
const startRecognitionBtn = document.querySelector('#start-recognition-btn');
const languageSelect = document.querySelector('#language');
const microphoneIcon = document.querySelector('.fa-microphone');
startRecognitionBtn.addEventListener('click', () => {
recognition.lang = languageSelect.value;
recognition.start();
startRecognitionBtn.disabled = true;
microphoneIcon.classList.add('recording');
});
recognition.addEventListener('result', (event) => {
const transcript = event.results[0][0].transcript;
alert(transcript);
});
recognition.addEventListener('end', () => {
startRecognitionBtn.disabled = false;
microphoneIcon.classList.remove('recording');
});
</script>
</body>
</html>