知方号

知方号

讯飞语音合成 如何选择发音人

问题描述

讯飞语音合成有多个发音人,如何选择一个合适的发音人呢?我的解决方法是,选择符合要求的,然后每个都听一遍.最后选出一个合适的.

我的要求

我是用来朗读技术文章的,文章中要英文也有中文,所以我要选择支持中英文的发音人。发音人列表 符合我条件的发音人如下:

名称属性语言参数名称引擎参数备注小燕青年女声中英文(普通话)xiaoyan默认小宇青年男声中英文(普通话)xiaoyu小研青年女声中英文(普通话)vixy小琪青年女声中英文(普通话)vixqxiaoqi小峰青年男声中英文(普通话)vixf 无法直接循环下载

下面写个demo,要求输入一段文字,然后使用上述的多个发音人分别来合成.下载下来我再一个个的听,选出一个英文清晰,阅读节奏合适的发音人. 因为要批量下载,我首先想到的是,循环调用下载方法不就行了如下所示:

for (......){// 3.创建一个SpeechSynthesizer对象SpeechSynthesizer mTts = SpeechSynthesizer.createSynthesizer();// 4.设置合成参数......mTts.synthesizeToUri(Input, fileName, synthesizeToUriListener);}

但是我失败了,这样并不会合成多个音频。只会合成一个。经过测试之后,我发现,调用完毕下载方法后,主线程就结束了. …最后经过一番思索解决方案如下.

创建下载线程

线程的知识我有点忘了,合成音频的方法最后会回调onSynthesizeCompleted这个方法,我在下载线程DemoListRunable中设置一个isEnd标记,当开始下载一个音频的时候,把isEnd设置为flase,下载完毕后设置为true. 在主线程中,通过不断的来查询这个标记,从而知道是否下载完毕。

package demo;import com.iflytek.cloud.speech.SpeechConstant;import com.iflytek.cloud.speech.SpeechError;import com.iflytek.cloud.speech.SpeechSynthesizer;import com.iflytek.cloud.speech.SynthesizeToUriListener;public class DemoListRunable implements Runnable{public static boolean isEnd=false;String fileName;String Input;String voiceName;public DemoListRunable(String voiceName, String fileName, String Input){this.voiceName = voiceName;this.fileName = fileName;this.Input = Input;}public void run(){// 3.创建一个SpeechSynthesizer对象SpeechSynthesizer mTts = SpeechSynthesizer.createSynthesizer();// 4.合成参数设置,详见《MSC Reference Manual》SpeechSynthesizer 类// 设置发音人// 小燕 青年女声 中英文(普通话) xiaoyan 默认// 小研 青年女声 中英文(普通话) vixy// 小琪 青年女声 中英文(普通话) vixq xiaoqi// 小宇 青年男声 中英文(普通话) xiaoyu// 小峰 青年男声 中英文(普通话) vixf// 4-1 设置发音人mTts.setParameter(SpeechConstant.VOICE_NAME, voiceName);//// 设置要下载的文件名mTts.setParameter(SpeechConstant.SPEED, "50");// 设置语调,范围0~100mTts.setParameter(SpeechConstant.PITCH, "50");// 设置音量,范围0~100mTts.setParameter(SpeechConstant.VOLUME, "50");// TODO Auto-generated method stubSystem.out.println(" 正在合成 " + fileName.substring(0, fileName.lastIndexOf("."))+ " 朗读样例" + " 下载位置:" + fileName);mTts.synthesizeToUri(Input, fileName, synthesizeToUriListener);}// 1 设置合成监听器static SynthesizeToUriListener synthesizeToUriListener = new SynthesizeToUriListener(){// progress为合成进度0~100public void onBufferProgress(int progress){}// 会话合成完成回调接口// uri为合成保存地址,error为错误信息,为null时表示合成会话成功public void onSynthesizeCompleted(String uri, SpeechError error){//表明下载完成isEnd=true;if(error==null)System.out.println(" 合成成功");else System.out.println(" 合成失败");}@Overridepublic void onEvent(int arg0, int arg1, int arg2, int arg3, Object arg4,Object arg5){// TODO Auto-generated method stub}};} 主线程 package demo;import java.util.Scanner;import com.iflytek.cloud.speech.SpeechConstant;import com.iflytek.cloud.speech.SpeechUtility;import replace.Replace;public class DemoList{static Scanner scanner = new Scanner(System.in);public static void main(String[] args){// 2 将“XXXXXXXX”替换成您申请的APPIDSpeechUtility.createUtility(SpeechConstant.APPID + "=XXXXXXXX");// 5设置要合成的文本System.out.println("######################################## 讯飞语音合成系统 ########################################");System.out.println("输入要合成的文字(以: "#exit"作为结束符):");StringBuffer sbBuffer = new StringBuffer(10240);String line = null;while (scanner.hasNext()){line = scanner.nextLine();if ("#exit".equals(line)){break;}sbBuffer.append(line.concat(" "));}System.out.println("---------------------------------- 特殊字符处理 ----------------------------------");// 处理输入文本,替换容易读错的特殊字符.String Input = Replace.replaceTitle(sbBuffer.toString());Input = Replace.replaceEnglish(Input);System.out.println(Input);System.out.println("---------------------------------- 特殊字符处理 ----------------------------------");String[] fileNameArr = new String[]{"小燕xiaoyan.pcm", "小研vixy.pcm", "小琪vixq.pcm", "小宇xiaoyu.pcm","小峰vixf.pcm"};String[] voiceNameArr = new String[]{"xiaoyan", "vixy", "vixq", "xiaoyu", "vixf"};for (int i = 0; i

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。