Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

接入minmax #843

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/MiniMax.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
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;

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) {
Expand Down Expand Up @@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Loading