Repository navigation
Expand file tree
/
Copy pathModel.js
More file actions
48 lines (44 loc) · 1.57 KB
/
Copy pathModel.js
File metadata and controls
48 lines (44 loc) · 1.57 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
47
48
function parseStatus(raw) {
try {
var data = JSON.parse(String(raw || "").trim())
} catch (e) {
return { ok: false, lastError: "Could not parse voice-reader status" }
}
if (!data || typeof data !== "object") return { ok: false, lastError: "Empty status" }
data.ok = true
return data
}
function stateLabel(state) {
if (state === "speaking") return "Speaking"
if (state === "paused") return "Paused"
if (state === "warming") return "Loading model"
if (state === "ingesting") return "Cloning voice"
if (state === "training") return "Fine-tuning"
if (state === "error") return "Error"
return "Idle"
}
function barIcon(state) {
if (state === "speaking") return ""
if (state === "paused") return ""
if (state === "training" || state === "ingesting") return ""
if (state === "error") return ""
return ""
}
function heroMeta(status) {
var training = status.training
if (training && training.message) return training.message
if (status.state === "speaking" && status.text) return status.text
if (status.state === "paused") return "Paused"
if (status.state === "error") return status.error || "Error"
var voice = status.voice
if (voice && voice.name) return voice.mode === "finetuned" ? voice.name + " · fine-tuned" : voice.name + " · clone"
return "Drop audio to clone a voice"
}
function fileUrlToPath(url) {
var text = String(url || "")
if (text.indexOf("file://") === 0) {
text = decodeURIComponent(text.substring(7))
if (text.indexOf("localhost") === 0) text = text.substring("localhost".length)
}
return text
}