【问题标题】:Text To Speech problems文字转语音问题
【发布时间】:2013-02-14 09:21:26
【问题描述】:

我想做一个文字转语音测试应用,看到这个教程:http://android-developers.blogspot.com.es/2009/09/introduction-to-text-to-speech-in.html

我尝试按照教程所说的进行操作,并且我将语言设置为仅西班牙语:

mTts = new TextToSpeech(this, this);
   Locale loc = new Locale ("spa", "ESP");
   mTts.setLanguage(loc);

我也试过这样做(不起作用):

// Specify the exact voice you are checking for
checkIntent.putExtra(TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR,"spa-ESP");

问题是当应用程序启动时,应用程序会提示我到一个屏幕,要求我下载四种语言,德语、西班牙语、法语、意大利语。如果我只下载西班牙语然后按返回键,应用程序可以工作,但每次我启动应用程序时,它都会显示相同的屏幕来下载其他三种语言,并且只有在我下载论坛语言时才会停止出现。

我的目标是提示用户只下载西班牙语,并且只显示一次语言下载对话框,而不是总是显示。

我正在使用 4.1 的 Nexus S 手机上对其进行测试

这是完整的代码:

public class MainActivity extends Activity implements OnInitListener {  
    private static final int MY_DATA_CHECK_CODE = 0;
    EditText editText;
    Button button;
    private TextToSpeech mTts;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editText = (EditText) findViewById(R.id.editText);
    button = (Button) findViewById(R.id.button);    

    editText.setText("Estoy probando, porque hay que probar.");                 

    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

    button.setOnClickListener(new OnClickListener() {           
        @Override
        public void onClick(View v) {
            mTts.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);              
        }
    });
}

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
            mTts = new TextToSpeech(this, this);
            Locale loc = new Locale ("spa", "ESP");
            mTts.setLanguage(loc);
        } else {
            // missing data, install it
            Intent installIntent = new Intent();
            installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);

            mTts = new TextToSpeech(this, this);
            Locale loc = new Locale ("spa", "ESP");
            mTts.setLanguage(loc);
        }
    }
}

@Override
public void onInit(int arg0) {}
}

希望你能帮我找到解决办法

问候

【问题讨论】:

  • 在文本转语音设置下勾选“始终使用我的设置”。

标签: android text-to-speech


【解决方案1】:

您不能使用MARC codes 而是使用ISO-639-1 / ISO-3166-1 代码来创建语言环境:Locale loc = new Locale ("es");。另请参阅Locale class reference 中的“类概述”部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    相关资源
    最近更新 更多