@revideo/create 0.5.8-alpha.1084 → 0.5.8-beta.1082

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.
Files changed (175) hide show
  1. package/package.json +9 -9
  2. package/examples/README.md +0 -43
  3. package/examples/avatar-with-background/package-lock.json +0 -3223
  4. package/examples/avatar-with-background/package.json +0 -26
  5. package/examples/avatar-with-background/src/project.meta +0 -31
  6. package/examples/avatar-with-background/src/project.ts +0 -6
  7. package/examples/avatar-with-background/src/render.ts +0 -14
  8. package/examples/avatar-with-background/src/revideo.d.ts +0 -1
  9. package/examples/avatar-with-background/src/scenes/example.meta +0 -5
  10. package/examples/avatar-with-background/src/scenes/example.tsx +0 -27
  11. package/examples/avatar-with-background/tsconfig.json +0 -9
  12. package/examples/avatar-with-background/vite.config.ts +0 -8
  13. package/examples/default/package.json +0 -24
  14. package/examples/default/src/project.meta +0 -31
  15. package/examples/default/src/project.ts +0 -7
  16. package/examples/default/src/render.ts +0 -15
  17. package/examples/default/src/revideo.d.ts +0 -1
  18. package/examples/default/src/scenes/example.tsx +0 -38
  19. package/examples/default/tsconfig.json +0 -9
  20. package/examples/default/vite.config.ts +0 -8
  21. package/examples/github-stars-celebration/package-lock.json +0 -3833
  22. package/examples/github-stars-celebration/package.json +0 -24
  23. package/examples/github-stars-celebration/src/global.css +0 -1
  24. package/examples/github-stars-celebration/src/project.meta +0 -28
  25. package/examples/github-stars-celebration/src/project.ts +0 -8
  26. package/examples/github-stars-celebration/src/render.ts +0 -15
  27. package/examples/github-stars-celebration/src/revideo.d.ts +0 -1
  28. package/examples/github-stars-celebration/src/scenes/example.meta +0 -5
  29. package/examples/github-stars-celebration/src/scenes/example.tsx +0 -51
  30. package/examples/github-stars-celebration/tsconfig.json +0 -9
  31. package/examples/github-stars-celebration/vite.config.ts +0 -8
  32. package/examples/google-cloud-run-parallelized/README.md +0 -127
  33. package/examples/google-cloud-run-parallelized/render-orchestrator/Dockerfile +0 -56
  34. package/examples/google-cloud-run-parallelized/render-orchestrator/package.json +0 -22
  35. package/examples/google-cloud-run-parallelized/render-orchestrator/src/index.ts +0 -72
  36. package/examples/google-cloud-run-parallelized/render-orchestrator/src/revideo.d.ts +0 -1
  37. package/examples/google-cloud-run-parallelized/render-orchestrator/tsconfig.json +0 -10
  38. package/examples/google-cloud-run-parallelized/render-worker/.gcloudignore +0 -17
  39. package/examples/google-cloud-run-parallelized/render-worker/.puppeteerrc.cjs +0 -9
  40. package/examples/google-cloud-run-parallelized/render-worker/package.json +0 -30
  41. package/examples/google-cloud-run-parallelized/render-worker/src/index.ts +0 -45
  42. package/examples/google-cloud-run-parallelized/render-worker/src/project.meta +0 -31
  43. package/examples/google-cloud-run-parallelized/render-worker/src/project.ts +0 -6
  44. package/examples/google-cloud-run-parallelized/render-worker/src/render.ts +0 -14
  45. package/examples/google-cloud-run-parallelized/render-worker/src/revideo.d.ts +0 -1
  46. package/examples/google-cloud-run-parallelized/render-worker/src/scenes/example.tsx +0 -30
  47. package/examples/google-cloud-run-parallelized/render-worker/tsconfig.json +0 -13
  48. package/examples/google-cloud-run-parallelized/render-worker/vite.config.ts +0 -9
  49. package/examples/logo.svg +0 -6
  50. package/examples/logo_dark.svg +0 -6
  51. package/examples/marketing-templates/README.md +0 -10
  52. package/examples/marketing-templates/marketing-template/package-lock.json +0 -3824
  53. package/examples/marketing-templates/marketing-template/package.json +0 -24
  54. package/examples/marketing-templates/marketing-template/src/globals.css +0 -0
  55. package/examples/marketing-templates/marketing-template/src/project.meta +0 -28
  56. package/examples/marketing-templates/marketing-template/src/project.ts +0 -9
  57. package/examples/marketing-templates/marketing-template/src/render.ts +0 -15
  58. package/examples/marketing-templates/marketing-template/src/revideo.d.ts +0 -1
  59. package/examples/marketing-templates/marketing-template/src/scenes/example.meta +0 -5
  60. package/examples/marketing-templates/marketing-template/src/scenes/example.tsx +0 -67
  61. package/examples/marketing-templates/marketing-template/tsconfig.json +0 -9
  62. package/examples/marketing-templates/marketing-template/vite.config.ts +0 -9
  63. package/examples/marketing-templates/multiple-videos-in-one/package-lock.json +0 -3824
  64. package/examples/marketing-templates/multiple-videos-in-one/package.json +0 -24
  65. package/examples/marketing-templates/multiple-videos-in-one/src/project.meta +0 -28
  66. package/examples/marketing-templates/multiple-videos-in-one/src/project.ts +0 -9
  67. package/examples/marketing-templates/multiple-videos-in-one/src/render.ts +0 -15
  68. package/examples/marketing-templates/multiple-videos-in-one/src/revideo.d.ts +0 -1
  69. package/examples/marketing-templates/multiple-videos-in-one/src/scenes/example.meta +0 -5
  70. package/examples/marketing-templates/multiple-videos-in-one/src/scenes/example.tsx +0 -122
  71. package/examples/marketing-templates/multiple-videos-in-one/tsconfig.json +0 -9
  72. package/examples/marketing-templates/multiple-videos-in-one/vite.config.ts +0 -9
  73. package/examples/parallelized-aws-lambda/.dockerignore +0 -3
  74. package/examples/parallelized-aws-lambda/Dockerfile +0 -21
  75. package/examples/parallelized-aws-lambda/Dockerfile.base +0 -64
  76. package/examples/parallelized-aws-lambda/README.md +0 -197
  77. package/examples/parallelized-aws-lambda/revideo-project/.puppeteerrc.cjs +0 -9
  78. package/examples/parallelized-aws-lambda/revideo-project/package-lock.json +0 -4133
  79. package/examples/parallelized-aws-lambda/revideo-project/package.json +0 -31
  80. package/examples/parallelized-aws-lambda/revideo-project/src/lambda.ts +0 -144
  81. package/examples/parallelized-aws-lambda/revideo-project/src/project.meta +0 -28
  82. package/examples/parallelized-aws-lambda/revideo-project/src/project.ts +0 -7
  83. package/examples/parallelized-aws-lambda/revideo-project/src/render.ts +0 -16
  84. package/examples/parallelized-aws-lambda/revideo-project/src/revideo.d.ts +0 -1
  85. package/examples/parallelized-aws-lambda/revideo-project/src/scenes/example.meta +0 -5
  86. package/examples/parallelized-aws-lambda/revideo-project/src/scenes/example.tsx +0 -29
  87. package/examples/parallelized-aws-lambda/revideo-project/tsconfig.json +0 -10
  88. package/examples/parallelized-aws-lambda/revideo-project/vite.config.ts +0 -9
  89. package/examples/reddit-post-video/README.md +0 -84
  90. package/examples/reddit-post-video/package-lock.json +0 -2941
  91. package/examples/reddit-post-video/package.json +0 -27
  92. package/examples/reddit-post-video/src/global.css +0 -1
  93. package/examples/reddit-post-video/src/metadata.json +0 -576
  94. package/examples/reddit-post-video/src/project.meta +0 -31
  95. package/examples/reddit-post-video/src/project.ts +0 -9
  96. package/examples/reddit-post-video/src/render.ts +0 -157
  97. package/examples/reddit-post-video/src/revideo.d.ts +0 -1
  98. package/examples/reddit-post-video/src/scenes/example.meta +0 -5
  99. package/examples/reddit-post-video/src/scenes/example.tsx +0 -74
  100. package/examples/reddit-post-video/tsconfig.json +0 -9
  101. package/examples/reddit-post-video/vite.config.ts +0 -6
  102. package/examples/rive-explanation-video/README.md +0 -9
  103. package/examples/rive-explanation-video/package-lock.json +0 -3706
  104. package/examples/rive-explanation-video/package.json +0 -25
  105. package/examples/rive-explanation-video/src/global.css +0 -1
  106. package/examples/rive-explanation-video/src/project.meta +0 -31
  107. package/examples/rive-explanation-video/src/project.ts +0 -8
  108. package/examples/rive-explanation-video/src/render.ts +0 -15
  109. package/examples/rive-explanation-video/src/revideo.d.ts +0 -1
  110. package/examples/rive-explanation-video/src/scenes/example.meta +0 -5
  111. package/examples/rive-explanation-video/src/scenes/example.tsx +0 -218
  112. package/examples/rive-explanation-video/tsconfig.json +0 -9
  113. package/examples/rive-explanation-video/vite.config.ts +0 -8
  114. package/examples/saas-template/.prettierrc +0 -9
  115. package/examples/saas-template/README.md +0 -28
  116. package/examples/saas-template/next/app/actions.tsx +0 -113
  117. package/examples/saas-template/next/app/api/render/route.ts +0 -22
  118. package/examples/saas-template/next/app/globals.css +0 -3
  119. package/examples/saas-template/next/app/layout.tsx +0 -25
  120. package/examples/saas-template/next/app/page.tsx +0 -187
  121. package/examples/saas-template/next/next.config.mjs +0 -4
  122. package/examples/saas-template/next/package.json +0 -34
  123. package/examples/saas-template/next/postcss.config.js +0 -6
  124. package/examples/saas-template/next/public/favicon.ico +0 -0
  125. package/examples/saas-template/next/public/next.svg +0 -1
  126. package/examples/saas-template/next/public/vercel.svg +0 -1
  127. package/examples/saas-template/next/tailwind.config.ts +0 -30
  128. package/examples/saas-template/next/tsconfig.json +0 -26
  129. package/examples/saas-template/next/utils/parse.ts +0 -35
  130. package/examples/saas-template/revideo/package.json +0 -24
  131. package/examples/saas-template/revideo/src/global.css +0 -1
  132. package/examples/saas-template/revideo/src/project.meta +0 -27
  133. package/examples/saas-template/revideo/src/project.ts +0 -9
  134. package/examples/saas-template/revideo/src/render.ts +0 -15
  135. package/examples/saas-template/revideo/src/revideo.d.ts +0 -1
  136. package/examples/saas-template/revideo/src/scenes/example.meta +0 -5
  137. package/examples/saas-template/revideo/src/scenes/example.tsx +0 -178
  138. package/examples/saas-template/revideo/tsconfig.json +0 -9
  139. package/examples/saas-template/revideo/vite.config.ts +0 -6
  140. package/examples/stitching-videos/README.md +0 -7
  141. package/examples/stitching-videos/package-lock.json +0 -2801
  142. package/examples/stitching-videos/package.json +0 -23
  143. package/examples/stitching-videos/src/project.meta +0 -28
  144. package/examples/stitching-videos/src/project.ts +0 -20
  145. package/examples/stitching-videos/src/render.ts +0 -26
  146. package/examples/stitching-videos/src/revideo.d.ts +0 -1
  147. package/examples/stitching-videos/src/scenes/example.tsx +0 -30
  148. package/examples/stitching-videos/tsconfig.json +0 -9
  149. package/examples/stitching-videos/vite.config.ts +0 -8
  150. package/examples/three-js-example/README.md +0 -8
  151. package/examples/three-js-example/package-lock.json +0 -2753
  152. package/examples/three-js-example/package.json +0 -25
  153. package/examples/three-js-example/src/components/Three.ts +0 -166
  154. package/examples/three-js-example/src/global.css +0 -1
  155. package/examples/three-js-example/src/project.meta +0 -31
  156. package/examples/three-js-example/src/project.ts +0 -8
  157. package/examples/three-js-example/src/render.ts +0 -15
  158. package/examples/three-js-example/src/revideo.d.ts +0 -1
  159. package/examples/three-js-example/src/scenes/basic3D.meta +0 -5
  160. package/examples/three-js-example/src/scenes/basic3D.tsx +0 -89
  161. package/examples/three-js-example/tsconfig.json +0 -9
  162. package/examples/three-js-example/vite.config.ts +0 -6
  163. package/examples/youtube-shorts/README.md +0 -65
  164. package/examples/youtube-shorts/package-lock.json +0 -3914
  165. package/examples/youtube-shorts/package.json +0 -30
  166. package/examples/youtube-shorts/src/global.css +0 -3
  167. package/examples/youtube-shorts/src/metadata.json +0 -635
  168. package/examples/youtube-shorts/src/project.meta +0 -28
  169. package/examples/youtube-shorts/src/project.ts +0 -9
  170. package/examples/youtube-shorts/src/render.ts +0 -43
  171. package/examples/youtube-shorts/src/revideo.d.ts +0 -1
  172. package/examples/youtube-shorts/src/scenes/example.tsx +0 -211
  173. package/examples/youtube-shorts/src/utils.ts +0 -123
  174. package/examples/youtube-shorts/tsconfig.json +0 -9
  175. package/examples/youtube-shorts/vite.config.ts +0 -8
