commit
ba1ad1fcdf
@ -9,12 +9,13 @@ export async function POST(req: NextRequest) {
|
|||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
try {
|
try {
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
const { prompt, tags, title, make_instrumental, model, wait_audio } = body;
|
const { prompt, tags, title, make_instrumental, model, wait_audio, negative_tags } = body;
|
||||||
const audioInfo = await (await sunoApi).custom_generate(
|
const audioInfo = await (await sunoApi).custom_generate(
|
||||||
prompt, tags, title,
|
prompt, tags, title,
|
||||||
Boolean(make_instrumental),
|
Boolean(make_instrumental),
|
||||||
model || DEFAULT_MODEL,
|
model || DEFAULT_MODEL,
|
||||||
Boolean(wait_audio)
|
Boolean(wait_audio),
|
||||||
|
negative_tags
|
||||||
);
|
);
|
||||||
return new NextResponse(JSON.stringify(audioInfo), {
|
return new NextResponse(JSON.stringify(audioInfo), {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
@ -138,6 +138,11 @@
|
|||||||
"description": "Music genre",
|
"description": "Music genre",
|
||||||
"example": "pop metal male melancholic"
|
"example": "pop metal male melancholic"
|
||||||
},
|
},
|
||||||
|
"negative_tags": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Negative Music genre",
|
||||||
|
"example": "female edm techno"
|
||||||
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Music title",
|
"description": "Music title",
|
||||||
|
@ -23,6 +23,7 @@ export interface AudioInfo {
|
|||||||
status: string; // Status
|
status: string; // Status
|
||||||
type?: string;
|
type?: string;
|
||||||
tags?: string; // Genre of music.
|
tags?: string; // Genre of music.
|
||||||
|
negative_tags?: string; // Negative tags of music.
|
||||||
duration?: string; // Duration of the audio
|
duration?: string; // Duration of the audio
|
||||||
error_message?: string; // Error message if any
|
error_message?: string; // Error message if any
|
||||||
}
|
}
|
||||||
@ -150,23 +151,25 @@ class SunoApi {
|
|||||||
* @param title The title for the generated audio.
|
* @param title The title for the generated audio.
|
||||||
* @param make_instrumental Indicates if the generated audio should be instrumental.
|
* @param make_instrumental Indicates if the generated audio should be instrumental.
|
||||||
* @param wait_audio Indicates if the method should wait for the audio file to be fully generated before returning.
|
* @param wait_audio Indicates if the method should wait for the audio file to be fully generated before returning.
|
||||||
|
* @param negative_tags Negative tags that should not be included in the generated audio.
|
||||||
* @returns A promise that resolves to an array of AudioInfo objects representing the generated audios.
|
* @returns A promise that resolves to an array of AudioInfo objects representing the generated audios.
|
||||||
*/
|
*/
|
||||||
public async custom_generate(
|
public async custom_generate(
|
||||||
prompt: string,
|
prompt: string,
|
||||||
tags: string,
|
tags: string,
|
||||||
title: string,
|
title: string,
|
||||||
make_instrumental: boolean = false,
|
make_instrumental: boolean = false,
|
||||||
model?: string,
|
model?: string,
|
||||||
wait_audio: boolean = false,
|
wait_audio: boolean = false,
|
||||||
): Promise<AudioInfo[]> {
|
negative_tags?: string,
|
||||||
|
): Promise<AudioInfo[]> {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
const audios = await this.generateSongs(prompt, true, tags, title, make_instrumental, model, wait_audio);
|
const audios = await this.generateSongs(prompt, true, tags, title, make_instrumental, model, wait_audio, negative_tags);
|
||||||
const costTime = Date.now() - startTime;
|
const costTime = Date.now() - startTime;
|
||||||
logger.info("Custom Generate Response:\n" + JSON.stringify(audios, null, 2));
|
logger.info("Custom Generate Response:\n" + JSON.stringify(audios, null, 2));
|
||||||
logger.info("Cost time: " + costTime);
|
logger.info("Cost time: " + costTime);
|
||||||
return audios;
|
return audios;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates songs based on the provided parameters.
|
* Generates songs based on the provided parameters.
|
||||||
@ -177,6 +180,7 @@ class SunoApi {
|
|||||||
* @param title Optional title for the song, used only if isCustom is true.
|
* @param title Optional title for the song, used only if isCustom is true.
|
||||||
* @param make_instrumental Indicates if the generated song should be instrumental.
|
* @param make_instrumental Indicates if the generated song should be instrumental.
|
||||||
* @param wait_audio Indicates if the method should wait for the audio file to be fully generated before returning.
|
* @param wait_audio Indicates if the method should wait for the audio file to be fully generated before returning.
|
||||||
|
* @param negative_tags Negative tags that should not be included in the generated audio.
|
||||||
* @returns A promise that resolves to an array of AudioInfo objects representing the generated songs.
|
* @returns A promise that resolves to an array of AudioInfo objects representing the generated songs.
|
||||||
*/
|
*/
|
||||||
private async generateSongs(
|
private async generateSongs(
|
||||||
@ -186,7 +190,8 @@ class SunoApi {
|
|||||||
title?: string,
|
title?: string,
|
||||||
make_instrumental?: boolean,
|
make_instrumental?: boolean,
|
||||||
model?: string,
|
model?: string,
|
||||||
wait_audio: boolean = false
|
wait_audio: boolean = false,
|
||||||
|
negative_tags?: string,
|
||||||
): Promise<AudioInfo[]> {
|
): Promise<AudioInfo[]> {
|
||||||
await this.keepAlive(false);
|
await this.keepAlive(false);
|
||||||
const payload: any = {
|
const payload: any = {
|
||||||
@ -197,6 +202,7 @@ class SunoApi {
|
|||||||
if (isCustom) {
|
if (isCustom) {
|
||||||
payload.tags = tags;
|
payload.tags = tags;
|
||||||
payload.title = title;
|
payload.title = title;
|
||||||
|
payload.negative_tags = negative_tags;
|
||||||
payload.prompt = prompt;
|
payload.prompt = prompt;
|
||||||
} else {
|
} else {
|
||||||
payload.gpt_description_prompt = prompt;
|
payload.gpt_description_prompt = prompt;
|
||||||
@ -208,6 +214,7 @@ class SunoApi {
|
|||||||
title: title,
|
title: title,
|
||||||
make_instrumental: make_instrumental,
|
make_instrumental: make_instrumental,
|
||||||
wait_audio: wait_audio,
|
wait_audio: wait_audio,
|
||||||
|
negative_tags: negative_tags,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
}, null, 2));
|
}, null, 2));
|
||||||
const response = await this.client.post(
|
const response = await this.client.post(
|
||||||
@ -259,6 +266,7 @@ class SunoApi {
|
|||||||
prompt: audio.metadata.prompt,
|
prompt: audio.metadata.prompt,
|
||||||
type: audio.metadata.type,
|
type: audio.metadata.type,
|
||||||
tags: audio.metadata.tags,
|
tags: audio.metadata.tags,
|
||||||
|
negative_tags: audio.metadata.negative_tags,
|
||||||
duration: audio.metadata.duration,
|
duration: audio.metadata.duration,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user