* Generates songs based on the provided parameters. * * @param prompt The text prompt to generate songs from. * @param isCustom Indicates if the generation should consider custom parameters like tags and title. * @param tags Optional tags to categorize the song, used only if isCustom is
(
prompt: string,
isCustom: boolean,
tags?: string,
title?: string,
make_instrumental?: boolean,
model?: string,
wait_audio: boolean = false,
negative_tags?: string,
task?: string,
continue_clip_id?: string,
continue_at?: number
)
| 545 | * @returns A promise that resolves to an array of AudioInfo objects representing the generated songs. |
| 546 | */ |
| 547 | private async generateSongs( |
| 548 | prompt: string, |
| 549 | isCustom: boolean, |
| 550 | tags?: string, |
| 551 | title?: string, |
| 552 | make_instrumental?: boolean, |
| 553 | model?: string, |
| 554 | wait_audio: boolean = false, |
| 555 | negative_tags?: string, |
| 556 | task?: string, |
| 557 | continue_clip_id?: string, |
| 558 | continue_at?: number |
| 559 | ): Promise<AudioInfo[]> { |
| 560 | await this.keepAlive(); |
| 561 | const payload: any = { |
| 562 | make_instrumental: make_instrumental, |
| 563 | mv: model || DEFAULT_MODEL, |
| 564 | prompt: '', |
| 565 | generation_type: 'TEXT', |
| 566 | continue_at: continue_at, |
| 567 | continue_clip_id: continue_clip_id, |
| 568 | task: task, |
| 569 | token: await this.getCaptcha() |
| 570 | }; |
| 571 | if (isCustom) { |
| 572 | payload.tags = tags; |
| 573 | payload.title = title; |
| 574 | payload.negative_tags = negative_tags; |
| 575 | payload.prompt = prompt; |
| 576 | } else { |
| 577 | payload.gpt_description_prompt = prompt; |
| 578 | } |
| 579 | logger.info( |
| 580 | 'generateSongs payload:\n' + |
| 581 | JSON.stringify( |
| 582 | { |
| 583 | prompt: prompt, |
| 584 | isCustom: isCustom, |
| 585 | tags: tags, |
| 586 | title: title, |
| 587 | make_instrumental: make_instrumental, |
| 588 | wait_audio: wait_audio, |
| 589 | negative_tags: negative_tags, |
| 590 | payload: payload |
| 591 | }, |
| 592 | null, |
| 593 | 2 |
| 594 | ) |
| 595 | ); |
| 596 | const response = await this.client.post( |
| 597 | `${SunoApi.BASE_URL}/api/generate/v2/`, |
| 598 | payload, |
| 599 | { |
| 600 | timeout: 10000 // 10 seconds timeout |
| 601 | } |
| 602 | ); |
| 603 | if (response.status !== 200) { |
| 604 | throw new Error('Error response:' + response.statusText); |
no test coverage detected