关闭

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

标签: TextToSpeech中文解决讯飞
2487人阅读 评论(0) 收藏 举报
分类:

原文地址: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();                  

}                                                                                                                  

    }                                                                                                                      

}    

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:19729次
    • 积分:392
    • 等级:
    • 排名:千里之外
    • 原创:18篇
    • 转载:16篇
    • 译文:0篇
    • 评论:0条
    文章分类