main
HuangHai 2 months ago
parent b510cc7362
commit 7acb6403d8

@ -187,14 +187,21 @@ public class SunoMusicGenerator {
System.out.println("状态: " + status); System.out.println("状态: " + status);
// 检查是否是我们要查询的任务 // 检查是否是我们要查询的任务
if (taskIds.contains(clipId)) { // 注意这里我们不再检查taskIds.contains(clipId)因为我们查询的是clips ID
// 检查是否完成 // 检查是否完成
if ("complete".equals(status)) { if ("complete".equals(status)) {
// 确保audio_url字段存在
if (clip.containsKey("audio_url") && clip.getString("audio_url") != null && !clip.getString("audio_url").isEmpty()) {
audioUrl = clip.getString("audio_url"); audioUrl = clip.getString("audio_url");
System.out.println("音乐生成已完成!"); System.out.println("音乐生成已完成!");
System.out.println("音频URL: " + audioUrl); System.out.println("音频URL: " + audioUrl);
isComplete = true; isComplete = true;
break; // 找到了我们要查询的任务,并且已完成 break; // 找到了已完成的任务
} else {
System.out.println("音乐生成已完成但未找到音频URL!");
// 打印完整的clip信息以便调试
System.out.println("完整的片段信息: " + clip.toJSONString());
}
} else if ("streaming".equals(status)) { } else if ("streaming".equals(status)) {
System.out.println("音乐生成中,继续等待..."); System.out.println("音乐生成中,继续等待...");
} else if ("failed".equals(status)) { } else if ("failed".equals(status)) {
@ -203,7 +210,6 @@ public class SunoMusicGenerator {
break; break;
} }
} }
}
} else { } else {
System.out.println("未找到音乐片段,继续等待..."); System.out.println("未找到音乐片段,继续等待...");
} }
@ -212,13 +218,20 @@ public class SunoMusicGenerator {
} }
// 3. 下载音频文件(如果生成成功) // 3. 下载音频文件(如果生成成功)
if (isComplete && audioUrl != null) { if (isComplete && audioUrl != null && !audioUrl.isEmpty()) {
// 移除URL中可能存在的反引号
audioUrl = audioUrl.replace("`", "").trim();
String fileName = "suno_music_" + System.currentTimeMillis() + ".mp3"; String fileName = "suno_music_" + System.currentTimeMillis() + ".mp3";
String savePath = "./downloads/" + fileName; // 使用basePath作为保存目录
String savePath = basePath + fileName;
System.out.println("准备下载音频到: " + savePath);
downloadAudio(client, audioUrl, savePath); downloadAudio(client, audioUrl, savePath);
} else if (retryCount >= MAX_RETRIES) { } else if (retryCount >= MAX_RETRIES) {
System.out.println("达到最大重试次数,任务可能仍在处理中"); System.out.println("达到最大重试次数,任务可能仍在处理中");
System.out.println("请稍后手动查询任务ID: " + taskId); System.out.println("请稍后手动查询任务ID: " + taskId);
} else if (audioUrl == null || audioUrl.isEmpty()) {
System.out.println("未能获取有效的音频URL无法下载");
} }
} }

Loading…
Cancel
Save