@agnocon/piece-camb-ai 0.1.7
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/LICENSE.MIT-AP +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/create-text-to-sound.d.ts +8 -0
- package/dist/lib/actions/create-text-to-sound.d.ts.map +1 -0
- package/dist/lib/actions/create-text-to-sound.js +100 -0
- package/dist/lib/actions/create-text-to-sound.js.map +1 -0
- package/dist/lib/actions/create-text-to-speech.d.ts +11 -0
- package/dist/lib/actions/create-text-to-speech.d.ts.map +1 -0
- package/dist/lib/actions/create-text-to-speech.js +121 -0
- package/dist/lib/actions/create-text-to-speech.js.map +1 -0
- package/dist/lib/actions/create-transcription.d.ts +9 -0
- package/dist/lib/actions/create-transcription.d.ts.map +1 -0
- package/dist/lib/actions/create-transcription.js +134 -0
- package/dist/lib/actions/create-transcription.js.map +1 -0
- package/dist/lib/actions/create-translation.d.ts +10 -0
- package/dist/lib/actions/create-translation.d.ts.map +1 -0
- package/dist/lib/actions/create-translation.js +116 -0
- package/dist/lib/actions/create-translation.js.map +1 -0
- package/dist/lib/auth.d.ts +2 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +41 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/common/index.d.ts +10 -0
- package/dist/lib/common/index.d.ts.map +1 -0
- package/dist/lib/common/index.js +152 -0
- package/dist/lib/common/index.js.map +1 -0
- package/package.json +47 -0
- package/src/index.ts +34 -0
- package/src/lib/actions/create-text-to-sound.ts +104 -0
- package/src/lib/actions/create-text-to-speech.ts +121 -0
- package/src/lib/actions/create-transcription.ts +132 -0
- package/src/lib/actions/create-translation.ts +115 -0
- package/src/lib/auth.ts +34 -0
- package/src/lib/common/index.ts +165 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AAC,2DAA2D,CAAC,CAAC;YACjF,CAAC;YAED,MAAM,cAAc,GAAG,MAAM,0BAAU,CAAC,WAAW,CAA6B;gBAC5E,MAAM,EAAE,0BAAU,CAAC,GAAG;gBACtB,GAAG,EAAE,GAAG,qBAAY,uBAAuB,MAAM,EAAE;gBACnD,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;aAC7C,CAAC,CAAC;YAEH,OAAO,cAAc,CAAC,IAAI,CAAC;QAG/B,CAAC;KAAA;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,8DA6BrB,CAAC"}
|
package/dist/lib/auth.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cambaiAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/camb-ai/src/lib/auth.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
const common_1 = require("./common");
|
|
10
|
+
exports.cambaiAuth = pieces_framework_1.PieceAuth.SecretText({
|
|
11
|
+
displayName: "API Key",
|
|
12
|
+
description: `
|
|
13
|
+
To get your API key, please follow these steps:
|
|
14
|
+
1. Log in to your [CAMB.AI Studio](https://camb.ai/studio/) account.
|
|
15
|
+
2. Navigate to your workspace's API Keys dashboard.
|
|
16
|
+
3. Create a new key if you haven't already.
|
|
17
|
+
4. Copy the API key and paste it here.
|
|
18
|
+
`,
|
|
19
|
+
required: true,
|
|
20
|
+
validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
21
|
+
try {
|
|
22
|
+
yield pieces_common_1.httpClient.sendRequest({
|
|
23
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
24
|
+
url: `${common_1.API_BASE_URL}/source-languages`,
|
|
25
|
+
headers: {
|
|
26
|
+
'x-api-key': auth,
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
valid: true,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return {
|
|
35
|
+
valid: false,
|
|
36
|
+
error: 'Invalid API Key.',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;AAAA,sFAAsF;AACtF,qEAAqE;AACrE,gEAAsD;AACtD,0DAAgE;AAChE,qCAAwC;AAE3B,QAAA,UAAU,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC3C,WAAW,EAAE,SAAS;IACtB,WAAW,EAAE;;;;;;KAMZ;IACD,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;QACrB,IAAI,CAAC;YACD,MAAM,0BAAU,CAAC,WAAW,CAAC;gBACzB,MAAM,EAAE,0BAAU,CAAC,GAAG;gBACtB,GAAG,EAAE,GAAG,qBAAY,mBAAmB;gBACvC,OAAO,EAAE;oBACL,WAAW,EAAE,IAAI;iBACpB;aACJ,CAAC,CAAC;YACH,OAAO;gBACH,KAAK,EAAE,IAAI;aACd,CAAC;QACN,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO;gBACH,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,kBAAkB;aAC5B,CAAC;QACN,CAAC;IACL,CAAC,CAAA;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const API_BASE_URL = "https://client.camb.ai/apis";
|
|
2
|
+
export declare const POLLING_INTERVAL_MS = 5000;
|
|
3
|
+
export declare const LONG_POLLING_INTERVAL_MS = 10000;
|
|
4
|
+
export declare const MAX_POLLING_ATTEMPTS = 10;
|
|
5
|
+
export declare const LONG_MAX_POLLING_ATTEMPTS = 120;
|
|
6
|
+
export declare const listVoicesDropdown: import("@agnocon/pieces-framework").DropdownProperty<number, true, import("@agnocon/pieces-framework").SecretTextProperty<true>>;
|
|
7
|
+
export declare const listSourceLanguagesDropdown: import("@agnocon/pieces-framework").DropdownProperty<number, true, import("@agnocon/pieces-framework").SecretTextProperty<true>>;
|
|
8
|
+
export declare const listTargetLanguagesDropdown: import("@agnocon/pieces-framework").DropdownProperty<number, true, import("@agnocon/pieces-framework").SecretTextProperty<true>>;
|
|
9
|
+
export declare const listFoldersDropdown: import("@agnocon/pieces-framework").DropdownProperty<number, false, import("@agnocon/pieces-framework").SecretTextProperty<true>>;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/common/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,gCAAgC,CAAC;AAC1D,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAC9C,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAmB7C,eAAO,MAAM,kBAAkB,kIA8B7B,CAAC;AAGH,eAAO,MAAM,2BAA2B,kIA8BtC,CAAC;AAGH,eAAO,MAAM,2BAA2B,kIA8BtC,CAAC;AAEH,eAAO,MAAM,mBAAmB,mIAsC9B,CAAC"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listFoldersDropdown = exports.listTargetLanguagesDropdown = exports.listSourceLanguagesDropdown = exports.listVoicesDropdown = exports.LONG_MAX_POLLING_ATTEMPTS = exports.MAX_POLLING_ATTEMPTS = exports.LONG_POLLING_INTERVAL_MS = exports.POLLING_INTERVAL_MS = exports.API_BASE_URL = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/camb-ai/src/lib/common/index.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
8
|
+
const pieces_common_1 = require("@agnocon/pieces-common");
|
|
9
|
+
const auth_1 = require("../auth");
|
|
10
|
+
exports.API_BASE_URL = "https://client.camb.ai/apis";
|
|
11
|
+
exports.POLLING_INTERVAL_MS = 5000;
|
|
12
|
+
exports.LONG_POLLING_INTERVAL_MS = 10000;
|
|
13
|
+
exports.MAX_POLLING_ATTEMPTS = 10;
|
|
14
|
+
exports.LONG_MAX_POLLING_ATTEMPTS = 120;
|
|
15
|
+
exports.listVoicesDropdown = pieces_framework_1.Property.Dropdown({
|
|
16
|
+
auth: auth_1.cambaiAuth,
|
|
17
|
+
displayName: 'Voice',
|
|
18
|
+
description: 'Select the voice to generate the speech.',
|
|
19
|
+
required: true,
|
|
20
|
+
refreshers: [],
|
|
21
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
22
|
+
var _b;
|
|
23
|
+
if (!auth) {
|
|
24
|
+
return {
|
|
25
|
+
disabled: true,
|
|
26
|
+
options: [],
|
|
27
|
+
placeholder: 'Please authenticate first',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
31
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
32
|
+
url: `${exports.API_BASE_URL}/list-voices`,
|
|
33
|
+
headers: {
|
|
34
|
+
'x-api-key': auth.secret_text,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const voices = (_b = response.body) !== null && _b !== void 0 ? _b : [];
|
|
38
|
+
return {
|
|
39
|
+
disabled: false,
|
|
40
|
+
options: voices.map((voice) => ({
|
|
41
|
+
label: voice.voice_name,
|
|
42
|
+
value: voice.id,
|
|
43
|
+
})),
|
|
44
|
+
};
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
exports.listSourceLanguagesDropdown = pieces_framework_1.Property.Dropdown({
|
|
48
|
+
auth: auth_1.cambaiAuth,
|
|
49
|
+
displayName: 'Source Language',
|
|
50
|
+
description: 'Select the original language of the input text.',
|
|
51
|
+
required: true,
|
|
52
|
+
refreshers: [],
|
|
53
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
54
|
+
var _b;
|
|
55
|
+
if (!auth) {
|
|
56
|
+
return {
|
|
57
|
+
disabled: true,
|
|
58
|
+
options: [],
|
|
59
|
+
placeholder: 'Please authenticate first',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
63
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
64
|
+
url: `${exports.API_BASE_URL}/source-languages`,
|
|
65
|
+
headers: {
|
|
66
|
+
'x-api-key': auth.secret_text,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
const languages = (_b = response.body) !== null && _b !== void 0 ? _b : [];
|
|
70
|
+
return {
|
|
71
|
+
disabled: false,
|
|
72
|
+
options: languages.map((lang) => ({
|
|
73
|
+
label: `${lang.language} (${lang.short_name})`,
|
|
74
|
+
value: lang.id,
|
|
75
|
+
})),
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
exports.listTargetLanguagesDropdown = pieces_framework_1.Property.Dropdown({
|
|
80
|
+
displayName: 'Target Language',
|
|
81
|
+
description: 'Select the language to translate the text into.',
|
|
82
|
+
auth: auth_1.cambaiAuth,
|
|
83
|
+
required: true,
|
|
84
|
+
refreshers: [],
|
|
85
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
86
|
+
var _b;
|
|
87
|
+
if (!auth) {
|
|
88
|
+
return {
|
|
89
|
+
disabled: true,
|
|
90
|
+
options: [],
|
|
91
|
+
placeholder: 'Please authenticate first',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
95
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
96
|
+
url: `${exports.API_BASE_URL}/target-languages`,
|
|
97
|
+
headers: {
|
|
98
|
+
'x-api-key': auth.secret_text,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const languages = (_b = response.body) !== null && _b !== void 0 ? _b : [];
|
|
102
|
+
return {
|
|
103
|
+
disabled: false,
|
|
104
|
+
options: languages.map((lang) => ({
|
|
105
|
+
label: `${lang.language} (${lang.short_name})`,
|
|
106
|
+
value: lang.id,
|
|
107
|
+
})),
|
|
108
|
+
};
|
|
109
|
+
}),
|
|
110
|
+
});
|
|
111
|
+
exports.listFoldersDropdown = pieces_framework_1.Property.Dropdown({
|
|
112
|
+
displayName: 'Folder',
|
|
113
|
+
auth: auth_1.cambaiAuth,
|
|
114
|
+
description: 'Select the folder to save the task in.',
|
|
115
|
+
required: false,
|
|
116
|
+
refreshers: [],
|
|
117
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
118
|
+
var _b;
|
|
119
|
+
if (!auth) {
|
|
120
|
+
return {
|
|
121
|
+
disabled: true,
|
|
122
|
+
options: [],
|
|
123
|
+
placeholder: 'Please authenticate first',
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
128
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
129
|
+
url: `${exports.API_BASE_URL}/folders`,
|
|
130
|
+
headers: {
|
|
131
|
+
'x-api-key': auth.secret_text,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const folders = (_b = response.body) !== null && _b !== void 0 ? _b : [];
|
|
135
|
+
return {
|
|
136
|
+
disabled: false,
|
|
137
|
+
options: folders.map((folder) => ({
|
|
138
|
+
label: folder.folder_name,
|
|
139
|
+
value: folder.folder_id,
|
|
140
|
+
})),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
return {
|
|
145
|
+
disabled: true,
|
|
146
|
+
options: [],
|
|
147
|
+
placeholder: "Could not load folders."
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}),
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/common/index.ts"],"names":[],"mappings":";;;;AAAA,8FAA8F;AAC9F,qEAAqE;AACrE,gEAAqD;AACrD,0DAAgE;AAChE,kCAAqC;AAGxB,QAAA,YAAY,GAAG,6BAA6B,CAAC;AAC7C,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAC3B,QAAA,wBAAwB,GAAG,KAAK,CAAC;AACjC,QAAA,oBAAoB,GAAG,EAAE,CAAC;AAC1B,QAAA,yBAAyB,GAAG,GAAG,CAAC;AAmBhC,QAAA,kBAAkB,GAAG,2BAAQ,CAAC,QAAQ,CAAC;IAChD,IAAI,EAAE,iBAAU;IAChB,WAAW,EAAE,OAAO;IACpB,WAAW,EAAE,0CAA0C;IACvD,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,EAAE;IACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;;QACpB,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO;gBACH,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;gBACX,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|
4
|
+
"description": "AgnoCon camb ai connector",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"LICENSE.MIT-AP"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"vendor": "node ../scripts/vendor-ap.mjs piece-camb-ai"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@agnocon/core-utils": "0.2.0",
|
|
25
|
+
"@agnocon/piece-types": "0.3.1",
|
|
26
|
+
"@agnocon/pieces-common": "0.12.8",
|
|
27
|
+
"@agnocon/pieces-framework": "0.36.0",
|
|
28
|
+
"tslib": "2.6.2",
|
|
29
|
+
"form-data": "^4.0.6"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "20.17.6",
|
|
33
|
+
"typescript": "5.5.4"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"agnocon": {
|
|
37
|
+
"originVersion": "0.1.7"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "restricted",
|
|
41
|
+
"tag": "latest"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"agnocon",
|
|
45
|
+
"connector"
|
|
46
|
+
]
|
|
47
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PieceAuth, createPiece } from "@agnocon/pieces-framework";
|
|
2
|
+
import { createCustomApiCallAction, httpClient, HttpMethod } from "@agnocon/pieces-common";
|
|
3
|
+
import { createTextToSound } from "./lib/actions/create-text-to-sound";
|
|
4
|
+
import { createTextToSpeech } from "./lib/actions/create-text-to-speech";
|
|
5
|
+
import { createTranslation } from "./lib/actions/create-translation";
|
|
6
|
+
import { createTranscription } from "./lib/actions/create-transcription";
|
|
7
|
+
import { API_BASE_URL } from "./lib/common";
|
|
8
|
+
import { PieceCategory } from '@agnocon/pieces-framework';
|
|
9
|
+
import { cambaiAuth } from './lib/auth';
|
|
10
|
+
|
|
11
|
+
export const cambAi = createPiece({
|
|
12
|
+
displayName: "Camb.AI",
|
|
13
|
+
auth: cambaiAuth,
|
|
14
|
+
minimumSupportedRelease: '0.36.1',
|
|
15
|
+
logoUrl: "https://cdn.activepieces.com/pieces/camb-ai.png",
|
|
16
|
+
authors: ['david-oluwaseun420','sanket-a11y'],
|
|
17
|
+
categories:[PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
|
18
|
+
actions: [
|
|
19
|
+
createTextToSound,
|
|
20
|
+
createTextToSpeech,
|
|
21
|
+
createTranslation,
|
|
22
|
+
createTranscription,
|
|
23
|
+
createCustomApiCallAction({
|
|
24
|
+
auth: cambaiAuth,
|
|
25
|
+
baseUrl: () => API_BASE_URL,
|
|
26
|
+
authMapping: async (auth) => {
|
|
27
|
+
return {
|
|
28
|
+
'x-api-key': auth.secret_text,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
triggers: [],
|
|
34
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
3
|
+
import { cambaiAuth } from '../auth';
|
|
4
|
+
import { API_BASE_URL, MAX_POLLING_ATTEMPTS, POLLING_INTERVAL_MS } from '../common';
|
|
5
|
+
import { listFoldersDropdown } from '../common';
|
|
6
|
+
|
|
7
|
+
export const createTextToSound = createAction({
|
|
8
|
+
auth: cambaiAuth,
|
|
9
|
+
name: 'create_text_to_sound',
|
|
10
|
+
displayName: 'Create Text-to-Sound',
|
|
11
|
+
description: 'Convert input text into “sound effects” using an AI model.',
|
|
12
|
+
audience: 'both',
|
|
13
|
+
aiMetadata: { description: 'Generates a sound-effect audio clip from a text prompt describing the desired effect using Camb.AI, polling until the generation task completes and returning the audio. Use to synthesize non-speech sound effects (not spoken voice — use Create Text-to-Speech for that). Duration is capped at 10 seconds (defaults to 8). Not idempotent: each call starts a new generation task and produces fresh audio.', idempotent: false },
|
|
14
|
+
props: {
|
|
15
|
+
prompt: Property.LongText({
|
|
16
|
+
displayName: 'Prompt',
|
|
17
|
+
description: 'A clear, descriptive explanation of the desired audio effect. Concise prompts yield more accurate results.',
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
duration: Property.Number({
|
|
21
|
+
displayName: 'Duration (seconds)',
|
|
22
|
+
description: 'The desired length of the audio in seconds (max 10). Defaults to 8 if not set.',
|
|
23
|
+
required: false,
|
|
24
|
+
}),
|
|
25
|
+
project_name: Property.ShortText({
|
|
26
|
+
displayName: 'Project Name',
|
|
27
|
+
description: 'A memorable name for your project to help organize tasks in your Camb.ai workspace.',
|
|
28
|
+
required: false,
|
|
29
|
+
}),
|
|
30
|
+
project_description: Property.LongText({
|
|
31
|
+
displayName: 'Project Description',
|
|
32
|
+
description: 'Provide details about your project\'s goals and specifications for documentation purposes.',
|
|
33
|
+
required: false,
|
|
34
|
+
}),
|
|
35
|
+
folder_id: listFoldersDropdown,
|
|
36
|
+
},
|
|
37
|
+
async run(context) {
|
|
38
|
+
const { auth } = context;
|
|
39
|
+
const { prompt, duration, project_name, project_description, folder_id } = context.propsValue;
|
|
40
|
+
|
|
41
|
+
const payload: Record<string, unknown> = { prompt };
|
|
42
|
+
if (duration) payload['duration'] = duration;
|
|
43
|
+
if (project_name) payload['project_name'] = project_name;
|
|
44
|
+
if (project_description) payload['project_description'] = project_description;
|
|
45
|
+
if (folder_id) payload['folder_id'] = folder_id;
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const initialResponse = await httpClient.sendRequest<{ task_id: string }>({
|
|
49
|
+
method: HttpMethod.POST,
|
|
50
|
+
url: `${API_BASE_URL}/text-to-sound`,
|
|
51
|
+
headers: {
|
|
52
|
+
'x-api-key': auth.secret_text,
|
|
53
|
+
'Content-Type': 'application/json'
|
|
54
|
+
},
|
|
55
|
+
body: payload,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const taskId = initialResponse.body.task_id;
|
|
59
|
+
let attempts = 0;
|
|
60
|
+
let run_id: string | null = null;
|
|
61
|
+
while (attempts < MAX_POLLING_ATTEMPTS) {
|
|
62
|
+
const statusResponse = await httpClient.sendRequest<{
|
|
63
|
+
status: string, run_id?: string
|
|
64
|
+
}>({
|
|
65
|
+
method: HttpMethod.GET,
|
|
66
|
+
url: `${API_BASE_URL}/text-to-sound/${taskId}`,
|
|
67
|
+
headers: {
|
|
68
|
+
'x-api-key': auth.secret_text,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const status = statusResponse.body.status;
|
|
73
|
+
|
|
74
|
+
if (status === 'SUCCESS') {
|
|
75
|
+
|
|
76
|
+
run_id = statusResponse.body.run_id ?? null;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (status === 'FAILED') {
|
|
81
|
+
|
|
82
|
+
throw new Error(`Sound generation task failed: ${JSON.stringify(statusResponse.body)}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
await new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
87
|
+
attempts++;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (!run_id) {
|
|
92
|
+
throw new Error("Sound generation task timed out or failed to return a run_id.");
|
|
93
|
+
}
|
|
94
|
+
const audioResponse = await httpClient.sendRequest({
|
|
95
|
+
method: HttpMethod.GET,
|
|
96
|
+
url: `${API_BASE_URL}/text-to-sound-result/${run_id}`,
|
|
97
|
+
headers: { 'x-api-key': auth.secret_text },
|
|
98
|
+
responseType: 'arraybuffer',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return { audio: audioResponse.body };
|
|
102
|
+
|
|
103
|
+
},
|
|
104
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { HttpMethod, httpClient, HttpResponse } from '@agnocon/pieces-common';
|
|
3
|
+
import { cambaiAuth } from '../auth';
|
|
4
|
+
import { API_BASE_URL, listSourceLanguagesDropdown, listVoicesDropdown ,POLLING_INTERVAL_MS,MAX_POLLING_ATTEMPTS } from '../common';
|
|
5
|
+
import { listFoldersDropdown } from '../common';
|
|
6
|
+
|
|
7
|
+
export const createTextToSpeech = createAction({
|
|
8
|
+
auth: cambaiAuth,
|
|
9
|
+
name: 'create_text_to_speech',
|
|
10
|
+
displayName: 'Create Text-to-Speech',
|
|
11
|
+
description: 'Convert text into speech using a specified voice, language, gender, and age group.',
|
|
12
|
+
audience: 'both',
|
|
13
|
+
aiMetadata: { description: 'Synthesizes spoken-voice audio from text via Camb.AI text-to-speech, polling until the task completes and writing the resulting WAV to a file. Requires a language and a voice_id (both selected from Camb.AI dropdowns); optionally tune gender and age. Use for spoken narration/dialogue; for non-speech sound effects use Create Text-to-Sound instead. Not idempotent: each call starts a new synthesis task and produces a new audio file.', idempotent: false },
|
|
14
|
+
props: {
|
|
15
|
+
text: Property.LongText({
|
|
16
|
+
displayName: 'Text',
|
|
17
|
+
description: 'The text to be converted to speech.',
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
language: listSourceLanguagesDropdown,
|
|
21
|
+
voice_id: listVoicesDropdown,
|
|
22
|
+
gender: Property.StaticDropdown({
|
|
23
|
+
displayName: 'Gender',
|
|
24
|
+
description: 'The gender of the speaker.',
|
|
25
|
+
required: false,
|
|
26
|
+
options: {
|
|
27
|
+
options: [
|
|
28
|
+
{ label: 'Male', value: 1 },
|
|
29
|
+
{ label: 'Female', value: 2 },
|
|
30
|
+
{ label: 'Neutral', value: 0 },
|
|
31
|
+
{ label: 'Unspecified', value: 9 },
|
|
32
|
+
],
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
age: Property.Number({
|
|
36
|
+
displayName: 'Age',
|
|
37
|
+
description: 'The age of the speaker to be generated.',
|
|
38
|
+
required: false,
|
|
39
|
+
}),
|
|
40
|
+
project_name: Property.ShortText({
|
|
41
|
+
displayName: 'Project Name',
|
|
42
|
+
description: 'A memorable name for your project to help organize tasks in your Camb.ai workspace.',
|
|
43
|
+
required: false,
|
|
44
|
+
}),
|
|
45
|
+
project_description: Property.LongText({
|
|
46
|
+
displayName: 'Project Description',
|
|
47
|
+
description: 'Provide details about your project\'s goals and specifications for documentation purposes.',
|
|
48
|
+
required: false,
|
|
49
|
+
}),
|
|
50
|
+
folder_id: listFoldersDropdown,
|
|
51
|
+
},
|
|
52
|
+
async run(context) {
|
|
53
|
+
const { auth } = context;
|
|
54
|
+
const { text, language, voice_id, gender, age, project_name, project_description, folder_id } = context.propsValue;
|
|
55
|
+
|
|
56
|
+
const payload: Record<string, unknown> = { text, language: Number(language), voice_id: Number(voice_id) };
|
|
57
|
+
if (gender !== undefined) payload['gender'] = gender;
|
|
58
|
+
if (age) payload['age'] = age;
|
|
59
|
+
if (project_name) payload['project_name'] = project_name;
|
|
60
|
+
if (project_description) payload['project_description'] = project_description;
|
|
61
|
+
if (folder_id) payload['folder_id'] = folder_id;
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const initialResponse = await httpClient.sendRequest<{ task_id: string }>({
|
|
65
|
+
method: HttpMethod.POST,
|
|
66
|
+
url: `${API_BASE_URL}/tts`,
|
|
67
|
+
headers: { 'x-api-key': auth.secret_text, 'Content-Type': 'application/json' },
|
|
68
|
+
body: payload,
|
|
69
|
+
});
|
|
70
|
+
const taskId = initialResponse.body.task_id;
|
|
71
|
+
|
|
72
|
+
let attempts = 0;
|
|
73
|
+
let run_id: string | null = null;
|
|
74
|
+
while (attempts < MAX_POLLING_ATTEMPTS) {
|
|
75
|
+
const statusResponse = await httpClient.sendRequest<{ status: string; run_id?: string }>({
|
|
76
|
+
method: HttpMethod.GET,
|
|
77
|
+
url: `${API_BASE_URL}/tts/${taskId}`,
|
|
78
|
+
headers: { 'x-api-key': auth.secret_text },
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (statusResponse.body.status === 'SUCCESS') {
|
|
82
|
+
|
|
83
|
+
run_id = statusResponse.body.run_id ?? null;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (statusResponse.body.status === 'FAILED') {
|
|
87
|
+
|
|
88
|
+
throw new Error(`Text-to-Speech task failed: ${JSON.stringify(statusResponse.body)}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await new Promise(resolve => setTimeout(resolve, POLLING_INTERVAL_MS));
|
|
92
|
+
attempts++;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if (!run_id) {
|
|
97
|
+
throw new Error("Text-to-Speech task timed out or failed to return a run_id.");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
const audioResponse: HttpResponse = await httpClient.sendRequest({
|
|
102
|
+
method: HttpMethod.GET,
|
|
103
|
+
url: `${API_BASE_URL}/tts-result/${run_id}`,
|
|
104
|
+
headers: { 'x-api-key': auth.secret_text },
|
|
105
|
+
responseType: 'arraybuffer',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const fileName = `speech_${run_id}.wav`;
|
|
109
|
+
const fileData = Buffer.from(audioResponse.body as ArrayBuffer);
|
|
110
|
+
const fileUrl = await context.files.write({
|
|
111
|
+
fileName,
|
|
112
|
+
data: fileData,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
message: "Speech generated successfully.",
|
|
117
|
+
audio_url: fileUrl,
|
|
118
|
+
run_id: run_id,
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
});
|