TextToSpeech语音解决中文不能用问题

转载 2015年07月07日 15:31:51

原文地址:http://fklg.iteye.com/blog/1683982


Android 系统自带的TTS (Text To Speak)语音库目前只有English ,German , Italian ,French ,Spanish(英文,德语,意大利语,法语,西班牙语)五个音库.所以中文发音必须要借助其他的软件,或者引擎.近些天研究目前有三个方法可以实现: 

1,一种是借助shoushuotts音库引擎和jar文件在自己的项目中调用.具体方法可查看网址:http://dev.10086.cn/cmdn/bbs/thread-58426-1-1.html 

(经过测试,中文发音很慢,用些多音字和特殊符号无法识别) 

2.是用addr软件,方法同上,要添加两个jar文件.有源代码实例: 

(测试发现,其中文发音是老外的调调,并且严重怀疑他的中文也是老外教的) 

3 安装讯飞语音插件.需要安装两个文件,讯飞语音TTS.apk 和讯飞语音包.apk,不需要jar文件,直接到系统配置 -> 语音输入与输出 --> 文字转语音设置 -->讯飞语音后边打钩(选择后才能设置其他项) -- > 默认引擎(讯飞语音) -->语言(中文) (用必要是还可以在讯飞语音合成里选择男声和女声) 

配置完成后,可直接用系统提供的TextToSpeak的方法直接调用即可. 

(测试发现,改发音是中标准的中文发音,据了解,国内语音识别系统做的最好的一家,发音连贯,并且可辨认符号如℃等) 

示例代码如下: 

    public class NiHaoTTS extends Activity implements OnInitListener {                                                      

                                                                                                                           

private int MY_DATA_CHECK_CODE = 0;                                                                                    

private TextToSpeech tts;                                                                                              

private EditText inputText;                                                                                            

private Button speakButton;                                                                                            

                                                                                                                       

@Override                                                                                                                 

public void onCreate(Bundle savedInstanceState) {                                                                         

                                                                                                                           

  super.onCreate(savedInstanceState);                                                                                      

  setContentView(R.layout.xunfei_tts);                                                                                           

                                                                                                                           

  inputText = (EditText) findViewById(R.id.input_text);                                                                    

  speakButton = (Button) findViewById(R.id.speak_button);                                                                  

  speakButton.setOnClickListener(new OnClickListener() {                                                                   

   @Override                                                                                                               

   public void onClick(View v) 

   {                                                                                           

       String text = inputText.getText().toString();                                                                       

       if (text!=null && text.length()>0) 

       {                                                                                

       Toast.makeText(NiHaoTTS.this, "Saying: " + text, Toast.LENGTH_LONG).show();   

       //开始阅读 text 

       tts.speak(text, TextToSpeech.QUEUE_ADD, null);                                                                         

       }                                                                                                                   

      }                                                                                                                       

         });                                                                                                                  

                                                                                                                           

    Intent checkIntent = new Intent();                                                                                       

        checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);                                                    

        startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);                                                             

    }                                                                                                                      

   protected void onActivityResult(int requestCode, int resultCode, Intent data) {                                            

        if (requestCode == MY_DATA_CHECK_CODE) 

        {                                                                           

            if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) 

            {                                                 

                // success, create the TTS instance                                                                        

            tts = new TextToSpeech(this, this);                                                                        

            }                                                                                                              

            else 

            {                                                                                                         

            // missing data, install it                                                                                

            Intent installIntent = new Intent();                                                                       

            installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);                                      

            startActivity(installIntent);                                                                              

        }                                                                                                              

        }                                                                                                                  

                                                                                                                       

   }                                                                                                                      

                                                                                                                       

@Override                                                                                                              

public void onInit(int status) 

{                                                                                       

    if (status == TextToSpeech.SUCCESS) 

    {                                                                              

        Toast.makeText(NiHaoTTS.this,                                                                               

                "Text-To-Speech engine is initialized", Toast.LENGTH_LONG).show();                                     

    }                                                                                                                  

    else if (status == TextToSpeech.ERROR) 

    {                                                                           

    Toast.makeText(NiHaoTTS.this,                                                                               

            "Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();                  

}                                                                                                                  

    }                                                                                                                      

}    

相关文章推荐

Android TTS(TextToSpeech)语音输出与RecognizerIntent语音识别

一、引言在《Android 4 高级编程(第3版)》第11章中,讲到了语音输出及语音识别。 对语音识别,公司项目中有用到,但是我们用的第三方的(讯飞),由于这块功能不是由我来做,所以也就没有花时间去...

Android TTS 英文或中文(要下载中文支持包)转语音 使用TextToSpeech

语音朗读,这是一个很好的功能,可以实现一些客户的特殊要求。在Android 实现主要功能只需要几段简单的代码即可完成。 在Android中使用语音朗读功能只需要使用此类 TextToSpeech,...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Android TTS 中文 文字转语音 使用TextToSpeech Svox

Android默认没有安装TTS数据包,无法文字转语音,而在设置里推荐的语音包是Pico TTS,并不支持中文,如果需要读中文,需要下载另外的第三方语音包,如:eSpeak,Svox,个人建议Svox...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

Android TextToSpeech多国语言自动朗读

实现的效果如下: 彩色圆角按钮的实现可以参考我的这篇文章http://blog.csdn.net/ldld1717/article/details/52314344 工程的...

文字合成语音TextToSpeech语音解决中文不能用问题

原文地址:http://fklg.iteye.com/blog/1683982 Android 系统自带的TTS (Text To Speak)语音库目前只有English ,German , It...
  • wo_ha
  • wo_ha
  • 2016年11月24日 17:59
  • 606

Text To Speech 总结

前言Android 1.6 加入了文字合成语音的功能,但是 Google 提供的语言库不支持中文。本篇文章总结了几个支持中文的语言库。TextToSpeech在介绍其他语言库之前,先介绍一下 Andr...

使用TextToSpeech语音读取

今天无意见发现Android中有个控件可以实现语音读取,它就是TextToSpeech控件。目前只支持5种语言:English、 French 、 German 、 Italian 和 Spanish...

Android TTS文本转语音TextToSpeech

Android 系统里内置了PicoTTS,对中文的支持很不给力。但是我们可以安装“讯飞语记”TTS,中文就不是问题了。 首先介绍下核心方法speak()及其参数public int speak(f...
  • iblade
  • iblade
  • 2017年02月06日 16:34
  • 1597
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:TextToSpeech语音解决中文不能用问题
举报原因:
原因补充:

(最多只允许输入30个字)