-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
68 lines (58 loc) · 2.03 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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dagloAPI stream STT Example</title>
<link href="./index.css" rel="stylesheet">
</head>
<body>
<div id="liveView" class="videoView">
<label>API Token</label>
<input id="token" placeholder="YOUR TOKEN">
<br>
<label>API Endpoint</label>
<input id="host" placeholder="https://apis.daglo.ai">
<button id="enableButton" class="enable-btn">
<span class="enable-btn-label">Microphone ON</span>
</button>
<p id="result"></p>
<div id="transcripts"></div>
<div id="speech-list"></div>
</div>
<script type="module">
import { DagloAPI } from 'https://actionpower.github.io/dagloapi-js-beta/lib/daglo-api.module.js';
document.getElementById('enableButton').addEventListener('click', async (event) => {
const baseURL = document?.getElementById('host').value?.trim();
const dagloToken = document?.getElementById('token').value?.trim();
let client = new DagloAPI({
host: baseURL,
apiToken: dagloToken
});
let transcriber = client.stream.transcriber();
transcriber.on('transcript', (data) => {
console.log('[#] onTranscript', data);
if (data?.text) {
const span = document.createElement('span');
span.textContent = data?.text;
document.getElementById('transcripts').append(span);
}
})
// transcriber.start();
// or
let stream;
try {
// capture the microphone
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
}
catch (err) {
console.log("The following error occured: " + err);
return alert("getUserMedia not supported on your browser");
}
if (stream) {
transcriber.connect(stream);
}
});
</script>
</body>
</html>