Spaces:
Runtime error
Runtime error
Commit
•
7ffb6c1
1
Parent(s):
2ac915f
Add new version
Browse files- classes/AppConfig.php +10 -3
- config/config.json +10 -2
- index.html +1 -0
- index.php +0 -1
- public/index-copy.php +1 -0
- public/index.php +24 -5
- public/logs/scene.log +0 -0
classes/AppConfig.php
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
declare(strict_types=1);
|
|
|
4 |
use Psr\Log\LoggerInterface;
|
5 |
|
6 |
class AppConfig
|
@@ -31,11 +32,17 @@ class AppConfig
|
|
31 |
public function getApiKey(string $className): string
|
32 |
{
|
33 |
if (!isset($this->config[$className])) {
|
34 |
-
$errorMessage = "API
|
35 |
$this->logger->error($errorMessage);
|
36 |
throw new \InvalidArgumentException($errorMessage);
|
37 |
}
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
-
}
|
|
|
1 |
<?php
|
2 |
|
3 |
declare(strict_types=1);
|
4 |
+
|
5 |
use Psr\Log\LoggerInterface;
|
6 |
|
7 |
class AppConfig
|
|
|
32 |
public function getApiKey(string $className): string
|
33 |
{
|
34 |
if (!isset($this->config[$className])) {
|
35 |
+
$errorMessage = "API keys not found for class {$className}.";
|
36 |
$this->logger->error($errorMessage);
|
37 |
throw new \InvalidArgumentException($errorMessage);
|
38 |
}
|
39 |
|
40 |
+
$keys = $this->config[$className];
|
41 |
+
$keyIndex = array_rand($keys);
|
42 |
+
$selectedKey = $keys[$keyIndex];
|
43 |
+
|
44 |
+
$this->logger->info("Using {$className} API key: {$selectedKey}");
|
45 |
+
|
46 |
+
return $selectedKey;
|
47 |
}
|
48 |
+
}
|
config/config.json
CHANGED
@@ -1,4 +1,12 @@
|
|
1 |
{
|
2 |
-
"ElevenLabsApi":
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
}
|
|
|
1 |
{
|
2 |
+
"ElevenLabsApi": [
|
3 |
+
"c6313218fbe0e41e721304370f8bf9e3",
|
4 |
+
"c6313218fbe0e41e721304370f8bf9e3",
|
5 |
+
"c6313218fbe0e41e721304370f8bf9e3"
|
6 |
+
],
|
7 |
+
"OpenAI": [
|
8 |
+
"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",
|
9 |
+
"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",
|
10 |
+
"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"
|
11 |
+
]
|
12 |
}
|
index.html
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
<a href="/public/">Welcome to Video Generator</a>
|
index.php
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<a href="public/">Welcome to Video Generator</a>
|
|
|
|
public/index-copy.php
CHANGED
@@ -21,6 +21,7 @@ $appConfig = new AppConfig($log);
|
|
21 |
$openaiApiKey = $appConfig->getApiKey('OpenAI');
|
22 |
$elevenLabsApiKey = $appConfig->getApiKey('ElevenLabsApi');
|
23 |
|
|
|
24 |
// Initialize OpenAI and ElevenLabsApi objects with the API keys and logger
|
25 |
$openai = new OpenAI($openaiApiKey, null, $log);
|
26 |
$elevenLabsApi = new ElevenLabsApi($elevenLabsApiKey, null, $log);
|
|
|
21 |
$openaiApiKey = $appConfig->getApiKey('OpenAI');
|
22 |
$elevenLabsApiKey = $appConfig->getApiKey('ElevenLabsApi');
|
23 |
|
24 |
+
|
25 |
// Initialize OpenAI and ElevenLabsApi objects with the API keys and logger
|
26 |
$openai = new OpenAI($openaiApiKey, null, $log);
|
27 |
$elevenLabsApi = new ElevenLabsApi($elevenLabsApiKey, null, $log);
|
public/index.php
CHANGED
@@ -21,6 +21,10 @@ $appConfig = new AppConfig($log);
|
|
21 |
$openaiApiKey = $appConfig->getApiKey('OpenAI');
|
22 |
$elevenLabsApiKey = $appConfig->getApiKey('ElevenLabsApi');
|
23 |
|
|
|
|
|
|
|
|
|
24 |
// Initialize OpenAI and ElevenLabsApi objects with the API keys and logger
|
25 |
$openai = new OpenAI($openaiApiKey, null, $log);
|
26 |
$elevenLabsApi = new ElevenLabsApi($elevenLabsApiKey, null, $log);
|
@@ -59,7 +63,7 @@ if (!file_exists($audio_file)) {
|
|
59 |
$log->info('Generating audio...');
|
60 |
$audio_data = [
|
61 |
'text' => $script,
|
62 |
-
'voiceId' => '
|
63 |
];
|
64 |
$audio_response = $elevenLabsApi->textToSpeechWithVoiceId($audio_data['voiceId'], $audio_data);
|
65 |
file_put_contents($audio_file, $audio_response->getBody());
|
@@ -189,18 +193,33 @@ $log->info('Data:', $log_data);
|
|
189 |
echo "Name is empty";
|
190 |
}
|
191 |
else {
|
|
|
192 |
$images_direct = str_replace('\\', '/', $images_dir);
|
193 |
$audio_direct = str_replace('\\', '/', $audio_file);
|
194 |
|
195 |
-
|
196 |
-
|
|
|
197 |
|
198 |
-
|
|
|
|
|
|
|
199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
if (file_exists('/var/www/html/public/output.mp4')) {
|
201 |
echo "Video generated successfully!"; ?>
|
202 |
<video width="540" height="260" controls>
|
203 |
-
<source src="output.mp4" type="video/mp4">
|
204 |
<!-- add additional source tags for other formats if needed -->
|
205 |
Your browser does not support the video tag.
|
206 |
</video>
|
|
|
21 |
$openaiApiKey = $appConfig->getApiKey('OpenAI');
|
22 |
$elevenLabsApiKey = $appConfig->getApiKey('ElevenLabsApi');
|
23 |
|
24 |
+
// echo "OpenAI API key: {$openaiApiKey}" . PHP_EOL;
|
25 |
+
// echo "ElevenLabsApi API key: {$elevenLabsApiKey}" . PHP_EOL;
|
26 |
+
|
27 |
+
|
28 |
// Initialize OpenAI and ElevenLabsApi objects with the API keys and logger
|
29 |
$openai = new OpenAI($openaiApiKey, null, $log);
|
30 |
$elevenLabsApi = new ElevenLabsApi($elevenLabsApiKey, null, $log);
|
|
|
63 |
$log->info('Generating audio...');
|
64 |
$audio_data = [
|
65 |
'text' => $script,
|
66 |
+
'voiceId' => 'AZnzlk1XvdvUeBnXmlld'
|
67 |
];
|
68 |
$audio_response = $elevenLabsApi->textToSpeechWithVoiceId($audio_data['voiceId'], $audio_data);
|
69 |
file_put_contents($audio_file, $audio_response->getBody());
|
|
|
193 |
echo "Name is empty";
|
194 |
}
|
195 |
else {
|
196 |
+
|
197 |
$images_direct = str_replace('\\', '/', $images_dir);
|
198 |
$audio_direct = str_replace('\\', '/', $audio_file);
|
199 |
|
200 |
+
// echo $images_direct;
|
201 |
+
// Get an array of all the files and directories inside the $images_dir directory
|
202 |
+
$dir_contents = scandir($images_direct);
|
203 |
|
204 |
+
// Remove the '.' and '..' entries from the array
|
205 |
+
$dir_contents = array_diff($dir_contents, array('.', '..'));
|
206 |
+
// print_r($dir_contents);
|
207 |
+
$dir_contents_str = '';
|
208 |
|
209 |
+
|
210 |
+
// echo $dir_contents_str;
|
211 |
+
$dir_contents_string = str_replace('C:/xampp/htdocs/proj/chatgpt-video-generator/public/', '', $dir_contents_str);
|
212 |
+
$audio_contents_string = str_replace('C:/xampp/htdocs/proj/chatgpt-video-generator/public/', '', $audio_direct);
|
213 |
+
// $img_path = $images_direct.'/*.png';
|
214 |
+
$img_path = '\'' . $images_direct . '/*.png\'';
|
215 |
+
// echo $img_path;
|
216 |
+
exec('ffmpeg -framerate 1/5 -pattern_type glob -i '.$img_path.' -i ' .$audio_contents_string. ' -filter_complex "[0:v]format=yuv420p[v]" -map "[v]" -map 1:a -c:v libx264 -c:a aac -shortest output.mp4');
|
217 |
+
// $cmd = 'ffmpeg -framerate 1/5 -pattern_type glob -i '.$img_path.' -i ' .$audio_contents_string. ' -filter_complex "[0:v]format=yuv420p[v]" -map "[v]" -map 1:a -c:v libx264 -c:a aac -shortest output.mp4';
|
218 |
+
// echo $cmd;
|
219 |
if (file_exists('/var/www/html/public/output.mp4')) {
|
220 |
echo "Video generated successfully!"; ?>
|
221 |
<video width="540" height="260" controls>
|
222 |
+
<source src="/var/www/html/public/output.mp4" type="video/mp4">
|
223 |
<!-- add additional source tags for other formats if needed -->
|
224 |
Your browser does not support the video tag.
|
225 |
</video>
|
public/logs/scene.log
CHANGED
The diff for this file is too large to render.
See raw diff
|
|