generated from lit/lit-element-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
171 lines (135 loc) · 4.21 KB
/
index.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Lit Starter Kit</title>
<script src="./src/my-element.ts" type="module"></script>
<script type="module" src="https://unpkg.com/@fluentui/web-components"></script>
<style>
html,
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
main {
display: flex;
flex-direction: column-reverse;
align-items: center;
height: 80vh;
justify-content: center;
gap: 8px;
}
fluent-text-area::part(control) {
height: 40vh;
width: 80vw;
}
#recording-bar {
display: none;
align-items: center;
justify-content: center;
position: fixed;
top: 8vh;
left: 0;
right: 0;
font-family: sans-serif;
font-weight: bold;
font-size: 14px;
animation: quickdown 0.3s;
}
#recording-bar p {
min-width: 8em;
background: #036ac4;
color: white;
border-radius: 20px;
padding: 10px;
font-size: 12px;
text-align: center;
box-shadow: 0px 2px 6px 0px #0000007a;
}
#instruct {
font-size: 12px;
}
@keyframes quickdown {
0% {
transform: translateY(-10px);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
</style>
</head>
<body>
<div id="recording-bar">
<p>Recording...</p>
</div>
<main>
<speech-to-text localOrCloud="local">
<fluent-button appearance="accent" id="start-button">Start</fluent-button>
<fluent-button id="stop-button">Stop</fluent-button>
<fluent-button id="file-button">Transcribe File</fluent-button>
</speech-to-text>
<p id="instruct">Press Start and then start speaking, when you are done press Stop and your speech will be
transcribed</p>
<fluent-text-area></fluent-text-area>
</main>
<script type="module">
document.querySelector('#start-button').addEventListener('click', startRecording);
document.querySelector('#stop-button').addEventListener('click', stopRecording);
document.querySelector("#file-button").addEventListener('click', transcribeFile);
window.addEventListener("interim-transcription", (e) => {
console.log('interim-transcription', e.detail);
document.querySelector('fluent-text-area').value = e.detail.message;
});
const speechToText = document.querySelector('speech-to-text');
let lines = [];
speechToText.addEventListener('recognized', (e) => {
console.log('recognized', e.detail.message);
if (e.detail.complete_message) {
document.querySelector('fluent-text-area').value = e.detail.complete_message;
}
else {
lines.push(e.detail.message);
document.querySelector('fluent-text-area').value = lines.join('\n');
}
});
function startRecording() {
console.log('startRecording');
speechToText.startSpeechToText();
const recordingBar = document.querySelector('#recording-bar');
recordingBar.style.display = 'flex';
const recordingButton = document.querySelector('#start-button');
recordingButton.disabled = true;
}
function stopRecording() {
console.log('stopRecording');
speechToText.stopSpeechToText();
const recordingBar = document.querySelector('#recording-bar');
recordingBar.style.display = 'none';
const recordingButton = document.querySelector('#start-button');
recordingButton.disabled = false;
}
async function transcribeFile() {
const pickerOpts = {
types: [
{
description: "Audio",
accept: {
"audio/*": [".wav"],
},
},
],
excludeAcceptAllOption: true,
multiple: false,
};
// Open file picker and destructure the result the first handle
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
// get file contents
const fileData = await fileHandle.getFile();
const speechToText = document.querySelector('speech-to-text');
speechToText.transcribeFile(fileData);
}
</script>
</body>
</html>