华为语音识别回滚

This commit is contained in:
joylink_zhangsai 2021-04-12 11:11:29 +08:00
parent 83d7238b11
commit d681f9c29a
3 changed files with 0 additions and 65 deletions

19
pom.xml
View File

@ -107,27 +107,8 @@
<artifactId>wechatpay-apache-httpclient</artifactId> <artifactId>wechatpay-apache-httpclient</artifactId>
<version>0.2.1</version> <version>0.2.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.huawei.sis</groupId>
<artifactId>huaweicloud-java-sdk-sis</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies> </dependencies>
<repositories>
<repository>
<id>sis-repo</id>
<name>Sis Release Repository</name>
<url>https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -106,11 +106,6 @@ public interface IVoiceService {
*/ */
String synthesis(String message, String per); String synthesis(String message, String per);
/**
* 华为语音识别
*/
VoiceRecognitionResult huaweiVoiceRecognition(MultipartFile file, String lang);
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor

View File

@ -3,12 +3,6 @@ package club.joylink.rtss.services.voice.baidu;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.IVoiceService; import club.joylink.rtss.services.IVoiceService;
import club.joylink.rtss.vo.client.VoiceRecognitionResult; import club.joylink.rtss.vo.client.VoiceRecognitionResult;
import com.huawei.sis.bean.AuthInfo;
import com.huawei.sis.bean.SisConfig;
import com.huawei.sis.bean.request.AsrCustomShortRequest;
import com.huawei.sis.bean.response.AsrCustomShortResponse;
import com.huawei.sis.client.AsrCustomizationClient;
import com.huawei.sis.exception.SisException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -18,20 +12,11 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Base64;
@Slf4j @Slf4j
@Service("baiDuVoiceService") @Service("baiDuVoiceService")
public class VoiceServiceImpl implements IVoiceService { public class VoiceServiceImpl implements IVoiceService {
/**
* 华为语音识别配置
*/
private final String ak = "YDUXTXRYGAHGPHAIXZCU";
private final String sk = "Kcbm3sTDCYEou8kGeAhKxfBkgWybIn6IjJyGBX3p";
private final String region = "cn-north-4";
private final String projectId = "0aada8176180f28c2f34c0196f5394e8";
@Autowired @Autowired
private AsrService asrService; private AsrService asrService;
@ -65,30 +50,4 @@ public class VoiceServiceImpl implements IVoiceService {
} }
} }
@Override
public VoiceRecognitionResult huaweiVoiceRecognition(MultipartFile file, String lang) {
String filePath;
try {
filePath = IVoiceService.handleAndSaveFile(file);
} catch (IOException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件上传失败", e);
}
AuthInfo authInfo = new AuthInfo(ak, sk, region, projectId);
SisConfig sisConfig = new SisConfig();
AsrCustomizationClient client = new AsrCustomizationClient(authInfo, sisConfig);
String data;
try {
data = Base64.getEncoder().encodeToString(file.getBytes());
} catch (IOException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件编码失败", e);
}
try {
AsrCustomShortRequest request = new AsrCustomShortRequest(data, "pcm16k16bit", "chinese_16k_common");
AsrCustomShortResponse response = client.getAsrShortResponse(request);
return new VoiceRecognitionResult(filePath, response.getResult().getText());
} catch (SisException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音识别失败", e);
}
}
} }