Commit 085ebfc792398afbf76ed8ccda8ca50a713f7635
1 parent
851c290c
【增加】AI:suno-api 自定义音乐生成接口接入
Showing
1 changed file
with
23 additions
and
5 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/suno/api/SunoApi.java
| @@ -55,6 +55,17 @@ public class SunoApi { | @@ -55,6 +55,17 @@ public class SunoApi { | ||
| 55 | .block(); | 55 | .block(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | + public List<MusicData> customGenerate(SunoApi.SunoReq sunReq) { | ||
| 59 | + return this.webClient.post() | ||
| 60 | + .uri("/api/custom_generate") | ||
| 61 | + .body(Mono.just(sunReq), SunoApi.SunoReq.class) | ||
| 62 | + .retrieve() | ||
| 63 | + .onStatus(STATUS_PREDICATE, EXCEPTION_FUNCTION) | ||
| 64 | + .bodyToMono(new ParameterizedTypeReference<List<MusicData>>() { | ||
| 65 | + }) | ||
| 66 | + .block(); | ||
| 67 | + } | ||
| 68 | + | ||
| 58 | public List<MusicData> doChatCompletion(String prompt) { | 69 | public List<MusicData> doChatCompletion(String prompt) { |
| 59 | return this.webClient.post() | 70 | return this.webClient.post() |
| 60 | .uri("/v1/chat/completions") | 71 | .uri("/v1/chat/completions") |
| @@ -105,8 +116,9 @@ public class SunoApi { | @@ -105,8 +116,9 @@ public class SunoApi { | ||
| 105 | * 根据提示生成音频 | 116 | * 根据提示生成音频 |
| 106 | * | 117 | * |
| 107 | * @param prompt 用于生成音乐音频的提示 | 118 | * @param prompt 用于生成音乐音频的提示 |
| 108 | - * @param tags 自定义模式才需要 | ||
| 109 | - * @param title 自定义模式才需要 | 119 | + * @param tags 音乐风格 |
| 120 | + * @param title 音乐名称 | ||
| 121 | + * @param mv 模型 | ||
| 110 | * @param waitAudio false表示后台模式,仅返回音频任务信息,需要调用get API获取详细的音频信息。 | 122 | * @param waitAudio false表示后台模式,仅返回音频任务信息,需要调用get API获取详细的音频信息。 |
| 111 | * true表示同步模式,API最多等待100s,音频生成完毕后直接返回音频链接等信息,建议在GPT等agent中使用。 | 123 | * true表示同步模式,API最多等待100s,音频生成完毕后直接返回音频链接等信息,建议在GPT等agent中使用。 |
| 112 | * @param makeInstrumental 指示音乐音频是否为定制,如果为 true,则从歌词生成,否则从提示生成 | 124 | * @param makeInstrumental 指示音乐音频是否为定制,如果为 true,则从歌词生成,否则从提示生成 |
| @@ -116,15 +128,21 @@ public class SunoApi { | @@ -116,15 +128,21 @@ public class SunoApi { | ||
| 116 | String prompt, | 128 | String prompt, |
| 117 | String tags, | 129 | String tags, |
| 118 | String title, | 130 | String title, |
| 131 | + String mv, | ||
| 119 | @JsonProperty("wait_audio") boolean waitAudio, | 132 | @JsonProperty("wait_audio") boolean waitAudio, |
| 120 | @JsonProperty("make_instrumental") boolean makeInstrumental | 133 | @JsonProperty("make_instrumental") boolean makeInstrumental |
| 121 | ) { | 134 | ) { |
| 122 | public SunoReq(String prompt) { | 135 | public SunoReq(String prompt) { |
| 123 | - this(prompt, null, null, false, false); | 136 | + this(prompt, null, null, null, false, false); |
| 124 | } | 137 | } |
| 125 | 138 | ||
| 139 | + public SunoReq(String prompt, String mv, boolean makeInstrumental) { | ||
| 140 | + this(prompt, null, null, mv, false, makeInstrumental); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + | ||
| 126 | public SunoReq(String prompt, String tags, String title) { | 144 | public SunoReq(String prompt, String tags, String title) { |
| 127 | - this(prompt, tags, title, false, false); | 145 | + this(prompt, tags, title, null, false, false); |
| 128 | } | 146 | } |
| 129 | } | 147 | } |
| 130 | 148 | ||
| @@ -140,7 +158,7 @@ public class SunoApi { | @@ -140,7 +158,7 @@ public class SunoApi { | ||
| 140 | * @param videoUrl 音乐视频的 URL | 158 | * @param videoUrl 音乐视频的 URL |
| 141 | * @param createdAt 音乐音频的创建时间 | 159 | * @param createdAt 音乐音频的创建时间 |
| 142 | * @param modelName | 160 | * @param modelName |
| 143 | - * @param status | 161 | + * @param status submitted、queued、streaming、complete |
| 144 | * @param gptDescriptionPrompt | 162 | * @param gptDescriptionPrompt |
| 145 | * @param prompt 生成音乐音频的提示 | 163 | * @param prompt 生成音乐音频的提示 |
| 146 | * @param type | 164 | * @param type |