-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarthaClient.js
More file actions
46 lines (43 loc) · 1.08 KB
/
marthaClient.js
File metadata and controls
46 lines (43 loc) · 1.08 KB
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
// marthaClient.js
(function () {
function requestMarthaTTS(text) {
return new Promise(function (resolve, reject) {
var trimmed = (text || "").trim();
if (!trimmed) {
return reject(new Error("Ingen tekst at læse."));
}
var url =
"https://oqaasileriffik.gl/martha/tts/?n=json&t=" +
encodeURIComponent(trimmed.slice(0, 10000));
fetch(url)
.then(function (res) {
if (!res.ok) {
throw new Error("Martha svarede ikke (HTTP " + res.status + ").");
}
return res.json();
})
.then(function (data) {
resolve(data);
})
.catch(function (err) {
reject(err);
});
});
}
function buildMarthaAudioUrl(fn) {
var part1 = fn.substring(0, 2);
var part2 = fn.substring(2, 4);
return (
"https://oqaasileriffik.gl/martha/data/" +
part1 +
"/" +
part2 +
"/" +
fn
);
}
window.marthaClient = {
requestMarthaTTS: requestMarthaTTS,
buildMarthaAudioUrl: buildMarthaAudioUrl,
};
})();