diff --git a/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/MiniMax.java b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/MiniMax.java index 339f9357d..4fcc8074c 100644 --- a/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/MiniMax.java +++ b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/MiniMax.java @@ -3,6 +3,7 @@ import com.google.gson.Gson; import okhttp3.*; import run.mone.ai.minimax.bo.RequestBodyContent; +import run.mone.ai.minimax.bo.T2AProResponse; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -10,6 +11,14 @@ public class MiniMax { static Gson gson = new Gson(); + + /** + * T2A(语音生成) + * @param groupId + * @param authorization + * @param content + * @return + */ public static byte[] call_Text_To_Speech(String groupId, String authorization, RequestBodyContent content) { if (groupId == null || groupId.trim().length() < 1) { @@ -60,4 +69,60 @@ public static byte[] call_Text_To_Speech(String groupId, String authorization, R } } + /** + * T2A Pro(长文本语音生成) + * @param groupId + * @param authorization + * @param content + * @return + */ + public static T2AProResponse call_T2A_Pro(String groupId, String authorization, RequestBodyContent content) { + + if (groupId == null || groupId.trim().length() < 1) { + throw new RuntimeException("groupId is null"); + } + + if (authorization == null || authorization.trim().length() < 1) { + throw new RuntimeException("authorization is null"); + } + + if (content == null) { + throw new RuntimeException("content is null"); + } + + if (content.getText() == null || content.getText().trim().length() < 1) { + throw new RuntimeException("content.text is null"); + } + + OkHttpClient client = new OkHttpClient.Builder().readTimeout(5, TimeUnit.MINUTES).build(); + // 设置请求体的内容类型和内容 + MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); + + String url = String.format("https://api.minimax.chat/v1/t2a_pro?GroupId=%s", groupId); + + // 构建请求 + Request request = new Request.Builder() + .url(url) + .post(RequestBody.create(mediaType, gson.toJson(content))) + .addHeader("Content-Type", "application/json") + .addHeader("Authorization","Bearer "+authorization) + .build(); + + // 发送请求并获取响应 + try (Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + + ResponseBody responseBody = response.body(); + T2AProResponse t2aProResponse = null; + if (responseBody != null) { + t2aProResponse = gson.fromJson(responseBody.string(), T2AProResponse.class); + } + return t2aProResponse; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } diff --git a/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/BaseResponse.java b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/BaseResponse.java new file mode 100644 index 000000000..d4424eafe --- /dev/null +++ b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/BaseResponse.java @@ -0,0 +1,14 @@ +package run.mone.ai.minimax.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +@Data +public class BaseResponse { + + @SerializedName(value = "status_code") + private String statusCode; + + @SerializedName(value = "status_msg") + private String statusMsg; +} diff --git a/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/ExtraInfo.java b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/ExtraInfo.java new file mode 100644 index 000000000..c6c9a2464 --- /dev/null +++ b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/ExtraInfo.java @@ -0,0 +1,28 @@ +package run.mone.ai.minimax.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +@Data +public class ExtraInfo { + + @SerializedName(value = "audio_length") + private Long audioLength; + + @SerializedName(value = "audio_sample_rate") + private Long audioSampleRate; + + @SerializedName(value = "audio_size") + private Long audioSize; + + private Long bitrate; + + @SerializedName(value = "word_count") + private Long wordCount; + + @SerializedName(value = "invisible_character_ratio") + private Double invisibleCharacterRatio; + + @SerializedName(value = "usage_characters") + private Long usageCharacters; +} diff --git a/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/T2AProResponse.java b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/T2AProResponse.java new file mode 100644 index 000000000..d16d0d94a --- /dev/null +++ b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/bo/T2AProResponse.java @@ -0,0 +1,26 @@ +package run.mone.ai.minimax.bo; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +@Data +public class T2AProResponse { + + /** + * 合成的音频下载链接 + */ + @SerializedName(value = "audio_file") + private String audioFile; + + /** + * 合成的字幕下载链接 + */ + @SerializedName(value = "subtitle_file") + private String subtitleFile; + + @SerializedName(value = "extra_info") + private ExtraInfo extraInfo; + + @SerializedName(value = "base_resp") + private BaseResponse baseResponse; +}