-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_speechmatics.js
44 lines (37 loc) · 1.11 KB
/
test_speechmatics.js
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
require("dotenv").config();
const fetch = require('cross-fetch');
const FormData = require('form-data');
const fs = require('fs');
const AUTH_TOKEN = process.env.API_Speechmatics;
const PATH_TO_FILE = 'example/William_Shakehand_Green_107.mp3';
const formData = new FormData();
formData.append('data_file', fs.createReadStream(PATH_TO_FILE));
formData.append('config', JSON.stringify({
type: 'transcription',
transcription_config: {
operating_point: 'enhanced',
language: 'en',
enable_entities: true
}
}));
fetch('https://asr.api.speechmatics.com/v2/jobs/', {
method: 'POST',
headers: {
'Authorization': `Bearer ${AUTH_TOKEN}`,
...formData.getHeaders()
},
body: formData
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
const JOB_ID = 'i0w6nivmbd';
fetch(`https://asr.api.speechmatics.com/v2/jobs/${JOB_ID}/transcript?format=txt`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${AUTH_TOKEN}`
}
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error(error));