Android开发_TTS技术

来源:互联网 发布:跳过windows update 编辑:程序博客网 时间:2024/05/12 19:47
public class Main extends Activity implements TextToSpeech.OnInitListener, OnClickListener{    private TextToSpeech tts;    private TextView textView;@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);tts = new TextToSpeech(this, this);        Button button = (Button)findViewById(R.id.button);        textView = (TextView)findViewById(R.id.textview);        button.setOnClickListener(this);}public void onClick(View view){tts.speak(textView.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);}@Overridepublic void onInit(int status) {if(status == TextToSpeech.SUCCESS){int result = tts.setLanguage(Locale.US);if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED){Toast.makeText(this, "Language is not available.", Toast.LENGTH_LONG).show();}}}}

0 0
原创粉丝点击