TTS文字转语音工具汇总



1.谷歌翻译的TTS

通过网络调用

http://translate.google.com/translate_tts?tl=zh&q=URL转码的文字

tl属性:语言种类,可以更改,如en,zh

q属性:文本,需要URL转码。

返回的是mpeglayer3?音频文件。


问题1:

页面使用js的window.open(url,name,param)打开新窗口,或者iframe跳转,发现url汉字部分总是乱码。

解决办法:

后来在页面添加encodePage=utf-8解决了。


问题2:

使用window.open打开的页面,不能自动播放google tts语音,必须手动在地址栏按下回车才有,url参数变化,又不能自动播放。

原因:

我所使用的是FireFox浏览器,会自动携带referer,google对http请求头的referer进行了屏蔽,可以参见此文:Google Text-To-Speech

......

Another restriction is that the service returns 404 Not Found if the request includes a Referer header (presumably one that is not for translate.google.com).

In spite of the limitations of the web service which certainly reflect the intention that the web service is only to be used by Google Translate, thanks to the new HTML5's Audio element and rel="noreferrer", the service may be utilized by client-side web applications like following (Google Chrome 4 recommended):
......

解决办法:TMD找不到阿...


2.讯飞语音API

网址:自己百度

申请比较容易,注册帐号然后新建相应平台的程序就可以得到appid,类似微博token一样用于验证的东东。

下载相关平台的SDK,将lib中的jar包导入eclipse项目,其中还有些批处理文件,.so是linux平台用的,.dll是windows平台用的,各自对应放好。

基本步骤可以参看SDK中的文档。

以下是一个简单的TTS程序:

import com.iflytek.speech.SpeechError;
import com.iflytek.speech.SynthesizerPlayer;
import com.iflytek.speech.SynthesizerPlayerListener;

public class GetTTS {
    public static void main(String[] args){
        private String appid="填写你得到的appid";  //填写你得到的appid
        private String voiceName= "xiaoyan";     //发音人声
        private int volume = 100;                //发音音量
        private int voiceSpeed = 40;             //发音语速
        private String backgroundSound = null;   //背景音乐,1是一首music
        private String ttsBufferTime = "tts_buffer_time=2000";   //缓冲时间
        private String sentence = "我是大笨蛋";            //你要说的话
    
        //步骤一:获得播放器
        SynthesizerPlayer tts = SynthesizerPlayer.createSynthesizerPlayer("appid=" + appid); 

        //步骤二:获得播放器监听器       
        /**
         * SynthesizerPlayer Listener
         */
        SynthesizerPlayerListener synListener = new SynthesizerPlayerListener() {
            //缓冲
            public void onBufferPercent(int percent, int beginPos, int endPos, String arg) {
                System.out.println("正在缓冲:" + percent);
            }
            //播放结束
            public void onEnd(SpeechError error) {
                if (error == null)
                    System.out.println("播放完成");
                else
                    System.out.println("错误代码:" + error.getErrorCode());
            }
            //开始播放
            public void onPlayBegin() {
            }
            //播放暂停
            public void onPlayPaused() {
            }
            //播放进度
            public void onPlayPercent(int percent, int beginPos, int endPos) {
            }
            //恢复播放
            public void onPlayResumed() {
            }
        };
    
        //步骤三:设置参数
        tts.setVoiceName(voiceName);
        tts.setSpeed(voiceSpeed);
        tts.setVolume(volume);        
        tts.setBackgroundSound(backgroundSound);

        //步骤四:开始说话
        tts.playText(sentence,ttsBufferTime,synListener);
        }
    }
}




转载于:https://my.oschina.net/fantasymaker/blog/229463

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值