@pipedream/spiritme 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.
@@ -0,0 +1,160 @@
1
+ import spiritme from "../../spiritme.app.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "spiritme-generate-video",
6
+ name: "Generate Video",
7
+ description: "Generates a new video using specific voice and avatar props. [See the documentation](https://api.spiritme.tech/api/swagger/#/videos/videos_create)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ spiritme,
12
+ name: {
13
+ type: "string",
14
+ label: "Name",
15
+ description: "Name of the video",
16
+ },
17
+ avatar: {
18
+ propDefinition: [
19
+ spiritme,
20
+ "avatar",
21
+ ],
22
+ },
23
+ voice: {
24
+ propDefinition: [
25
+ spiritme,
26
+ "voice",
27
+ ],
28
+ },
29
+ text: {
30
+ type: "string",
31
+ label: "Text",
32
+ description: "The text to use for the video. Example: `Hello everyone! I am a virtual avatar from Spiritme.` Use tags `<emotion name=\"emotion_name\"> text </emotion>` to add emotions to the generated video. The list of supported emotions are `neutral`, `semismile`, `smile`, `happiness`, `sadness`, and `surprise`. Either text or audio file is required.",
33
+ optional: true,
34
+ },
35
+ audioFile: {
36
+ propDefinition: [
37
+ spiritme,
38
+ "file",
39
+ () => ({
40
+ type: [
41
+ "audio",
42
+ ],
43
+ }),
44
+ ],
45
+ label: "Audio File",
46
+ description: "Identifier of an audio file. Either text or audio file is required.",
47
+ },
48
+ media: {
49
+ propDefinition: [
50
+ spiritme,
51
+ "file",
52
+ () => ({
53
+ type: [
54
+ "image",
55
+ "video",
56
+ ],
57
+ }),
58
+ ],
59
+ label: "Media File",
60
+ description: "Identifier of an image or video file. One of avatar or media is required.",
61
+ },
62
+ viewType: {
63
+ type: "string",
64
+ label: "View Type",
65
+ description: "Content as is or content in circle. Supported only for avatars.",
66
+ optional: true,
67
+ options: [
68
+ "rectangular",
69
+ "circular",
70
+ ],
71
+ },
72
+ autoEmotionsMarkup: {
73
+ type: "boolean",
74
+ label: "Auto Emotions Markup",
75
+ description: "Add emotions automatically by AI",
76
+ optional: true,
77
+ },
78
+ waitForCompletion: {
79
+ type: "boolean",
80
+ label: "Wait For Completion",
81
+ description: "Set to `true` to poll the API in 3-second intervals until the video is completed",
82
+ optional: true,
83
+ },
84
+ },
85
+ async run({ $ }) {
86
+ const {
87
+ spiritme,
88
+ name,
89
+ avatar,
90
+ voice,
91
+ text,
92
+ audioFile,
93
+ media,
94
+ viewType,
95
+ autoEmotionsMarkup,
96
+ waitForCompletion,
97
+ } = this;
98
+
99
+ if (!avatar && !media) {
100
+ throw new ConfigurationError("One of `Avatar` or `Media File` is required");
101
+ }
102
+
103
+ if (!text && !audioFile) {
104
+ throw new ConfigurationError("One of `Text` or `Audio File` is required");
105
+ }
106
+
107
+ let response = await spiritme.generateVideo({
108
+ $,
109
+ data: {
110
+ name,
111
+ slides: [
112
+ {
113
+ audio_source: {
114
+ text,
115
+ voice: voice
116
+ ? {
117
+ id: voice,
118
+ }
119
+ : undefined,
120
+ file: audioFile
121
+ ? {
122
+ id: audioFile,
123
+ }
124
+ : undefined,
125
+ },
126
+ layers: [
127
+ {
128
+ avatar: avatar
129
+ ? {
130
+ id: avatar,
131
+ }
132
+ : undefined,
133
+ media: media
134
+ ? {
135
+ id: media,
136
+ }
137
+ : undefined,
138
+ view_type: viewType,
139
+ },
140
+ ],
141
+ },
142
+ ],
143
+ auto_emotions_markup: autoEmotionsMarkup,
144
+ },
145
+ });
146
+
147
+ if (waitForCompletion) {
148
+ const timer = (ms) => new Promise((res) => setTimeout(res, ms));
149
+ while (response.status !== "success") {
150
+ response = await spiritme.getVideo({
151
+ videoId: response.id,
152
+ });
153
+ await timer(3000);
154
+ }
155
+ }
156
+
157
+ $.export("$summary", `Generated video with ID: ${response.id}`);
158
+ return response;
159
+ },
160
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/spiritme",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream SpiritMe Components",
5
5
  "main": "spiritme.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.0.0"
