-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvosk.js
68 lines (53 loc) · 1.96 KB
/
vosk.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { getApiUrl, doExtrasFetch } from '../../../extensions.js';
export { VoskSttProvider };
const DEBUG_PREFIX = '<Speech Recognition module (Vosk)> ';
class VoskSttProvider {
//########//
// Config //
//########//
settings;
defaultSettings = {
language: '',
};
get settingsHtml() {
let html = '';
return html;
}
onSettingsChange() {
// Used when provider settings are updated from UI
}
loadSettings(settings) {
// Populate Provider UI given input settings
if (Object.keys(settings).length == 0) {
console.debug(DEBUG_PREFIX + 'Using default vosk STT extension settings');
}
// Only accept keys defined in defaultSettings
this.settings = this.defaultSettings;
for (const key in settings) {
if (key in this.settings) {
this.settings[key] = settings[key];
} else {
throw `Invalid setting passed to STT extension: ${key}`;
}
}
$('#speech_recognition_language').val(this.settings.language);
console.debug(DEBUG_PREFIX + 'Vosk STT settings loaded');
}
async processAudio(audioblob) {
var requestData = new FormData();
requestData.append('AudioFile', audioblob, 'record.wav');
requestData.append('language', this.settings.language);
const url = new URL(getApiUrl());
url.pathname = '/api/speech-recognition/vosk/process-audio';
const apiResult = await doExtrasFetch(url, {
method: 'POST',
body: requestData,
});
if (!apiResult.ok) {
toastr.error(apiResult.statusText, 'STT Generation Failed (Vosk)', { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
}
const result = await apiResult.json();
return result.transcript;
}
}