Skip to content

Commit

Permalink
generate changes to work with neets
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgsolomon committed Oct 28, 2024
1 parent 266a021 commit 6650a7b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 161 deletions.
54 changes: 25 additions & 29 deletions generate/eleven.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export async function generateTranscriptAudio(
duration,
background,
music,
videoId,
videoId
) {
if (!local) {
await query(
"UPDATE `pending-videos` SET status = 'Generating transcript', progress = 0 WHERE video_id = ?",
[videoId],
[videoId]
);
}

Expand All @@ -40,21 +40,21 @@ export async function generateTranscriptAudio(
if (!local) {
await query(
"UPDATE `pending-videos` SET status = 'Fetching images', progress = 5 WHERE video_id = ?",
[videoId],
[videoId]
);
}

const images = await fetchValidImages(
transcript,
transcript.length,
ai,
duration,
duration
);

if (!local) {
await query(
"UPDATE `pending-videos` SET status = 'Generating audio', progress = 12 WHERE video_id = ?",
[videoId],
[videoId]
);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ export const music: string = ${
export const fps = ${fps};
export const initialAgentName = '${initialAgentName}';
export const videoFileName = '/background/${background}-' + ${Math.floor(
Math.random() * 10,
Math.random() * 10
)} + '.mp4';
export const subtitlesFileName = [
${audios
Expand All @@ -113,7 +113,7 @@ export const subtitlesFileName = [
name: '${entry.person}',
file: staticFile('srt/${entry.person}-${i}.srt'),
asset: '${entry.image}',
}`,
}`
)
.join(',\n ')}
];
Expand All @@ -124,32 +124,28 @@ export const subtitlesFileName = [
return { audios, transcript };
}

export async function generateAudio(voice_id, person, line, index) {
const response = await fetch(
`https://api.elevenlabs.io/v1/text-to-speech/${voice_id}`,
{
method: 'POST',
headers: {
'xi-api-key': process.env.ELEVEN_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model_id: 'eleven_multilingual_v2',
text: line,
voice_settings: {
stability: 0.5,
similarity_boost: 0.75,
},
}),
async function generateAudio(voice_id, person, line, index) {
const response = await fetch('https://api.neets.ai/v1/tts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.NEETS_API_KEY,
},
);
body: JSON.stringify({
text: line,
voice_id: voice_id,
params: {
model: 'ar-diff-50k',
},
}),
});

if (!response.ok) {
throw new Error(`Server responded with status code ${response.status}`);
}

const audioStream = fs.createWriteStream(
`public/voice/${person}-${index}.mp3`,
`public/voice/${person}-${index}.mp3`
);
response.body.pipe(audioStream);

Expand Down Expand Up @@ -177,14 +173,14 @@ async function fetchValidImages(transcript, length, ai, duration) {
for (let i = 0; i < length; i++) {
const imageFetch = await fetch(
`https://www.googleapis.com/customsearch/v1?q=${encodeURI(
transcript[i].asset,
transcript[i].asset
)}&cx=${process.env.GOOGLE_CX}&searchType=image&key=${
process.env.GOOGLE_API_KEY
}&num=${4}`,
{
method: 'GET',
headers: { 'Content-Type': 'application/json' },
},
}
);
const imageResponse = await imageFetch.json();

Expand All @@ -195,7 +191,7 @@ async function fetchValidImages(transcript, length, ai, duration) {
) {
console.log(
'No images found or items not iterable',
imageResponse.items,
imageResponse.items
);
images.push({ link: 'https://images.smart.wtf/black.png' });
continue; // Skip to the next iteration
Expand Down
14 changes: 7 additions & 7 deletions generate/localBuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ async function cleanupResources() {
}

const agents = [
'BARACK_OBAMA',
'BEN_SHAPIRO',
// 'BARACK_OBAMA',
// 'BEN_SHAPIRO',
'JORDAN_PETERSON',
'JOE_ROGAN',
'DONALD_TRUMP',
'MARK_ZUCKERBERG',
'JOE_BIDEN',
'LIL_YACHTY',
// 'DONALD_TRUMP',
// 'MARK_ZUCKERBERG',
// 'JOE_BIDEN',
// 'LIL_YACHTY',
// 'RICK_SANCHEZ',
];

Expand All @@ -48,7 +48,7 @@ async function main() {

// CHANGE THIS VALUE FOR YOUR CHOICE OF AGENTS
const agentA = agents[0];
const agentB = agents[4];
const agentB = agents[1];

// CHANGE THIS VALUE FOR A CUSTOM VIDEO TOPIC
const videoTopic = 'Proximal Policy Optimization';
Expand Down
49 changes: 0 additions & 49 deletions generate/makeaudio.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion generate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/fluent-ffmpeg": "^2.1.24",
"audioconcat": "^0.1.4",
"fluent-ffmpeg": "^2.1.2",
"groq-sdk": "^0.3.3",
"groq-sdk": "^0.7.0",
"mysql2": "^3.9.1",
"openai": "^4.46.1",
"parse-srt": "1.0.0-alpha",
Expand Down
36 changes: 0 additions & 36 deletions generate/poll.mjs

This file was deleted.

38 changes: 0 additions & 38 deletions generate/render.mjs

This file was deleted.

1 change: 1 addition & 0 deletions generate/transcribe.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const transcribeAudio = async (audios) => {
}

const data = await response.json();
console.log('Data:', JSON.stringify(data, null, 2));
return data;
} catch (error) {
console.error(
Expand Down
1 change: 0 additions & 1 deletion rebuild.txt

This file was deleted.

0 comments on commit 6650a7b

Please sign in to comment.