Skip to content

Commit

Permalink
speech2text (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
caochengxiang authored May 17, 2024
2 parents 7499298 + faff4a0 commit cbbc688
Show file tree
Hide file tree
Showing 6 changed files with 994 additions and 0 deletions.
33 changes: 33 additions & 0 deletions jcommon/ai/bytedance/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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>bytedance</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>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.1</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.4</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package run.mone.ai.bytedance;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;

@Slf4j
public class ArsClientOut {

public static String callArsClient(ArsRequest request) {
String response = "";
AsrClient asr_client = null;
try {
asr_client = AsrClient.build();
asr_client.setAppid(request.getAppId());
asr_client.setToken(request.getToken());
asr_client.setCluster(request.getCluster());
asr_client.setFormat(request.getAudio_format());
asr_client.setShow_utterances(true);
asr_client.asr_sync_connect();

AsrResponse asr_response = asr_response = asr_client.asr_send(request.getAudio(), true);

// get asr text
// AsrResponse response = asr_client.getAsrResponse();
for (AsrResponse.Result result: asr_response.getResult()) {
response = response + result.getText();
}
} catch (Exception e) {
log.error("callArsClient error", e);
} finally {
if (asr_client != null) {
asr_client.asr_close();
}
}
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package run.mone.ai.bytedance;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ArsRequest {

private String appId;

private String token;

private String cluster;

@Builder.Default
private String audio_format = "mp3";

private byte[] audio;
}
Loading

0 comments on commit cbbc688

Please sign in to comment.