当前位置: 首页 > news >正文

做业务 哪个网站比较好公司网站的主页优化

做业务 哪个网站比较好,公司网站的主页优化,手机网站集成支付宝,php+缺少+wordpress一、业务场景 最近笔者在业务中涉及到语音告警的模块#xff0c;需要将告警内容以文件或流形式返回给前端进行语音播报#xff0c;具体的分析与处理如下 二、业务分析 首先告警内容提示信息这里做的处理是通过专门字段去存储、编辑#xff0c;根据拟定好的代码逻辑判断是…一、业务场景 最近笔者在业务中涉及到语音告警的模块需要将告警内容以文件或流形式返回给前端进行语音播报具体的分析与处理如下 二、业务分析 首先告警内容提示信息这里做的处理是通过专门字段去存储、编辑根据拟定好的代码逻辑判断是否触发语音告警操作后续考虑用哪种方案实现文字转语音功能合适这里笔者选用的是阿里云付费的nls语音服务。 三、解决方案 1、pom文件引入 dependencygroupIdcom.alibaba.nls/groupIdartifactIdnls-sdk-tts/artifactIdversion2.2.1/version /dependency2、yml文件配置添加 # nls语音配置 ali:nls:##产品相关信息app-key: access-key-id: access-key-secret: ##语音信息声音类型、语速voice: sijiapitch-rate: -68speech-rate: 0 3、实体类构建 import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Data Component ConfigurationProperties(prefix ali.nls) public class NlsProperties {private String appKey;private String accessKeyId;private String accessKeySecret;private String url;//发音人private String voice;//语调范围是-500~500可选默认是0private Integer pitchRate;//语速范围是-500~500默认是0private Integer speechRate;} 4、config类构建 import com.demo.NlsProperties; import com.demo.NlsTemplate; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.core.StringRedisTemplate;Configuration public class NlsAutoConfiguration {Beanpublic NlsTemplate nlsTemplate(NlsProperties nlsProperties, StringRedisTemplate stringRedisTemplate){return new NlsTemplate(nlsProperties,stringRedisTemplate);}}5、服务类构建 import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.alibaba.nls.client.AccessToken; import com.alibaba.nls.client.protocol.OutputFormatEnum; import com.alibaba.nls.client.protocol.SampleRateEnum; import com.demo.NlsProperties; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import okhttp3.*; import org.springframework.data.redis.core.StringRedisTemplate; import java.io.*; import java.util.Date;Slf4j RequiredArgsConstructor public class NlsTemplate {private final NlsProperties nlsProperties;private final StringRedisTemplate stringRedisTemplate;/*** HTTPS POST请求*/public byte[] processPOSTRequest(String text) {/*** 设置HTTPS POST请求* 1.使用HTTPS协议* 2.语音合成服务域名nls-gateway-cn-shanghai.aliyuncs.com* 3.语音合成接口请求路径/stream/v1/tts* 4.设置必须请求参数appkey、token、text、format、sample_rate* 5.设置可选请求参数voice、volume、speech_rate、pitch_rate*/String url https://nls-gateway-cn-shenzhen.aliyuncs.com/stream/v1/tts;JSONObject taskObject new JSONObject();taskObject.putOpt(appkey, nlsProperties.getAppKey());taskObject.putOpt(token, this.getToken());taskObject.putOpt(text, text);taskObject.putOpt(format, OutputFormatEnum.MP3.getName());taskObject.putOpt(voice, nlsProperties.getVoice());taskObject.putOpt(sample_rate, SampleRateEnum.SAMPLE_RATE_16K.value);// speech_rate 语速范围是-500~500可选默认是0。taskObject.putOpt(speech_rate, nlsProperties.getSpeechRate());// pitch_rate 语调范围是-500~500可选默认是0。taskObject.putOpt(pitch_rate, nlsProperties.getPitchRate());String bodyContent JSONUtil.toJsonStr(taskObject);System.out.println(POST Body Content: bodyContent);RequestBody reqBody RequestBody.create(MediaType.parse(application/json), bodyContent);Request request new Request.Builder().url(url).header(Content-Type, application/json).post(reqBody).build();try {OkHttpClient client new OkHttpClient();Response response client.newCall(request).execute();String contentType response.header(Content-Type);byte[] data null;if (audio/mpeg.equals(contentType)) {data response.body().bytes();System.out.println(The POST request succeed!);} else {String errorMessage response.body().string();System.out.println(The POST request failed: errorMessage);}response.close();if (data ! null data.length 0) {// String filePath D:/test.wav; //音频文件保存路径及文件名 // saveFile(data, filePath); //调用函数将音频保存到本地return data;}} catch (Exception e) {e.printStackTrace();}return null;}/*** token暂存redis中*** */SneakyThrowsprivate String getToken() {String key NLS_TOKEN;Boolean hasKey stringRedisTemplate.hasKey(key);if (BooleanUtil.isTrue(hasKey)) {return stringRedisTemplate.opsForValue().get(key);}AccessToken token new AccessToken(nlsProperties.getAccessKeyId(), nlsProperties.getAccessKeySecret());token.apply();String accessToken token.getToken();stringRedisTemplate.opsForValue().set(key, accessToken);stringRedisTemplate.expireAt(key, new Date(token.getExpireTime() * 1000));return accessToken;}/*** 文件转换与生成** */public static void saveFile(byte[] bytes, String filePath) {try {FileOutputStream fos new FileOutputStream(new File(filePath));fos.write(bytes);fos.close();} catch (IOException e) {e.printStackTrace();}}} 具体的配置可以参考官方文档 https://help.aliyun.com/product/30413.html?spma2c4g.750001.0.0.61184fadyUJTlQ 如果服务会频繁使用可以把获取到阿里云token暂存在redis使用。 四、尾言 以上是语音合成业务的大致实现方案后续笔者尝试或有改进的方案也会同步上去感谢阅读和指正。
http://www.pierceye.com/news/215512/

相关文章:

  • 佛山新网站建设详细内容手机软件公司
  • 网站建设美词原创怎样建设一个能上传数据的网站
  • 网站建设网站营销做APP必须要有网站么
  • 易企建站咖啡公司网站建设策划书
  • wordpress 不能查看站点网站建设公司软件开
  • 网站文章seoftp搭建wordpress
  • 济宁企业做网站受欢迎的常州做网站
  • 我有域名有服务器怎么建设网站凡科官网app下载
  • 深圳保障性住房可以买卖吗襄樊seo排名
  • 餐饮官网建站模板网站开发实验报告可行性分析
  • 美食网站建设规划书外链工具软件
  • 网站设计模板代码七牛wordpress后台慢
  • 佛山网站建设怎么办huang色网站
  • 涞水县建设局网站wordpress wp_enqueue_script
  • 网站怎么添加音乐wordpress livechat
  • 网站开发的业务需求分析学校网站建设运行简介
  • 网站建设找博网iis7.0网站错误代码解决
  • 嘉鱼网站建设公司php网站开发技术期末题库
  • 企业网站搭建方案wordpress代码编辑器件
  • 网站的大小黄埔移动网站建设
  • 建设网站的语言中囯军事网
  • 网站开发职业访谈上海 建设工程质量监督站网站
  • 网站开发程序用什么好用新浪微博做网站
  • 什么免费推广网站好旅游订房网站开发需求文档
  • 网站运营是做啥的wordpress带会员中心主题
  • 网站设计怎么弄微信表情开放平台官网
  • 做网站纸张大小滨州网站建设模板建设
  • wordpress建站位置被跨境电商骗了怎么办
  • 巫山网站建设哇塞fm网站维护
  • 南宁百度网站推广计算机网站建设与推广