-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
local.html
62 lines (50 loc) · 1.52 KB
/
local.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
<html>
<body>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" role="button">Upload File</button>
</form>
<audio src="" controls></audio>
</body>
<script>
const url = 'https://api.deepgram.com/v1/listen';
const apiKey = 'DEEPGRAM-TOKEN';
const form = document.querySelector('form');
form.addEventListener('submit', e => {
e.preventDefault();
// Create a new FileReader instance
const reader = new FileReader();
const file = document.querySelector('[name=file]').files[0];
console.log(file);
reader.readAsArrayBuffer(file);
let blob = null;
reader.addEventListener('load', () => {
console.log("creating blob");
file.arrayBuffer().then((arrayBuffer) => {
blob = new Blob([new Uint8Array(arrayBuffer)], {type: file.type });
console.log(blob);
document.querySelector('audio').setAttribute('src', URL.createObjectURL(blob));
fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Token ' + apiKey,
'Content-Type': file.type
},
body: blob
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error(error));
});
});
});
</script>
</html>
<!--
curl \
--request POST \
--header 'Authorization: Token YOUR_DEEPGRAM_API_KEY' \
--header 'Content-Type: audio/wav' \
--data-binary @youraudio.wav \
--url 'https://api.deepgram.com/v1/listen'
-->