This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
virtual-device.ts
53 lines (44 loc) · 1.65 KB
/
virtual-device.ts
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
import {IVirtualDeviceResult, VirtualDevice} from "virtual-device-sdk";
import {Global} from "../core/global";
export class VirtualDeviceClient {
public static speak(utterance: string, token?: string, locale?: string, voiceID?: string): Promise<IVirtualDeviceResult> {
if (token) {
if (Global.config()) {
Global.config().updateVirtualDeviceToken(token);
}
}
const tokenToUse = token ? token : Global.config().virtualDeviceToken();
if (!tokenToUse) {
throw new Error("Token Required");
}
const virtualDevice = new VirtualDevice(tokenToUse, locale, voiceID);
return virtualDevice.message(utterance);
}
public static renderResult(result: IVirtualDeviceResult): string {
let stringResult = "";
if (result.transcript) {
stringResult = "Transcript:\n";
stringResult += result.transcript + "\n\n";
}
if (result.streamURL) {
stringResult += "Stream:\n";
stringResult += result.streamURL + "\n\n";
}
if (result.card) {
stringResult += "Card:\n";
if (result.card.mainTitle) {
stringResult += result.card.mainTitle + "\n";
}
if (result.card.subTitle) {
stringResult += result.card.subTitle + "\n";
}
if (result.card.textField) {
stringResult += result.card.textField + "\n";
}
if (result.card.imageURL) {
stringResult += result.card.imageURL + "\n";
}
}
return stringResult;
}
}