@fonoster/autopilot 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pilot.js +12 -11
- package/dist/types.d.ts +5 -0
- package/dist/types.js +7 -0
- package/dist/util.d.ts +38 -0
- package/dist/util.js +80 -1
- package/package.json +10 -8
package/dist/pilot.js
CHANGED
|
@@ -27,12 +27,10 @@ const types_1 = require("./events/types");
|
|
|
27
27
|
const voice_1 = require("@fonoster/voice");
|
|
28
28
|
const cerebro_1 = require("./cerebro");
|
|
29
29
|
const server_1 = require("./events/server");
|
|
30
|
-
const nanoid_1 = require("nanoid");
|
|
31
30
|
const engines_1 = require("./intents/engines");
|
|
32
31
|
const util_1 = require("./util");
|
|
33
32
|
const googleasr_1 = __importDefault(require("@fonoster/googleasr"));
|
|
34
33
|
const logger_1 = require("@fonoster/logger");
|
|
35
|
-
const googletts_1 = __importDefault(require("@fonoster/googletts"));
|
|
36
34
|
const apps_1 = __importDefault(require("@fonoster/apps"));
|
|
37
35
|
const secrets_1 = __importDefault(require("@fonoster/secrets"));
|
|
38
36
|
const envs_1 = require("./envs");
|
|
@@ -64,21 +62,24 @@ function pilot(config) {
|
|
|
64
62
|
const ieSecret = await secrets.getSecret(app.intentsEngineConfig.secretName);
|
|
65
63
|
const intentsEngine = (0, engines_1.getIntentsEngine)(app)(JSON.parse(ieSecret.secret));
|
|
66
64
|
intentsEngine?.setProjectId(app.intentsEngineConfig.projectId);
|
|
67
|
-
const voiceConfig = {
|
|
68
|
-
name: app.speechConfig.voice,
|
|
69
|
-
playbackId: (0, nanoid_1.nanoid)(),
|
|
70
|
-
cachingFields: ["name"]
|
|
71
|
-
};
|
|
72
65
|
const speechSecret = await secrets.getSecret(app.speechConfig.secretName);
|
|
73
66
|
const speechCredentials = {
|
|
74
67
|
private_key: JSON.parse(speechSecret.secret).private_key,
|
|
75
68
|
client_email: JSON.parse(speechSecret.secret).client_email
|
|
76
69
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
const voiceConfig = (0, util_1.getVoiceConfig)({
|
|
71
|
+
secretString: speechSecret.secret,
|
|
72
|
+
app,
|
|
73
|
+
config
|
|
74
|
+
});
|
|
75
|
+
logger.verbose("voice config", { voiceConfig });
|
|
76
|
+
const ttsPlugin = (0, util_1.getTTSPlugin)({
|
|
77
|
+
languageCode: voiceConfig.languageCode,
|
|
78
|
+
vendor: voiceConfig.vendor,
|
|
79
|
+
secretString: speechSecret.secret,
|
|
80
80
|
path: config.fileRetentionPolicyDirectory
|
|
81
|
-
})
|
|
81
|
+
});
|
|
82
|
+
voiceResponse.use(ttsPlugin);
|
|
82
83
|
voiceResponse.use(new googleasr_1.default({
|
|
83
84
|
credentials: speechCredentials,
|
|
84
85
|
languageCode: config.defaultLanguageCode
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TTSVendor = void 0;
|
|
4
|
+
var TTSVendor;
|
|
5
|
+
(function (TTSVendor) {
|
|
6
|
+
TTSVendor["GOOGLE"] = "google";
|
|
7
|
+
TTSVendor["AMAZON"] = "amazon";
|
|
8
|
+
TTSVendor["MICROSOFT"] = "microsoft";
|
|
9
|
+
})(TTSVendor || (exports.TTSVendor = TTSVendor = {}));
|
package/dist/util.d.ts
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
|
+
import GoogleTTS from "@fonoster/googletts";
|
|
2
|
+
import PollyTTS from "@fonoster/pollytts";
|
|
3
|
+
import AzureTTS from "@fonoster/azuretts";
|
|
1
4
|
import { EventsClient } from "./events/emitter";
|
|
2
5
|
import { ClientEvent } from "./events/types";
|
|
6
|
+
import { TTSVendor } from "./types";
|
|
3
7
|
export declare const getEnvOrDefault: (envName: string, def: number) => number;
|
|
4
8
|
export declare const getEnvOrBool: (envName: string) => boolean;
|
|
5
9
|
export declare const removeEmpty: (obj: any) => {};
|
|
6
10
|
export declare const sendClientEvent: (eventsClient: EventsClient | null, event: ClientEvent) => void;
|
|
11
|
+
export declare const getTTSPlugin: (params: {
|
|
12
|
+
languageCode: string;
|
|
13
|
+
vendor: TTSVendor;
|
|
14
|
+
path: string;
|
|
15
|
+
secretString: string;
|
|
16
|
+
}) => PollyTTS | AzureTTS | GoogleTTS;
|
|
17
|
+
export declare const getVoiceConfig: (params: {
|
|
18
|
+
secretString: string;
|
|
19
|
+
app: {
|
|
20
|
+
speechConfig: {
|
|
21
|
+
voice: string;
|
|
22
|
+
languageCode: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
config: {
|
|
26
|
+
defaultLanguageCode: string;
|
|
27
|
+
};
|
|
28
|
+
}) => {
|
|
29
|
+
voice: string;
|
|
30
|
+
languageCode: string;
|
|
31
|
+
region: string;
|
|
32
|
+
vendor: TTSVendor;
|
|
33
|
+
cachingFields: string[];
|
|
34
|
+
playbackId: string;
|
|
35
|
+
name?: undefined;
|
|
36
|
+
} | {
|
|
37
|
+
name: string;
|
|
38
|
+
languageCode: string;
|
|
39
|
+
cachingFields: string[];
|
|
40
|
+
playbackId: string;
|
|
41
|
+
vendor: TTSVendor;
|
|
42
|
+
voice?: undefined;
|
|
43
|
+
region?: undefined;
|
|
44
|
+
};
|
package/dist/util.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendClientEvent = exports.removeEmpty = exports.getEnvOrBool = exports.getEnvOrDefault = void 0;
|
|
6
|
+
exports.getVoiceConfig = exports.getTTSPlugin = exports.sendClientEvent = exports.removeEmpty = exports.getEnvOrBool = exports.getEnvOrDefault = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/rox
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Rox AI
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License")
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
const googletts_1 = __importDefault(require("@fonoster/googletts"));
|
|
26
|
+
const pollytts_1 = __importDefault(require("@fonoster/pollytts"));
|
|
27
|
+
const azuretts_1 = __importDefault(require("@fonoster/azuretts"));
|
|
28
|
+
const types_1 = require("./types");
|
|
29
|
+
const nanoid_1 = require("nanoid");
|
|
4
30
|
const getEnvOrDefault = (envName, def) => process.env[envName] ? parseInt(process.env[envName] || "") : def;
|
|
5
31
|
exports.getEnvOrDefault = getEnvOrDefault;
|
|
6
32
|
const getEnvOrBool = (envName) => process.env[envName]
|
|
@@ -24,3 +50,56 @@ const sendClientEvent = (eventsClient, event) => {
|
|
|
24
50
|
}
|
|
25
51
|
};
|
|
26
52
|
exports.sendClientEvent = sendClientEvent;
|
|
53
|
+
const getTTSPlugin = (params) => {
|
|
54
|
+
const { path, languageCode, vendor, secretString } = params;
|
|
55
|
+
if (vendor === types_1.TTSVendor.AMAZON) {
|
|
56
|
+
const config = JSON.parse(secretString);
|
|
57
|
+
return new pollytts_1.default({
|
|
58
|
+
accessKeyId: config.tts?.credentials?.accessKeyId,
|
|
59
|
+
secretAccessKey: config.tts?.credentials?.secretAccessKey,
|
|
60
|
+
path
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (vendor === types_1.TTSVendor.MICROSOFT) {
|
|
64
|
+
const config = JSON.parse(secretString);
|
|
65
|
+
return new azuretts_1.default({
|
|
66
|
+
subscriptionKey: config.tts?.subscriptionKey,
|
|
67
|
+
serviceRegion: config.tts?.serviceRegion,
|
|
68
|
+
path
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Default to Google
|
|
72
|
+
const credentials = JSON.parse(secretString);
|
|
73
|
+
return new googletts_1.default({
|
|
74
|
+
credentials: {
|
|
75
|
+
privateKey: credentials.private_key,
|
|
76
|
+
clientEmail: credentials.client_email
|
|
77
|
+
},
|
|
78
|
+
languageCode,
|
|
79
|
+
path
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
exports.getTTSPlugin = getTTSPlugin;
|
|
83
|
+
const getVoiceConfig = (params) => {
|
|
84
|
+
const { secretString, app } = params;
|
|
85
|
+
const speechSecret = JSON.parse(secretString);
|
|
86
|
+
if ("tts" in speechSecret) {
|
|
87
|
+
const ttsConfig = speechSecret.tts;
|
|
88
|
+
return {
|
|
89
|
+
voice: ttsConfig.voice,
|
|
90
|
+
languageCode: ttsConfig.languageCode,
|
|
91
|
+
region: ttsConfig.region,
|
|
92
|
+
vendor: ttsConfig.vendor,
|
|
93
|
+
cachingFields: ttsConfig.cachingFields,
|
|
94
|
+
playbackId: (0, nanoid_1.nanoid)()
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
name: app.speechConfig.voice,
|
|
99
|
+
languageCode: app.speechConfig.languageCode || params.config.defaultLanguageCode,
|
|
100
|
+
cachingFields: ["name"],
|
|
101
|
+
playbackId: (0, nanoid_1.nanoid)(),
|
|
102
|
+
vendor: types_1.TTSVendor.GOOGLE
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
exports.getVoiceConfig = getVoiceConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/autopilot",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
"build": "tsc --build ./tsconfig.json"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@fonoster/apps": "^0.5.
|
|
16
|
-
"@fonoster/
|
|
17
|
-
"@fonoster/
|
|
18
|
-
"@fonoster/
|
|
19
|
-
"@fonoster/
|
|
20
|
-
"@fonoster/
|
|
15
|
+
"@fonoster/apps": "^0.5.5",
|
|
16
|
+
"@fonoster/azuretts": "^0.5.5",
|
|
17
|
+
"@fonoster/googleasr": "^0.5.5",
|
|
18
|
+
"@fonoster/googletts": "^0.5.5",
|
|
19
|
+
"@fonoster/logger": "^0.5.5",
|
|
20
|
+
"@fonoster/pollytts": "^0.5.5",
|
|
21
|
+
"@fonoster/secrets": "^0.5.5",
|
|
22
|
+
"@fonoster/voice": "^0.5.5",
|
|
21
23
|
"@google-cloud/dialogflow": "^4.3.1",
|
|
22
24
|
"@google-cloud/dialogflow-cx": "^2.13.0",
|
|
23
25
|
"date-fns": "^2.29.3",
|
|
@@ -37,5 +39,5 @@
|
|
|
37
39
|
"publishConfig": {
|
|
38
40
|
"access": "public"
|
|
39
41
|
},
|
|
40
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "4a1438d9dedeaf7b2a5b6a50d5e233f994e2b2cf"
|
|
41
43
|
}
|