私はビューページャ、およびすべてのページにいくつかのテキストを持っているが、私は、ボタンを押してテキストを音声に変換するイベントで、ボタンを持っている私が知っているテキスト読み上げビューページャ
火事ですどのようにテキストを音声に変換を使用しますが、それはviewPagerに来るとき、私は知らないする
コード:
パブリッククラスMainActivityアクティビティが TextToSpeech.OnInitListener {
を実装して拡張private TextToSpeech tts; private Button btnSpeak; private EditText txtText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tts = new TextToSpeech(this, this); btnSpeak = (Button) findViewById(R.id.btnSpeak); txtText = (EditText) findViewById(R.id.txtText); // button on click event btnSpeak.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { speakOut(); } }); } @Override public void onDestroy() { // Don't forget to shutdown! if (tts != null) { tts.stop(); tts.shutdown(); } super.onDestroy(); } @Override public void onInit(int status) { // TODO Auto-generated method stub if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.US); // tts.setPitch(5); // set pitch level // tts.setSpeechRate(2); // set speech speed rate if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "Language is not supported"); } else { btnSpeak.setEnabled(true); speakOut(); } } else { Log.e("TTS", "Initilization Failed"); } } private void speakOut() { String text = txtText.getText().toString(); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); }
}
- viewpagerでこれを実装し、話す方法(変換)ページ