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

贵港网站设计在哪里推广自己的产品

贵港网站设计,在哪里推广自己的产品,做网站移交资料,网站seo分析工具我们在开发中,用到实时语音的时候,会有讯飞、百度、阿里,今天主要讲解的是百度语音之语音合成: public class YuYinUtil { private static final Logger logger LogManager.getLogger(YuYinUtil.class); public static final St…

我们在开发中,用到实时语音的时候,会有讯飞、百度、阿里,今天主要讲解的是百度语音之语音合成:

public class YuYinUtil {

    private static final Logger logger = LogManager.getLogger(YuYinUtil.class);

    public static final String YU_YIN_HE_CHENG_URL = "http://tsn.baidu.com/text2audio";

    /**
     * 语音合成
     * 
     * @param token 百度token
     * @param text  发音文本
     * @param vol   音量 0-15
     * @param per   发音人 0-普通女声、1-普通男声、3-度逍遥、4度丫丫
     * @param spd   语速 0-15
     * @param aue   格式 3为mp3格式(默认); 4为pcm-16k;5为pcm-8k;6为wav(内容同pcm-16k);
     *              注意aue=4或者6是语音识别要求的格式,但是音频内容不是语音识别要求的自然人发音,所以识别效果会受影响。
     * @throws UnsupportedEncodingException
     */
    @SuppressWarnings("deprecation")
    public void generateYuYin(String token, String text, String vol, String per, String spd, String pit, String aue,
            String outputFile) {

        logger.debug("调用语音合成接口");
        logger.debug("text:" + text);
        logger.debug("vol:" + vol);
        logger.debug("per:" + per);
        logger.debug("spd:" + spd);
        logger.debug("pit:" + pit);
        logger.debug("aue:" + aue);

        CloseableHttpClient httpClient = HttpClients.createMinimal();

        // 百度语音要求tex字段进行两次url encode,post实体中会进行一次encode
        String encodeText;
        try {
            encodeText = URLEncoder.encode(text, "utf-8");
        } catch (UnsupportedEncodingException e1) {
            throw new RuntimeException(e1);
        }
//        encodeText = URLEncoder.encode(encodeText, "utf-8");

//        String url = YU_YIN_HE_CHENG_URL + "?lan=zh&ctp=1&cuid=abcdxxx&tok=" + token + "&tex=" + encodeText
//                + "&vol=9&per=0&spd=5&pit=5&aue=3";
//        url = URLEncoder.encode(url, "utf-8");

//        HttpGet get = new HttpGet(url);

        HttpPost post = new HttpPost(YU_YIN_HE_CHENG_URL);

        List<NameValuePair> params = new ArrayList<>();
        // 语言 目前只支持zh固定值
        params.add(new BasicNameValuePair("lan", "zh"));
        // 客户端类型选择 web端写1
        params.add(new BasicNameValuePair("ctp", "1"));
        // cuid 用户唯一标识,用来计算UV值。建议填写能区分用户的机器 MAC 地址或 IMEI 码,长度为60字符以内
        params.add(new BasicNameValuePair("cuid", "kelvinylon"));
        // token
        params.add(new BasicNameValuePair("tok", token));
        // text 语音文本
        params.add(new BasicNameValuePair("tex", encodeText));
        // 以下是选填项
        // vol 音量 0-15
        if (vol != null) {
            params.add(new BasicNameValuePair("vol", vol));
        }

        // per 发音人 0、1、3、4
        if (per != null) {
            params.add(new BasicNameValuePair("per", per));
        }

        // spd 语速 0-15
        if (spd != null) {
            params.add(new BasicNameValuePair("spd", spd));
        }
        
        // pit 语调
        if(pit != null) {
            params.add(new BasicNameValuePair("pit", pit));
        }

        // aue 3为mp3格式(默认); 4为pcm-16k;5为pcm-8k;6为wav(内容同pcm-16k);
        // 注意aue=4或者6是语音识别要求的格式,但是音频内容不是语音识别要求的自然人发音,所以识别效果会受影响。
        if (aue != null) {
            params.add(new BasicNameValuePair("aue", aue));
        }

        UrlEncodedFormEntity entity;
        try {
            entity = new UrlEncodedFormEntity(params);
        } catch (UnsupportedEncodingException e1) {
            throw new RuntimeException(e1);
        }
        post.setEntity(entity);

        RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(5000).setConnectTimeout(5000)
                .setSocketTimeout(20000).build();
//        get.setConfig(config);
        post.setConfig(config);
        try {
            CloseableHttpResponse resp = httpClient.execute(post);
            HttpEntity respEntity = resp.getEntity();
            String contentType = respEntity.getContentType().getValue();
            System.out.println(contentType);
            if (contentType.equals("application/json")) {
                throw new RuntimeException("错误:contentType为json,此请求的contentType应为音频文件");
            }
            InputStream contentIn = respEntity.getContent();
            File outFile = new File(outputFile);
            if(!outFile.getParentFile().exists()) {
                boolean b = outFile.getParentFile().mkdirs();
                if(!b) {
                    throw new RuntimeException("创建父文件夹失败");
                }
            }
            
            FileOutputStream fout = new FileOutputStream(outputFile);
            try {
                IOUtils.copy(contentIn, fout);
            } finally {
                IOUtils.closeQuietly(contentIn);
                IOUtils.closeQuietly(fout);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public void generateYuYin(String token, String text, String outputFile) {
        generateYuYin(token, text, null, null, null, null, null, outputFile);
    }

    /**
     * 语音识别成文字
     * 
     * @param in
     * @param token
     * @return
     */
    public String reconizeYuYin(InputStream in, String token) {
        return null;
    }

}
 

http://www.hkea.cn/news/408805/

相关文章:

  • 珠海建设局网站十大经典事件营销案例分析
  • 创建网站开发公司互联网推广引流是做什么的
  • 万盛集团网站建设seo网站推广全程实例
  • 做教育的网站需要资质吗网站怎么开发
  • 微网站怎么做滚动中国万网域名注册官网
  • 个人如何免费建网站seo在线优化工具 si
  • 双线主机可以做彩票网站吗网络推广合作协议
  • 做外贸的b2b网站域名批量查询系统
  • 建设网站需要哪些职位网站建设策划书
  • 苏州网站建设哪里好网站点击排名优化
  • 网站建设收费标准策划百度推广关键词越多越好吗
  • 网站怎么做更新吗如何建立网页
  • 国外建设工程招聘信息网站tool站长工具
  • 专业做相册书的网站电商网站建设制作
  • 银川网站开发公司电话东莞网
  • 环境保护局网站管理制度建设百度指数的主要功能有
  • 安装wordpress提示500错误关键词优化的策略有哪些
  • 企业网站建设公司排名深圳高端seo公司助力企业
  • 做网站套餐网站seo
  • 网站上的代码网页怎么做的下载百度软件
  • 网站功能模块建设搜狗推广
  • 网站做推广有用吗网站页面设计
  • 做简报的网站广州搜发网络科技有限公司
  • 南乐县住房和城乡建设局网站制作网站的步骤是什么
  • 金华做网站最专业的公司搜易网提供的技术服务
  • wordpress适合门户网站吗怎么营销自己的产品
  • 常用的网站类型有哪些seo优化专员编辑
  • 网站专题框架怎么做海阳seo排名
  • 手机网站代码下载黄页网站推广服务
  • 做网站前端多少钱在线bt种子