diff --git a/jcommon/ai/minimax/pom.xml b/jcommon/ai/minimax/pom.xml new file mode 100644 index 000000000..c4e1dd802 --- /dev/null +++ b/jcommon/ai/minimax/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + run.mone + ai + 1.4-jdk20-SNAPSHOT + + + minimax + + + 21 + 21 + UTF-8 + + + + + com.squareup.okhttp3 + okhttp + 4.10.0 + + + \ No newline at end of file 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 new file mode 100644 index 000000000..6e90eddfa --- /dev/null +++ b/jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/MiniMax.java @@ -0,0 +1,46 @@ +package run.mone.ai.minimax; + +import okhttp3.*; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.concurrent.TimeUnit; + +public class MiniMax { + + + public static byte[] call_Text_To_Speech(String groupId, String authorization, String content) { + 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/text_to_speech?GroupId=%s", groupId); + + // 构建请求 + Request request = new Request.Builder() + .url(url) + .post(RequestBody.create(mediaType, 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(); + if (responseBody != null) { + // 作为字节数组接收 + byte[] audioData = responseBody.bytes(); + return audioData; + } + return null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/jcommon/ai/minimax/src/test/java/run/mone/ai/minimax/test/MiniMaxTest.java b/jcommon/ai/minimax/src/test/java/run/mone/ai/minimax/test/MiniMaxTest.java new file mode 100644 index 000000000..880b2fb90 --- /dev/null +++ b/jcommon/ai/minimax/src/test/java/run/mone/ai/minimax/test/MiniMaxTest.java @@ -0,0 +1,22 @@ +package run.mone.ai.minimax.test; + +import com.google.gson.JsonObject; +import org.junit.Test; +import run.mone.ai.minimax.MiniMax; + +public class MiniMaxTest { + + @Test + public void testCall() { + try { + JsonObject json = new JsonObject(); + json.addProperty("voice_id", "male-qn-qingse"); + json.addProperty("text", "你好,北京今天天气很好!"); + json.addProperty("model", "speech-01"); + String content = json.toString(); + MiniMax.call_Text_To_Speech("", "", content); + } catch (Exception e) { + System.out.println(e); + } + } +} diff --git a/jcommon/ai/pom.xml b/jcommon/ai/pom.xml index 0c71cad63..111b79489 100644 --- a/jcommon/ai/pom.xml +++ b/jcommon/ai/pom.xml @@ -16,6 +16,7 @@ moonshot google aws + minimax