-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudioGeneration.js
More file actions
35 lines (30 loc) · 1.14 KB
/
audioGeneration.js
File metadata and controls
35 lines (30 loc) · 1.14 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
const fetch = require('node-fetch');
async function generateAudio(text, genre) {
const finalText = "Make a " + genre + " song about " + text;
try {
const response = await fetch("https://studio-api.suno.ai/api/external/generate/", {
method: "POST",
headers: {
"authorization": `Bearer ${process.env.SUNO_API_KEY}`,
"content-type": "application/json"
},
body: JSON.stringify({
topic: finalText,
tags: genre
})
});
if (!response.ok) {
const errorBody = await response.text();
console.error(`API response not OK. Status: ${response.status}, Body: ${errorBody}`);
throw new Error(`Failed to generate audio. Status: ${response.status}`);
}
const data = await response.json();
const song_uuid = data["id"];
const cdn_link = "https://cdn1.suno.ai/" + song_uuid + ".mp3";
return cdn_link;
} catch (error) {
console.error("Error in generateAudio:", error);
throw error;
}
}
module.exports = { generateAudio };