@@ -1,43 +0,0 @@
1
- require('dotenv').config();
2
-
3
- import {renderVideo} from '@revideo/renderer';
4
- import metadata from './metadata.json';
5
- import { getVideoScript, generateAudio, getWordTimestamps, dalleGenerate, getImagePromptFromScript } from './utils';
6
- import { v4 as uuidv4 } from 'uuid';
7
- import * as fs from 'fs';
8
-
9
- async function createVideo(topic: string, voiceName: string){
10
- const jobId = uuidv4();
11
-
12
- console.log("Generating assets...")
13
- const script = await getVideoScript(topic);
14
- console.log("script", script);
15
-
16
- await generateAudio(script, voiceName, `./public/${jobId}-audio.wav`);
17
- const words = await getWordTimestamps(`./public/${jobId}-audio.wav`);
18
-
19
- console.log("Generating images...")
20
- const imagePromises = Array.from({ length: 5 }).map(async (_, index) => {
21
- const imagePrompt = await getImagePromptFromScript(script);
22
- await dalleGenerate(imagePrompt, `./public/${jobId}-image-${index}.png`);
23
- return `/${jobId}-image-${index}.png`;
24
- });
25
-
26
- const imageFileNames = await Promise.all(imagePromises);
27
- const metadata = {
28
- audioUrl: `${jobId}-audio.wav`,
29
- images: imageFileNames,
30
- words: words
31
- };
32
-
33
- await fs.promises.writeFile(`./public/${jobId}-metadata.json`, JSON.stringify(metadata, null, 2));
34
-
35
- console.log("Assets generated! Rendering video...")
36
- await renderVideo({
37
- projectFile: './src/project.ts',
38
- variables: metadata
39
- });
40
- console.log("Render finished");
41
- }
42
-
43
- createVideo("The moon landing", "Sarah");
@@ -1 +0,0 @@
1
- /// <reference types="@revideo/core/project" />
@@ -1,211 +0,0 @@
1
- import {Audio, Img, makeScene2D, Txt, View2D, Rect} from '@revideo/2d';
2
- import {all, createRef, waitFor, useScene, Reference, createSignal} from '@revideo/core';
3
-
4
- interface Word {
5
- punctuated_word: string;
6
- start: number;
7
- end: number;
8
- }
9
-
10
- interface captionSettings {
11
- fontSize: number;
12
- textColor: string;
13
- fontWeight: number;
14
- fontFamily: string;
15
- numSimultaneousWords: number;
16
- stream: boolean;
17
- textAlign: "center" | "left";
18
- textBoxWidthInPercent: number;
19
- borderColor?: string;
20
- borderWidth?: number;
21
- currentWordColor?: string;
22
- currentWordBackgroundColor?: string;
23
- shadowColor?: string;
24
- shadowBlur?: number;
25
- fadeInAnimation?: boolean;
26
- }
27
-
28
- const textSettings: captionSettings = {
29
- fontSize: 80,
30
- numSimultaneousWords: 4, // how many words are shown at most simultaneously
31
- textColor: "white",
32
- fontWeight: 800,
33
- fontFamily: "Mulish",
34
- stream: false, // if true, words appear one by one
35
- textAlign: "center",
36
- textBoxWidthInPercent: 70,
37
- fadeInAnimation: true,
38
- currentWordColor: "cyan",
39
- currentWordBackgroundColor: "red", // adds a colored box to the word currently spoken
40
- shadowColor: "black",
41
- shadowBlur: 30
42
- }
43
-
44
-
45
- export default makeScene2D(function* (view) {
46
- const images = useScene().variables.get('images', [])();
47
- const audioUrl = useScene().variables.get('audioUrl', 'none')();
48
- const words = useScene().variables.get('words', [])();
49
-
50
- const duration = words[words.length-1].end + 0.5;
51
-
52
- yield view.add(
53
- <>
54
- <Audio
55
- src={audioUrl}
56
- play={true}
57
- />
58
- <Audio
59
- src={"https://revideo-example-assets.s3.amazonaws.com/chill-beat-2.mp3"}
60
- play={true}
61
- volume={0.1}
62
- />
63
- </>
64
- );
65
-
66
- yield* all(
67
- displayImages(view, images, duration),
68
- displayWords(
69
- view,
70
- words,
71
- textSettings
72
- )
73
- )
74
- });
75
-
76
- function* displayImages(view: View2D, images: string[], totalDuration: number){
77
- for(const img of images){
78
- const ref = createRef<Img>();
79
- view.add(<Img
80
- src={img}
81
- size={["100%", "100%"]}
82
- ref={ref}
83
- zIndex={0}
84
- />
85
- )
86
- yield* waitFor(totalDuration/images.length);
87
- }
88
- }
89
-
90
- function* displayWords(view: View2D, words: Word[], settings: captionSettings){
91
- let waitBefore = words[0].start;
92
-
93
- for (let i = 0; i < words.length; i += settings.numSimultaneousWords) {
94
- const currentBatch = words.slice(i, i + settings.numSimultaneousWords);
95
- const nextClipStart =
96
- i < words.length - 1 ? words[i + settings.numSimultaneousWords]?.start || null : null;
97
- const isLastClip = i + settings.numSimultaneousWords >= words.length;
98
- const waitAfter = isLastClip ? 1 : 0;
99
- const textRef = createRef<Txt>();
100
- yield* waitFor(waitBefore);
101
-
102
- if(settings.stream){
103
- let nextWordStart = 0;
104
- yield view.add(<Txt width={`${settings.textBoxWidthInPercent}%`} textWrap={true} zIndex={2} textAlign={settings.textAlign} ref={textRef}/>);
105
-
106
- for(let j = 0; j < currentBatch.length; j++){
107
- const word = currentBatch[j];
108
- yield* waitFor(nextWordStart);
109
- const optionalSpace = j === currentBatch.length-1? "" : " ";
110
- const backgroundRef = createRef<Rect>();
111
- const wordRef = createRef<Txt>();
112
- const opacitySignal = createSignal(settings.fadeInAnimation ? 0.5 : 1);
113
- textRef().add(
114
- <Txt
115
- fontSize={settings.fontSize}
116
- fontWeight={settings.fontWeight}
117
- fontFamily={settings.fontFamily}
118
- textWrap={true}
119
- textAlign={settings.textAlign}
120
- fill={settings.currentWordColor}
121
- ref={wordRef}
122
- lineWidth={settings.borderWidth}
123
- shadowBlur={settings.shadowBlur}
124
- shadowColor={settings.shadowColor}
125
- zIndex={2}
126
- stroke={settings.borderColor}
127
- opacity={opacitySignal}
128
- >
129
- {word.punctuated_word}
130
- </Txt>
131
- );
132
- textRef().add(<Txt fontSize={settings.fontSize}>{optionalSpace}</Txt>);
133
- view.add(<Rect fill={settings.currentWordBackgroundColor} zIndex={1} size={wordRef().size} position={wordRef().position} radius={10} padding={10} ref={backgroundRef} />);
134
- yield* all(waitFor(word.end-word.start), opacitySignal(1, Math.min((word.end-word.start)*0.5, 0.1)));
135
- wordRef().fill(settings.textColor);
136
- backgroundRef().remove();
137
- nextWordStart = currentBatch[j+1]?.start - word.end || 0;
138
- }
139
- textRef().remove();
140
-
141
- } else {
142
- yield view.add(<Txt width={`${settings.textBoxWidthInPercent}%`} textAlign={settings.textAlign} ref={textRef} textWrap={true} zIndex={2}/>);
143
-
144
- const wordRefs = [];
145
- const opacitySignal = createSignal(settings.fadeInAnimation ? 0.5 : 1);
146
- for(let j = 0; j < currentBatch.length; j++){
147
- const word = currentBatch[j];
148
- const optionalSpace = j === currentBatch.length-1? "" : " ";
149
- const wordRef = createRef<Txt>();
150
- textRef().add(
151
- <Txt
152
- fontSize={settings.fontSize}
153
- fontWeight={settings.fontWeight}
154
- ref={wordRef}
155
- fontFamily={settings.fontFamily}
156
- textWrap={true}
157
- textAlign={settings.textAlign}
158
- fill={settings.textColor}
159
- zIndex={2}
160
- stroke={settings.borderColor}
161
- lineWidth={settings.borderWidth}
162
- shadowBlur={settings.shadowBlur}
163
- shadowColor={settings.shadowColor}
164
- opacity={opacitySignal}
165
- >
166
- {word.punctuated_word}
167
- </Txt>
168
- );
169
- textRef().add(<Txt fontSize={settings.fontSize}>{optionalSpace}</Txt>);
170
-
171
- // we have to yield once to await the first word being aligned correctly
172
- if(j===0 && i === 0){
173
- yield;
174
- }
175
- wordRefs.push(wordRef);
176
- }
177
-
178
- yield* all(
179
- opacitySignal(1, Math.min(0.1, (currentBatch[0].end-currentBatch[0].start)*0.5)),
180
- highlightCurrentWord(view, currentBatch, wordRefs, settings.currentWordColor, settings.currentWordBackgroundColor),
181
- waitFor(currentBatch[currentBatch.length-1].end - currentBatch[0].start + waitAfter),
182
- );
183
- textRef().remove();
184
- }
185
- waitBefore = nextClipStart !== null ? nextClipStart - currentBatch[currentBatch.length-1].end : 0;
186
- }
187
- }
188
-
189
- function* highlightCurrentWord(view: View2D, currentBatch: Word[], wordRefs: Reference<Txt>[], wordColor: string, backgroundColor: string){
190
- let nextWordStart = 0;
191
-
192
- for(let i = 0; i < currentBatch.length; i++){
193
- yield* waitFor(nextWordStart);
194
- const word = currentBatch[i];
195
- const originalColor = wordRefs[i]().fill();
196
- nextWordStart = currentBatch[i+1]?.start - word.end || 0;
197
- wordRefs[i]().fill(wordColor);
198
-
199
- const backgroundRef = createRef<Rect>();
200
- if(backgroundColor){
201
- view.add(<Rect fill={backgroundColor} zIndex={1} size={wordRefs[i]().size} position={wordRefs[i]().position} radius={10} padding={10} ref={backgroundRef} />);
202
- }
203
-
204
- yield* waitFor(word.end-word.start);
205
- wordRefs[i]().fill(originalColor);
206
-
207
- if(backgroundColor){
208
- backgroundRef().remove();
209
- }
210
- }
211
- }
@@ -1,123 +0,0 @@
1
- import OpenAI from 'openai';
2
- import axios from "axios";
3
- import * as fs from "fs";
4
- import { createClient } from "@deepgram/sdk";
5
-
6
- const deepgram = createClient(process.env["DEEPGRAM_API_KEY"] || "");
7
- const openai = new OpenAI({
8
- apiKey: process.env['OPENAI_API_KEY'],
9
- });
10
-
11
- export async function getWordTimestamps(audioFilePath: string){
12
- const {result} = await deepgram.listen.prerecorded.transcribeFile(fs.readFileSync(audioFilePath), {
13
- model: "nova-2",
14
- smart_format: true,
15
- });
16
-
17
- if (result) {
18
- return result.results.channels[0].alternatives[0].words;
19
- } else {
20
- throw Error("transcription result is null");
21
- }
22
-
23
- }
24
-
25
- export async function generateAudio(text: string, voiceName: string, savePath: string) {
26
- const data = {
27
- model_id: "eleven_multilingual_v2",
28
- text: text,
29
- };
30
-
31
- const voiceId = await getVoiceByName(voiceName);
32
-
33
- const response = await axios.post(`https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`, data, {
34
- headers: {
35
- "Content-Type": "application/json",
36
- "xi-api-key": process.env.ELEVEN_API_KEY || "",
37
- },
38
- responseType: "arraybuffer",
39
- });
40
-
41
- fs.writeFileSync(savePath, response.data);
42
- }
43
-
44
- async function getVoiceByName(name: string) {
45
- const response = await fetch("https://api.elevenlabs.io/v1/voices", {
46
- method: "GET",
47
- headers: {
48
- "xi-api-key": process.env.ELEVEN_API_KEY || "",
49
- },
50
- });
51
-
52
- if (!response.ok) {
53
- throw new Error(`HTTP error! status: ${response.status}`);
54
- }
55
-
56
- const data: any = await response.json();
57
- const voice = data.voices.find((voice: {name: string; voice_id: string}) => voice.name === name);
58
- return voice ? voice.voice_id : null;
59
- }
60
-
61
- export async function getVideoScript(videoTopic: string) {
62
- const prompt = `Create a script for a youtube short. The script should be around 60 to 80 words long and be an interesting text about the provided topic, and it should start with a catchy headline, something like "Did you know that?" or "This will blow your mind". Remember that this is for a voiceover that should be read, so things like hashtags should not be included. Now write the script for the following topic: "${videoTopic}". Now return the script and nothing else, also no meta-information - ONLY THE VOICEOVER.`;
63
-
64
- const chatCompletion = await openai.chat.completions.create({
65
- messages: [{ role: 'user', content: prompt }],
66
- model: 'gpt-4-turbo-preview',
67
- });
68
-
69
- const result = chatCompletion.choices[0].message.content;
70
-
71
- if (result) {
72
- return result;
73
- } else {
74
- throw Error("returned text is null");
75
- }
76
-
77
- }
78
-
79
- export async function getImagePromptFromScript(script: string) {
80
- const prompt = `My goal is to create a Youtube Short based on the following script. To create a background image for the video, I am using a text-to-video AI model. Please write a short (not longer than a single sentence), suitable prompt for such a model based on this script: ${script}.\n\nNow return the prompt and nothing else.`;
81
-
82
- const chatCompletion = await openai.chat.completions.create({
83
- messages: [{ role: 'user', content: prompt }],
84
- model: 'gpt-4-turbo-preview',
85
- temperature: 1.0 // high temperature for "creativeness"
86
- });
87
-
88
- const result = chatCompletion.choices[0].message.content;
89
-
90
- if (result) {
91
- return result;
92
- } else {
93
- throw Error("returned text is null");
94
- }
95
-
96
- }
97
-
98
- export async function dalleGenerate(prompt: string, savePath: string) {
99
- const response = await openai.images.generate({
100
- model: "dall-e-3",
101
- prompt: prompt,
102
- size: "1024x1792",
103
- quality: "standard",
104
- n: 1,
105
- });
106
-
107
- if (!response.data || !response.data[0]) {
108
- throw new Error("No image generated");
109
- }
110
-
111
- const url = response.data[0].url;
112
- const responseImage = await axios.get(url || "", {
113
- responseType: "arraybuffer",
114
- });
115
- const buffer = Buffer.from(responseImage.data, "binary");
116
-
117
- try {
118
- await fs.promises.writeFile(savePath, buffer);
119
- } catch (error) {
120
- console.error("Error saving the file:", error);
121
- throw error; // Rethrow the error so it can be handled by the caller
122
- }
123
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "@revideo/2d/tsconfig.project.json",
3
- "include": ["src"],
4
- "compilerOptions": {
5
- "noEmit": false,
6
- "outDir": "dist",
7
- "module": "CommonJS"
8
- }
9
- }
@@ -1,8 +0,0 @@
1
- import {defineConfig} from 'vite';
2
- import motionCanvas from '@revideo/vite-plugin';
3
-
4
- export default defineConfig({
5
- plugins: [
6
- motionCanvas()
7
- ],
8
- });