14
17
  }
15
18
  }
@@ -0,0 +1,85 @@
1
+ import spiritme from "../../spiritme.app.mjs";
2
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3
+ import sampleEmit from "./test-event.mjs";
4
+
5
+ export default {
6
+ key: "spiritme-new-avatar-video-completion",
7
+ name: "New Avatar Video Completion",
8
+ description: "Emit new event when an avatar video completes rendering.",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ props: {
13
+ spiritme,
14
+ db: "$.service.db",
15
+ timer: {
16
+ type: "$.interface.timer",
17
+ default: {
18
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
19
+ },
20
+ },
21
+ },
22
+ hooks: {
23
+ async deploy() {
24
+ await this.processEvent(25);
25
+ },
26
+ },
27
+ methods: {
28
+ _getLastTs() {
29
+ return this.db.get("lastTs") || 0;
30
+ },
31
+ _setLastTs(lastTs) {
32
+ this.db.set("lastTs", lastTs);
33
+ },
34
+ emitEvent(video) {
35
+ const meta = this.generateMeta(video);
36
+ this.$emit(video, meta);
37
+ },
38
+ generateMeta(video) {
39
+ return {
40
+ id: video.id,
41
+ summary: `New Video: ${video.name}`,
42
+ ts: Date.parse(video.gd),
43
+ };
44
+ },
45
+ async processEvent(max) {
46
+ const lastTs = this._getLastTs();
47
+ const params = {
48
+ limit: 100,
49
+ offset: 0,
50
+ status: [
51
+ "success",
52
+ ],
53
+ };
54
+ let total;
55
+
56
+ const videos = [];
57
+ do {
58
+ const { results } = await this.spiritme.listVideos({
59
+ params,
60
+ });
61
+ for (const video of results) {
62
+ const ts = Date.parse(video.gd);
63
+ if (ts >= lastTs && (!max || videos.length < max)) {
64
+ videos.push(video);
65
+ } else {
66
+ break;
67
+ }
68
+ }
69
+ params.offset += params.limit;
70
+ total = results?.length;
71
+ } while (total === params.limit && (!max || videos.length < max));
72
+
73
+ if (!videos.length) {
74
+ return;
75
+ }
76
+
77
+ this._setLastTs(Date.parse(videos[0].gd));
78
+ videos.reverse().forEach((video) => this.emitEvent(video));
79
+ },
80
+ },
81
+ async run() {
82
+ await this.processEvent();
83
+ },
84
+ sampleEmit,
85
+ };
@@ -0,0 +1,51 @@
1
+ export default {
2
+ "id": 85987,
3
+ "cd": "2024-06-28T21:32:14.878982Z",
4
+ "gd": "2024-06-28T21:34:37.340485Z",
5
+ "name": "Video",
6
+ "slides": [
7
+ {
8
+ "id": 1,
9
+ "audio_source": {
10
+ "text": "<emotion name=\"happiness\">Pipedream is the best!</emotion>",
11
+ "voice": {
12
+ "id": 18,
13
+ "name": "Kimberly",
14
+ "label": "English Kimberly",
15
+ "provider": "amazon",
16
+ "sex": "female"
17
+ },
18
+ "file": null
19
+ },
20
+ "layers": [
21
+ {
22
+ "id": 1,
23
+ "avatar": {
24
+ "id": 9889,
25
+ "name": "Elizabeth",
26
+ "preview": "https://cdn.spiritme.tech/media/avatars/previews/ec724f6e58a22d3ec9dd81fe825f3eb1ea2a99b6.png",
27
+ "frame_width": 1073,
28
+ "frame_height": 1177
29
+ },
30
+ "media": null,
31
+ "x": 0.5,
32
+ "y": 1,
33
+ "scale": 1,
34
+ "crop": null,
35
+ "view_type": "rectangular"
36
+ }
37
+ ],
38
+ "background": null
39
+ }
40
+ ],
41
+ "webhook": null,
42
+ "resolution": {
43
+ "width": 1920,
44
+ "height": 1080
45
+ },
46
+ "auto_emotions_markup": true,
47
+ "enable_subtitles": false,
48
+ "status": "success",
49
+ "result": "https://cdn.spiritme.tech/media/videos/3fa94ae367237676442cde44feacaf5c24875966.mp4",
50
+ "thumbnail": "https://cdn.spiritme.tech/media/videos/65dd50bc2b996b3457fcb4d98ce5c270bed54a6d.jpeg"
51
+ }
package/spiritme.app.mjs CHANGED
@@ -1,11 +1,131 @@
1
+ import { axios } from "@pipedream/platform";
2
+ const DEFAULT_LIMIT = 50;
3
+
1
4
  export default {
2
5
  type: "app",
3
6
  app: "spiritme",
4
- propDefinitions: {},
7
+ propDefinitions: {
8
+ avatar: {
9
+ type: "string",
10
+ label: "Avatar",
11
+ description: "The identifier for the avatar to be used. One of avatar or media is required.",
12
+ optional: true,
13
+ async options({ page }) {
14
+ const { results } = await this.listAvatars({
15
+ params: {
16
+ limit: DEFAULT_LIMIT,
17
+ offset: page * DEFAULT_LIMIT,
18
+ },
19
+ });
20
+ return results?.map(({
21
+ id: value, name: label,
22
+ }) => ({
23
+ value,
24
+ label,
25
+ })) || [];
26
+ },
27
+ },
28
+ voice: {
29
+ type: "string",
30
+ label: "Voice",
31
+ description: "The identifier of the voice to be used",
32
+ optional: true,
33
+ async options({ page }) {
34
+ const { results } = await this.listVoices({
35
+ params: {
36
+ limit: DEFAULT_LIMIT,
37
+ offset: page * DEFAULT_LIMIT,
38
+ },
39
+ });
40
+ return results?.map(({
41
+ id: value, name: label,
42
+ }) => ({
43
+ value,
44
+ label,
45
+ })) || [];
46
+ },
47
+ },
48
+ file: {
49
+ type: "string",
50
+ label: "Voice",
51
+ description: "The identifier of the file to be used",
52
+ optional: true,
53
+ async options({
54
+ page, type,
55
+ }) {
56
+ const { results } = await this.listFiles({
57
+ params: {
58
+ limit: DEFAULT_LIMIT,
59
+ offset: page * DEFAULT_LIMIT,
60
+ type,
61
+ },
62
+ });
63
+ return results?.map(({
64
+ id: value, name: label,
65
+ }) => ({
66
+ value,
67
+ label,
68
+ })) || [];
69
+ },
70
+ },
71
+ },
5
72
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
73
+ _baseUrl() {
74
+ return "https://api.spiritme.tech/api";
75
+ },
76
+ _makeRequest(opts = {}) {
77
+ const {
78
+ $ = this,
79
+ path,
80
+ ...otherOpts
81
+ } = opts;
82
+ return axios($, {
83
+ ...otherOpts,
84
+ url: `${this._baseUrl()}${path}`,
85
+ headers: {
86
+ Authorization: `Token ${this.$auth.api_key}`,
87
+ Accept: "application/json",
88
+ },
89
+ });
90
+ },
91
+ listAvatars(opts = {}) {
92
+ return this._makeRequest({
93
+ path: "/avatars/",
94
+ ...opts,
95
+ });
96
+ },
97
+ listVoices(opts = {}) {
98
+ return this._makeRequest({
99
+ path: "/tts/voices/",
100
+ ...opts,
101
+ });
102
+ },
103
+ listFiles(opts = {}) {
104
+ return this._makeRequest({
105
+ path: "/files/",
106
+ ...opts,
107
+ });
108
+ },
109
+ listVideos(opts = {}) {
110
+ return this._makeRequest({
111
+ path: "/videos/",
112
+ ...opts,
113
+ });
114
+ },
115
+ getVideo({
116
+ videoId, ...opts
117
+ }) {
118
+ return this._makeRequest({
119
+ path: `/videos/${videoId}/`,
120
+ ...opts,
121
+ });
122
+ },
123
+ generateVideo(opts = {}) {
124
+ return this._makeRequest({
125
+ method: "POST",
126
+ path: "/videos/",
127
+ ...opts,
128
+ });
9
129
  },
10
130
  },
11
- };
131
+ };