veo 3
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
// Replace with your actual API keys
const TTS_API_KEY = 'your-google-tts-key';
const VIDEO_API_KEY = 'your-video-api-key';
app.post('/generate-video', async (req, res) => {
try {
// Step 1: Generate audio from text
const ttsResponse = await axios.post(
'https://texttospeech.googleapis.com/v1/text:synthesize',
{
input: { text: req.body.script },
voice: { languageCode: 'en-US', name: req.body.voice },
audioConfig: { audioEncoding: 'MP3' }
},
{ params: { key: TTS_API_KEY } }
);
// Step 2: Generate video with audio
const videoResponse = await axios.post(
'https://api.synthesia.io/v2/videos',
{
test: false,
input: [
{
scriptText: req.body.script,
avatar: "anna_costume1_cameraA",
background: "green_screen",
audio: ttsResponse.data.audioContent
}
]
},
{ headers: { Authorization: VIDEO_API_KEY } }
);
res.json({ videoUrl: videoResponse.data.downloadUrl });
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Video generation failed' });
}
});
app.listen(3000, () => console.log('Proxy server running'));
Comments
Post a Comment