使用Svox实现中文转语音TextToSpeech(TTS)

小米测试通过!

Android默认没有安装TTS数据包,无法文字转语音,而在设置里推荐的语音包是Pico TTS,并不支持中文,如果需要读中文,需要下载另外的第三方语音包,如:eSpeak,Svox,个人建议Svox,eSpeak非常生硬,而且很多汉字都读不出,不支持中英文混读(英文当拼音读)。下载链接自己Google下吧,很多软件市场(推荐360手机助手)都有下载。下载安装后打开设置-语音输入和输出-文字转语音设置,默认引擎选择Svox Classic TTS,勾选Svox Classic TTS,语言选择中文(Yun)或广东话(Svox安装后还要下载安装相应的语言包的,类似插件)。接下来代码就简单了,关键的就两三行:

import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TTSActivity extends Activity {  
    /** Called when the activity is first created. */  
    TextToSpeech tts;  
    Button btn;  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_tts);  
        btn=(Button)findViewById(R.id.btn);  
        tts = new TextToSpeech(this, null);   
        btn.setOnClickListener(new OnClickListener(){  
   
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub  
                tts.speak("测试一下,欢迎光临!110来了!", TextToSpeech.QUEUE_FLUSH, null);  
            }});  
   
    }  
}  


忘记说了,这玩意试用一天,之后咋办看你了。

安装国产的讯飞语音吧,免费。

猜你喜欢

转载自gundumw100.iteye.com/blog/1763948
今日推荐