提交查询门店和积分返利

yy_dev
袁野 1 year ago
parent b89f70bfbf
commit 2ad2b0b036
  1. 16
      cweb/src/main/java/com/cweb/controller/TestController.java
  2. 18
      service/pom.xml
  3. 108
      service/src/main/java/com/hfkj/tts/HWYunSisService.java

@ -34,6 +34,7 @@ import com.hfkj.model.MerBasisModel;
import com.hfkj.model.ResponseData; import com.hfkj.model.ResponseData;
import com.hfkj.service.*; import com.hfkj.service.*;
import com.hfkj.sysenum.*; import com.hfkj.sysenum.*;
import com.hfkj.tts.HWYunSisService;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
@ -644,4 +645,19 @@ public class TestController {
} }
} }
@RequestMapping(value="/ttsCustomDemo",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "updateReview")
public ResponseData ttsCustomDemo() {
try {
return ResponseMsgUtil.success(HWYunSisService.ttsCustomDemo());
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResponseMsgUtil.exception(e);
}
}
} }

@ -373,6 +373,11 @@
<artifactId>freemarker</artifactId> <artifactId>freemarker</artifactId>
<version>2.3.23</version> <version>2.3.23</version>
</dependency> </dependency>
<dependency>
<groupId>com.huawei.sis</groupId>
<artifactId>huaweicloud-java-sdk-sis</artifactId>
<version>1.8.1</version>
</dependency>
<!--<dependency> <!--<dependency>
<groupId>com.huaweicloud</groupId> <groupId>com.huaweicloud</groupId>
<artifactId>esdk-obs-java</artifactId> <artifactId>esdk-obs-java</artifactId>
@ -396,4 +401,17 @@
</resource> </resource>
</resources> </resources>
</build> </build>
<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>
</project> </project>

@ -0,0 +1,108 @@
package com.hfkj.tts;
import com.huawei.sis.bean.AuthInfo;
import com.huawei.sis.bean.SisConfig;
import com.huawei.sis.bean.SisConstant;
import com.huawei.sis.bean.request.TtsCustomRequest;
import com.huawei.sis.bean.response.TtsCustomResponse;
import com.huawei.sis.client.TtsCustomizationClient;
import com.huawei.sis.exception.SisException;
import com.huawei.sis.util.JsonUtils;
public class HWYunSisService {
private static final int DEFAULT_PITCH = 0;
private static final int DEFAULT_SPEED = -100;
private static final int DEFAULT_VOLUME = 50;
private static String ak = "SQ9ERSS9KKJ7VC72TK4D";
private static String sk = "YqG2MDTsjXPel5URmKpOfyePrzbMWCU9YdzCUPmp";
// 区域,如cn-north-1、cn-north-4
private static String region = "cn-east-3";
// 项目id。登录管理控制台,鼠标移动到右上角的用户名上,在下拉列表中选择我的凭证,在项目列表中查看项目id。多项目时,展开“所属区域”,从“项目ID”列获取子项目ID。
private static String projectId = "075456f65780107f2f4ec013ff43b487";
// 待合成的文本
private static String text = "惠支付收款 98.6元";
// 设置本地音频保存路径.可选择不保存到本地。需具体到文件,如D:/test.wav
// private static String path = CommonSysConst.getSysConfig().getFile_url() + "/tts/test.wav";
private static String path = "/Volumes/work/开发/filesystem/test.mp3";
/**
* 用于语音合成参数设置例如发声人音高语速音量采样率连接超时所有参数均可以不设置采用默认
*
* @param request 语音合成请求
*/
private static void setParameter(TtsCustomRequest request) {
// 设置语音格式,可选MP3,pcm等,默认wav
request.setAudioFormat("mp3");
// 音高,[-500, 500], 默认0
request.setPitch(DEFAULT_PITCH);
// 语速,[-500, 500],默认0
request.setSpeed(DEFAULT_SPEED);
// 音量,[0, 100],默认50
request.setVolume(DEFAULT_VOLUME);
// 当前支持8000和16000,默认8000
request.setSampleRate("8000");
// 设置property,特征字符串,{language}_{speaker}_{domain}
request.setProperty("chinese_huaxiaowen_common");
// 设置返回数据是否保存,默认不保存。若保存,则需要设置一下保存路径,如D:/1.wav
request.setSaved(true);
request.setSavePath(path);
}
/**
* 定义config所有参数可选设置超时时间等
*
* @return SisConfig
*/
private static SisConfig getConfig() {
SisConfig config = new SisConfig();
// 设置连接超时,默认10000ms
config.setConnectionTimeout(SisConstant.DEFAULT_CONNECTION_TIMEOUT);
// 设置读取超时,默认10000ms
config.setReadTimeout(SisConstant.DEFAULT_READ_TIMEOUT);
// 设置代理, 一定要确保代理可用才启动此设置。 代理初始化也可用不加密的代理,new ProxyHostInfo(host, port);
// ProxyHostInfo proxy = new ProxyHostInfo(host, port, username, password);
// config.setProxy(proxy);
return config;
}
/**
* 根据文本和api获取生成的音频数据
*/
public static Object ttsCustomDemo() {
try {
// 1. 初始化TtsCustomizationClient
// 定义authInfo,根据ak,sk,region, projectId.
AuthInfo authInfo = new AuthInfo(ak, sk, region, projectId);
// 定义config,所有参数可选,设置超时时间。
SisConfig config = getConfig();
// 根据authInfo和config,构造TtsCustomizationClient
TtsCustomizationClient tts = new TtsCustomizationClient(authInfo, config);
// 2. 配置请求
TtsCustomRequest request = new TtsCustomRequest(text);
// 设置参数,所有参数均可选,如果要保存合成音频文件,需要在request设置
setParameter(request);
// 3. 发送请求,获取响应。具体结果可通过response.getXX获取。
TtsCustomResponse response = tts.getTtsResponse(request);
return JsonUtils.obj2Str(response, true);
} catch (SisException e) {
e.printStackTrace();
System.out.println("error_code:" + e.getErrorCode() + "\nerror_msg:" + e.getErrorMsg());
return null;
}
}
}
Loading…
Cancel
Save