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 #840

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
27 changes: 27 additions & 0 deletions jcommon/ai/minimax/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>run.mone</groupId>
<artifactId>ai</artifactId>
<version>1.4-jdk20-SNAPSHOT</version>
</parent>

<artifactId>minimax</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
</dependencies>
</project>
46 changes: 46 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
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
1 change: 1 addition & 0 deletions jcommon/ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<module>moonshot</module>
<module>google</module>
<module>aws</module>
<module>minimax</module>
</modules>

<properties>
Expand Down
Loading