-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_video_examples.py
More file actions
executable file
Β·211 lines (182 loc) Β· 7.21 KB
/
audio_video_examples.py
File metadata and controls
executable file
Β·211 lines (182 loc) Β· 7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python3
"""
Audio + Video Generation Examples
This script demonstrates the complete multimedia generation pipeline:
1. Generate image from text prompt (DALL-E)
2. Create video animation from image (Runway)
3. Generate audio narration (OpenAI TTS)
The result is a complete multimedia experience with synchronized content.
"""
import json
import requests
import time
from pathlib import Path
API_BASE_URL = "http://localhost:8000"
def test_prompt_to_multimedia():
"""Test complete prompt-to-multimedia generation."""
print("π¨β‘οΈπ¬ποΈ Complete Multimedia Generation Test")
print("=" * 60)
print()
examples = [
{
"name": "Peaceful Nature Scene",
"image_prompt": "A serene mountain lake surrounded by pine trees at golden hour",
"video_prompt": "Gentle ripples on the water surface with soft morning light filtering through trees",
"voice_type": "nova",
"style": "descriptive"
},
{
"name": "Ocean Meditation",
"image_prompt": "A peaceful beach with gentle waves and sunset colors in the sky",
"video_prompt": "Soft waves washing onto shore with seabirds flying in the distance",
"voice_type": "shimmer",
"style": "meditative"
},
{
"name": "Forest Adventure",
"image_prompt": "A mystical forest path with sunbeams shining through tall trees",
"video_prompt": "Leaves gently swaying in the breeze with magical light dancing",
"voice_type": "fable",
"style": "poetic"
},
{
"name": "Educational Nature",
"image_prompt": "A diverse ecosystem with mountains, forests, and a flowing river",
"video_prompt": "Natural processes showing the interconnection of water, plants, and landscape",
"voice_type": "onyx",
"style": "educational"
}
]
for i, example in enumerate(examples, 1):
print(f"π¬ Example {i}: {example['name']}")
print(f" Image: {example['image_prompt']}")
print(f" Video: {example['video_prompt']}")
print(f" Voice: {example['voice_type']} ({example['style']} style)")
print()
# Test this example
payload = {
"image_prompt": example["image_prompt"],
"video_prompt": example["video_prompt"],
"ratio": "1280:720",
"duration": 5,
"voice_type": example["voice_type"],
"style": example["style"]
}
try:
print(f" π Generating multimedia content...")
start_time = time.time()
response = requests.post(
f"{API_BASE_URL}/generate-video-from-prompt",
json=payload,
timeout=180 # 3 minutes for complete generation
)
processing_time = time.time() - start_time
if response.status_code == 200:
result = response.json()
print(f" β
SUCCESS! ({processing_time:.1f}s total)")
print(f" π¬ Video: {result.get('video_url', 'N/A')}")
if result.get('has_audio', False):
print(f" ποΈ Audio: Generated with {result.get('voice_type')} voice")
print(f" π Style: {result.get('narration_style')}")
print(f" π File: {result.get('audio_file', 'N/A')}")
print(" π COMPLETE MULTIMEDIA PACKAGE!")
else:
print(" π½οΈ Video only (audio generation skipped)")
# Save result
timestamp = time.strftime("%Y%m%d_%H%M%S")
filename = f"multimedia_result_{example['name'].lower().replace(' ', '_')}_{timestamp}.json"
with open(filename, 'w') as f:
json.dump(result, f, indent=2)
print(f" πΎ Saved to: {filename}")
else:
print(f" β Failed: HTTP {response.status_code}")
print(f" π Response: {response.text}")
except requests.exceptions.Timeout:
print(f" β° Timeout after 3 minutes")
except Exception as e:
print(f" β Error: {e}")
print()
# Small delay between examples
if i < len(examples):
print(" βΈοΈ Waiting 10 seconds before next example...")
time.sleep(10)
print()
def generate_curl_examples():
"""Generate CURL examples for multimedia generation."""
print("π CURL Examples for Multimedia Generation")
print("=" * 50)
print()
examples = [
{
"name": "Descriptive Nature",
"curl": f'''curl -X POST "{API_BASE_URL}/generate-video-from-prompt" \\
-H "Content-Type: application/json" \\
-d '{{
"image_prompt": "A serene mountain lake surrounded by pine trees at golden hour",
"video_prompt": "Gentle ripples on the water with soft morning light",
"ratio": "1280:720",
"duration": 5,
"voice_type": "nova",
"style": "descriptive"
}}\''''
},
{
"name": "Meditative Ocean",
"curl": f'''curl -X POST "{API_BASE_URL}/generate-video-from-prompt" \\
-H "Content-Type: application/json" \\
-d '{{
"image_prompt": "A peaceful beach with gentle waves at sunset",
"video_prompt": "Soft waves washing onto shore with seabirds flying",
"ratio": "1280:720",
"duration": 10,
"voice_type": "shimmer",
"style": "meditative"
}}\''''
},
{
"name": "Poetic Forest",
"curl": f'''curl -X POST "{API_BASE_URL}/generate-video-from-prompt" \\
-H "Content-Type: application/json" \\
-d '{{
"image_prompt": "A mystical forest path with sunbeams through trees",
"video_prompt": "Leaves swaying with magical light dancing",
"ratio": "1024:1024",
"duration": 5,
"voice_type": "fable",
"style": "poetic"
}}\''''
}
]
for example in examples:
print(f"# {example['name']}")
print(example['curl'])
print()
def main():
"""Main function."""
print("π¬ AI Multimedia Generation Test Suite")
print("Create complete video experiences with AI-generated:")
print(" π¨ Images (DALL-E)")
print(" π¬ Videos (Runway)")
print(" ποΈ Audio Narration (OpenAI TTS)")
print()
# Test multimedia generation
test_prompt_to_multimedia()
# Generate CURL examples
generate_curl_examples()
print("π Multimedia generation test complete!")
print()
print("π‘ Available Voice Types:")
print(" - alloy: Balanced voice, suitable for most content")
print(" - echo: Warm, friendly voice")
print(" - fable: Storytelling voice with character")
print(" - onyx: Deep, authoritative voice")
print(" - nova: Bright, energetic voice")
print(" - shimmer: Soft, gentle voice")
print()
print("π¨ Available Styles:")
print(" - descriptive: Detailed scene description")
print(" - poetic: Artistic, flowing narration")
print(" - educational: Informative, explanatory")
print(" - meditative: Calming, peaceful guidance")
if __name__ == "__main__":
main()