-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
jcommon/ai/minimax/src/main/java/run/mone/ai/minimax/MiniMax.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
jcommon/ai/minimax/src/test/java/run/mone/ai/minimax/test/MiniMaxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters