Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't set TTS's paras via button
    primarykey
    data
    text
    <p>I tried to set TTS's paras such as pitch and speech rate by pressing a button, but somehow nothing changes when I pressed it...</p> <p>See the code following, what I planned is that once I press the button <strong>SetPara</strong>, the <strong>_pitch</strong> and <strong>_rate</strong> will be set to 0.5, and</p> <pre><code>tts.setPitch(_pitch); tts.setSpeechRate(_rate); </code></pre> <p>will set TTS's pitch and speech rate to 0.5, but the problem now is that after I pressed the <strong>SetPara</strong> button the pitch and speech rate didn't change...</p> <p>Please help me out :))))</p> <pre><code>package com.example.text2speechtrail; import java.util.Locale; import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity implements TextToSpeech.OnInitListener { /** Called when the activity is first created. */ private TextToSpeech tts; private Button btnSpeak; private EditText txtText; private Button btnSetPara; private EditText getPitch; private EditText getRate; public float _pitch; public float _rate; String _string_pitch = null; String _string_rate = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tts = new TextToSpeech(this, this); btnSpeak = (Button) findViewById(R.id.btnSpeak); btnSetPara = (Button) findViewById(R.id.setPara); txtText = (EditText) findViewById(R.id.txtText); getPitch = (EditText) findViewById(R.id.getPitch); getRate = (EditText) findViewById(R.id.getRate); btnSetPara.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { SetPara(); } }); // button on click event btnSpeak.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { speakOut(); } }); } public void SetPara(){ _pitch = (float) 0.5; _rate = (float) 0.5; } @Override public void onDestroy() { // Don't forget to shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.onDestroy(); } @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.ENGLISH); tts.setPitch(_pitch); tts.setSpeechRate(_rate); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "This 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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload