Skip to content

Commit

Permalink
接入minmax (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
caochengxiang authored May 16, 2024
2 parents e466541 + 4997685 commit 8063860
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
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

0 comments on commit 8063860

Please sign in to comment.