@pipedream/palatine_speech 0.0.1 → 0.1.0
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/actions/download-transcription/download-transcription.mjs +65 -0
- package/actions/get-task-status/get-task-status.mjs +47 -0
- package/actions/mark-task-done/mark-task-done.mjs +37 -0
- package/actions/transcribe-audio/transcribe-audio.mjs +133 -0
- package/common/constants.mjs +7 -0
- package/package.json +4 -1
- package/palatine_speech.app.mjs +104 -5
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import app from "../../palatine_speech.app.mjs";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
key: "palatine_speech-download-transcription",
|
|
7
|
+
name: "Download Transcription",
|
|
8
|
+
description: "Downloads the transcription results in a specified file format (SRT, VTT, TXT, CSV, or XLSX). The task must be completed before downloading. [See the documentation](https://docs.speech.palatine.ru/api-reference/transcribe/transcribe-polling-api/download-as-file)",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "action",
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
destructiveHint: false,
|
|
14
|
+
openWorldHint: true,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
app,
|
|
18
|
+
taskId: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
app,
|
|
21
|
+
"taskId",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
fileFormat: {
|
|
25
|
+
propDefinition: [
|
|
26
|
+
app,
|
|
27
|
+
"fileFormat",
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
filename: {
|
|
31
|
+
type: "string",
|
|
32
|
+
label: "Filename",
|
|
33
|
+
description: "The name of the file to save the transcription to in the `/tmp` directory",
|
|
34
|
+
},
|
|
35
|
+
syncDir: {
|
|
36
|
+
type: "dir",
|
|
37
|
+
accessMode: "write",
|
|
38
|
+
sync: true,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
async run({ $ }) {
|
|
42
|
+
const {
|
|
43
|
+
app,
|
|
44
|
+
taskId,
|
|
45
|
+
fileFormat,
|
|
46
|
+
filename,
|
|
47
|
+
} = this;
|
|
48
|
+
|
|
49
|
+
const response = await app.downloadTranscription({
|
|
50
|
+
$,
|
|
51
|
+
taskId,
|
|
52
|
+
params: {
|
|
53
|
+
file_format: fileFormat,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const filePath = path.join("/tmp", path.basename(filename));
|
|
58
|
+
fs.writeFileSync(filePath, response);
|
|
59
|
+
|
|
60
|
+
$.export("$summary", `Successfully downloaded transcription to ${filePath}`);
|
|
61
|
+
return {
|
|
62
|
+
filePath,
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import app from "../../palatine_speech.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "palatine_speech-get-task-status",
|
|
5
|
+
name: "Get Task Status",
|
|
6
|
+
description: "Retrieves the status and results of a transcription task. Use this to poll for completion after starting a transcription job. [See the documentation](https://docs.speech.palatine.ru/api-reference/transcribe/transcribe-polling-api/task-status)",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
annotations: {
|
|
10
|
+
readOnlyHint: true,
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
openWorldHint: true,
|
|
13
|
+
},
|
|
14
|
+
props: {
|
|
15
|
+
app,
|
|
16
|
+
taskId: {
|
|
17
|
+
propDefinition: [
|
|
18
|
+
app,
|
|
19
|
+
"taskId",
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
responseFormat: {
|
|
23
|
+
propDefinition: [
|
|
24
|
+
app,
|
|
25
|
+
"responseFormat",
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
async run({ $ }) {
|
|
30
|
+
const {
|
|
31
|
+
app,
|
|
32
|
+
taskId,
|
|
33
|
+
responseFormat,
|
|
34
|
+
} = this;
|
|
35
|
+
|
|
36
|
+
const response = await app.getTaskStatus({
|
|
37
|
+
$,
|
|
38
|
+
taskId,
|
|
39
|
+
params: {
|
|
40
|
+
response_format: responseFormat,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
$.export("$summary", `Successfully retrieved task status as \`${response.status}\`.`);
|
|
45
|
+
return response;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import app from "../../palatine_speech.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "palatine_speech-mark-task-done",
|
|
5
|
+
name: "Mark Task Done",
|
|
6
|
+
description: "Marks a transcription task as completed and removes it from the list of active tasks. Use this to clean up resources after retrieving results. [See the documentation](https://docs.speech.palatine.ru/api-reference/transcribe/transcribe-polling-api/task-done)",
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
annotations: {
|
|
10
|
+
readOnlyHint: false,
|
|
11
|
+
destructiveHint: true,
|
|
12
|
+
openWorldHint: true,
|
|
13
|
+
},
|
|
14
|
+
props: {
|
|
15
|
+
app,
|
|
16
|
+
taskId: {
|
|
17
|
+
propDefinition: [
|
|
18
|
+
app,
|
|
19
|
+
"taskId",
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
async run({ $ }) {
|
|
24
|
+
const {
|
|
25
|
+
app,
|
|
26
|
+
taskId,
|
|
27
|
+
} = this;
|
|
28
|
+
|
|
29
|
+
const response = await app.markTaskDone({
|
|
30
|
+
$,
|
|
31
|
+
taskId,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
$.export("$summary", "Successfully marked task as done");
|
|
35
|
+
return response;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import FormData from "form-data";
|
|
2
|
+
import {
|
|
3
|
+
getFileStreamAndMetadata,
|
|
4
|
+
ConfigurationError,
|
|
5
|
+
} from "@pipedream/platform";
|
|
6
|
+
import app from "../../palatine_speech.app.mjs";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
key: "palatine_speech-transcribe-audio",
|
|
10
|
+
name: "Transcribe Audio",
|
|
11
|
+
description: "Starts an asynchronous transcription job for an audio or video file. Optionally wait for completion by enabling the 'Wait for Completion' option. [See the documentation](https://docs.speech.palatine.ru/api-reference/transcribe/transcribe-polling-api/transcribe)",
|
|
12
|
+
version: "0.0.1",
|
|
13
|
+
type: "action",
|
|
14
|
+
annotations: {
|
|
15
|
+
readOnlyHint: false,
|
|
16
|
+
destructiveHint: false,
|
|
17
|
+
openWorldHint: true,
|
|
18
|
+
},
|
|
19
|
+
props: {
|
|
20
|
+
app,
|
|
21
|
+
filePath: {
|
|
22
|
+
type: "string",
|
|
23
|
+
label: "File Path or URL",
|
|
24
|
+
description: "Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.mp3`)",
|
|
25
|
+
},
|
|
26
|
+
model: {
|
|
27
|
+
propDefinition: [
|
|
28
|
+
app,
|
|
29
|
+
"model",
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
fastInference: {
|
|
33
|
+
propDefinition: [
|
|
34
|
+
app,
|
|
35
|
+
"fastInference",
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
waitForCompletion: {
|
|
39
|
+
type: "boolean",
|
|
40
|
+
label: "Wait for Completion",
|
|
41
|
+
description: "If enabled, the action will poll the task status until the transcription is complete before returning the result",
|
|
42
|
+
optional: true,
|
|
43
|
+
},
|
|
44
|
+
pollingInterval: {
|
|
45
|
+
type: "integer",
|
|
46
|
+
label: "Polling Interval (seconds)",
|
|
47
|
+
description: "Time to wait between status checks when waiting for completion. Only used if **Wait for Completion** is enabled. Defaults to `3` seconds if not specified.",
|
|
48
|
+
optional: true,
|
|
49
|
+
min: 1,
|
|
50
|
+
max: 60,
|
|
51
|
+
},
|
|
52
|
+
maxPollingAttempts: {
|
|
53
|
+
type: "integer",
|
|
54
|
+
label: "Max Polling Attempts",
|
|
55
|
+
description: "Maximum number of times to check the status before timing out. Only used if **Wait for Completion** is enabled. Defaults to `3` attempts if not specified.",
|
|
56
|
+
optional: true,
|
|
57
|
+
min: 1,
|
|
58
|
+
max: 20,
|
|
59
|
+
},
|
|
60
|
+
syncDir: {
|
|
61
|
+
type: "dir",
|
|
62
|
+
accessMode: "read",
|
|
63
|
+
sync: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
async run({ $ }) {
|
|
67
|
+
const {
|
|
68
|
+
app,
|
|
69
|
+
filePath,
|
|
70
|
+
model,
|
|
71
|
+
fastInference,
|
|
72
|
+
waitForCompletion,
|
|
73
|
+
pollingInterval = 3,
|
|
74
|
+
maxPollingAttempts = 3,
|
|
75
|
+
} = this;
|
|
76
|
+
|
|
77
|
+
const data = new FormData();
|
|
78
|
+
|
|
79
|
+
const {
|
|
80
|
+
stream,
|
|
81
|
+
metadata,
|
|
82
|
+
} = await getFileStreamAndMetadata(filePath);
|
|
83
|
+
|
|
84
|
+
data.append("file", stream, {
|
|
85
|
+
contentType: metadata.contentType,
|
|
86
|
+
knownLength: metadata.size,
|
|
87
|
+
filename: metadata.name,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const response = await app.transcribeAudio({
|
|
91
|
+
$,
|
|
92
|
+
headers: data.getHeaders(),
|
|
93
|
+
params: {
|
|
94
|
+
model,
|
|
95
|
+
fast_inference: fastInference,
|
|
96
|
+
},
|
|
97
|
+
data,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const taskId = response.task_id;
|
|
101
|
+
|
|
102
|
+
if (!waitForCompletion) {
|
|
103
|
+
$.export("$summary", "Successfully started transcription job");
|
|
104
|
+
return response;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Poll for completion
|
|
108
|
+
let attempts = 0;
|
|
109
|
+
let taskStatus;
|
|
110
|
+
|
|
111
|
+
while (attempts < maxPollingAttempts) {
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, pollingInterval * 1000));
|
|
113
|
+
|
|
114
|
+
taskStatus = await app.getTaskStatus({
|
|
115
|
+
$,
|
|
116
|
+
taskId,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (taskStatus.status === "success") {
|
|
120
|
+
$.export("$summary", "Transcription completed successfully");
|
|
121
|
+
return taskStatus;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (taskStatus.status === "error") {
|
|
125
|
+
throw new ConfigurationError(`Transcription failed: ${taskStatus.error || "Unknown error"}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
attempts++;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
throw new ConfigurationError(`Transcription timed out after ${maxPollingAttempts} attempts`);
|
|
132
|
+
},
|
|
133
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/palatine_speech",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Pipedream Palatine Speech Components",
|
|
5
5
|
"main": "palatine_speech.app.mjs",
|
|
6
6
|
"keywords": [
|
|
@@ -11,5 +11,8 @@
|
|
|
11
11
|
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@pipedream/platform": "^3.1.1"
|
|
14
17
|
}
|
|
15
18
|
}
|
package/palatine_speech.app.mjs
CHANGED
|
@@ -1,11 +1,110 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
import constants from "./common/constants.mjs";
|
|
3
|
+
|
|
1
4
|
export default {
|
|
2
5
|
type: "app",
|
|
3
6
|
app: "palatine_speech",
|
|
4
|
-
propDefinitions: {
|
|
7
|
+
propDefinitions: {
|
|
8
|
+
taskId: {
|
|
9
|
+
type: "string",
|
|
10
|
+
label: "Task ID",
|
|
11
|
+
description: "The unique identifier of the transcription task",
|
|
12
|
+
},
|
|
13
|
+
model: {
|
|
14
|
+
type: "string",
|
|
15
|
+
label: "Recognition Model",
|
|
16
|
+
description: "The speech recognition model to use",
|
|
17
|
+
options: [
|
|
18
|
+
{
|
|
19
|
+
label: "Palatine Large Highspeed",
|
|
20
|
+
value: "palatine_large_highspeed",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: "Palatine Small",
|
|
24
|
+
value: "palatine_small",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
optional: true,
|
|
28
|
+
},
|
|
29
|
+
fastInference: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
label: "Fast Inference",
|
|
32
|
+
description: "Enable accelerated inference for faster processing",
|
|
33
|
+
optional: true,
|
|
34
|
+
},
|
|
35
|
+
fileFormat: {
|
|
36
|
+
type: "string",
|
|
37
|
+
label: "File Format",
|
|
38
|
+
description: "The format for the downloaded transcription file",
|
|
39
|
+
options: [
|
|
40
|
+
"srt",
|
|
41
|
+
"vtt",
|
|
42
|
+
"txt",
|
|
43
|
+
"csv",
|
|
44
|
+
"xlsx",
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
responseFormat: {
|
|
48
|
+
type: "string",
|
|
49
|
+
label: "Response Format",
|
|
50
|
+
description: "Format for the task status response",
|
|
51
|
+
options: [
|
|
52
|
+
"srt",
|
|
53
|
+
"vtt",
|
|
54
|
+
],
|
|
55
|
+
optional: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
5
58
|
methods: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
59
|
+
getUrl(path) {
|
|
60
|
+
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
|
|
61
|
+
},
|
|
62
|
+
getHeaders(headers) {
|
|
63
|
+
return {
|
|
64
|
+
"Authorization": `Bearer ${this.$auth.api_key}`,
|
|
65
|
+
...headers,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
_makeRequest({
|
|
69
|
+
$ = this, path, headers, ...opts
|
|
70
|
+
}) {
|
|
71
|
+
return axios($, {
|
|
72
|
+
url: this.getUrl(path),
|
|
73
|
+
headers: this.getHeaders(headers),
|
|
74
|
+
...opts,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
transcribeAudio(args = {}) {
|
|
78
|
+
return this._makeRequest({
|
|
79
|
+
method: "POST",
|
|
80
|
+
path: "/transcribe/do_transcribe",
|
|
81
|
+
...args,
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
getTaskStatus({
|
|
85
|
+
taskId, ...args
|
|
86
|
+
}) {
|
|
87
|
+
return this._makeRequest({
|
|
88
|
+
path: `/transcribe/task_status/${taskId}`,
|
|
89
|
+
...args,
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
downloadTranscription({
|
|
93
|
+
taskId, ...args
|
|
94
|
+
}) {
|
|
95
|
+
return this._makeRequest({
|
|
96
|
+
path: `/transcribe/download_as_file/${taskId}`,
|
|
97
|
+
...args,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
markTaskDone({
|
|
101
|
+
taskId, ...args
|
|
102
|
+
}) {
|
|
103
|
+
return this._makeRequest({
|
|
104
|
+
method: "POST",
|
|
105
|
+
path: `/transcribe/task_done/${taskId}`,
|
|
106
|
+
...args,
|
|
107
|
+
});
|
|
9
108
|
},
|
|
10
109
|
},
|
|
11
|
-
};
|
|
110
|
+
};
|