Merge remote-tracking branch 'origin/test'

This commit is contained in:
joylink_zhangsai 2021-04-12 19:07:23 +08:00
commit d703a3e128
3 changed files with 91 additions and 91 deletions

36
pom.xml
View File

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

View File

@ -16,15 +16,15 @@ import org.springframework.web.multipart.MultipartFile;
@RequestMapping("/api/voice") @RequestMapping("/api/voice")
public class VoiceController { public class VoiceController {
//
@Autowired // @Autowired
@Qualifier("HuaWeiVoiceService") // @Qualifier("HuaWeiVoiceService")
private IVoiceService iVoiceService; // private IVoiceService iVoiceService;
//
@ApiOperation("语音识别") // @ApiOperation("语音识别")
@PostMapping("recognition") // @PostMapping("recognition")
public VoiceRecognitionResult voiceRecognition(MultipartFile file) { // public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
return this.iVoiceService.voiceRecognition(file, ""); // return this.iVoiceService.voiceRecognition(file, "");
} // }
} }

View File

@ -1,63 +1,63 @@
package club.joylink.rtss.services.voice.huawei; //package club.joylink.rtss.services.voice.huawei;
//
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.AuthInfo;
import com.huawei.sis.bean.SisConfig; //import com.huawei.sis.bean.SisConfig;
import com.huawei.sis.bean.request.AsrCustomShortRequest; //import com.huawei.sis.bean.request.AsrCustomShortRequest;
import com.huawei.sis.bean.response.AsrCustomShortResponse; //import com.huawei.sis.bean.response.AsrCustomShortResponse;
import com.huawei.sis.client.AsrCustomizationClient; //import com.huawei.sis.client.AsrCustomizationClient;
import com.huawei.sis.exception.SisException; //import com.huawei.sis.exception.SisException;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; //import org.springframework.web.multipart.MultipartFile;
//
import java.io.IOException; //import java.io.IOException;
import java.util.Base64; //import java.util.Base64;
//
@Slf4j //@Slf4j
@Service("HuaWeiVoiceService") //@Service("HuaWeiVoiceService")
public class HuaweiVoiceServiceImpl implements IVoiceService { //public class HuaweiVoiceServiceImpl implements IVoiceService {
//
/** // /**
* 华为语音识别配置 // * 华为语音识别配置
*/ // */
private final String ak = "YDUXTXRYGAHGPHAIXZCU"; // private final String ak = "YDUXTXRYGAHGPHAIXZCU";
private final String sk = "Kcbm3sTDCYEou8kGeAhKxfBkgWybIn6IjJyGBX3p"; // private final String sk = "Kcbm3sTDCYEou8kGeAhKxfBkgWybIn6IjJyGBX3p";
private final String region = "cn-north-4"; // private final String region = "cn-north-4";
private final String projectId = "0aada8176180f28c2f34c0196f5394e8"; // private final String projectId = "0aada8176180f28c2f34c0196f5394e8";
//
//
@Override // @Override
public String synthesis(String message, String per) { // public String synthesis(String message, String per) {
throw BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.exception("功能暂未实现"); // throw BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.exception("功能暂未实现");
} // }
//
@Override // @Override
public VoiceRecognitionResult voiceRecognition(MultipartFile file, String lang) { // public VoiceRecognitionResult voiceRecognition(MultipartFile file, String lang) {
String filePath; // String filePath;
try { // try {
filePath = IVoiceService.handleAndSaveFile(file); // filePath = IVoiceService.handleAndSaveFile(file);
} catch (IOException e) { // } catch (IOException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件上传失败", e); // throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件上传失败", e);
} // }
AuthInfo authInfo = new AuthInfo(ak, sk, region, projectId); // AuthInfo authInfo = new AuthInfo(ak, sk, region, projectId);
SisConfig sisConfig = new SisConfig(); // SisConfig sisConfig = new SisConfig();
AsrCustomizationClient client = new AsrCustomizationClient(authInfo, sisConfig); // AsrCustomizationClient client = new AsrCustomizationClient(authInfo, sisConfig);
String data; // String data;
try { // try {
data = Base64.getEncoder().encodeToString(file.getBytes()); // data = Base64.getEncoder().encodeToString(file.getBytes());
} catch (IOException e) { // } catch (IOException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件编码失败", e); // throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件编码失败", e);
} // }
try { // try {
AsrCustomShortRequest request = new AsrCustomShortRequest(data, "pcm16k16bit", "chinese_16k_common"); // AsrCustomShortRequest request = new AsrCustomShortRequest(data, "pcm16k16bit", "chinese_16k_common");
AsrCustomShortResponse response = client.getAsrShortResponse(request); // AsrCustomShortResponse response = client.getAsrShortResponse(request);
return new VoiceRecognitionResult(filePath, response.getResult().getText()); // return new VoiceRecognitionResult(filePath, response.getResult().getText());
} catch (SisException e) { // } catch (SisException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音识别失败", e); // throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音识别失败", e);
} // }
} // }
//
} //}