Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Change your <code>onInit</code> as per below. You'd mistake with that one only.</p> <pre><code>@Override public void onInit(int status) { // TODO Auto-generated method stub if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.ENGLISH); // tts.setPitch(5); // set pitch level // tts.setSpeechRate(0); // set speech speed rate if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "Language is not supported"); } else { } } else { Log.e("TTS", "Initilization Failed"); } } </code></pre> <p>Otherwise, try this working example.</p> <pre><code>public class LocationSampleActivity extends Activity implements OnInitListener { TextView tv; private TextToSpeech tts; Location speakLoc; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView)this.findViewById(R.id.txtLocation); tts = new TextToSpeech(this, this); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener ll = new mylocationlistener(); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll); } private class mylocationlistener implements LocationListener { @Override public void onLocationChanged(Location location) { if (location != null) { Log.d("LOCATION CHANGED", location.getLatitude() + ""); Log.d("LOCATION CHANGED", location.getLongitude() + ""); String str = "\n CurrentLocation: "+ "\n Latitude: "+ location.getLatitude() + "\n Longitude: " + location.getLongitude(); tv.append(str); speak(location); } } @Override public void onProviderDisabled(String provider) { Toast.makeText(LocationSampleActivity.this,"Error onProviderDisabled",Toast.LENGTH_LONG).show(); } @Override public void onProviderEnabled(String provider) { Toast.makeText(LocationSampleActivity.this,"onProviderEnabled",Toast.LENGTH_LONG).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { Toast.makeText(LocationSampleActivity.this,"onStatusChanged",Toast.LENGTH_LONG).show(); } } @Override public void onInit(int status) { // TODO Auto-generated method stub if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.ENGLISH); // tts.setPitch(5); // set pitch level // tts.setSpeechRate(0); // set speech speed rate if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "Language is not supported"); } else { } } else { Log.e("TTS", "Initilization Failed"); } } public void speak(Location lo) { speakLoc = lo; double lat = speakLoc.getLatitude(); double lon = speakLoc.getLongitude(); String speak = "Your location is:" + lat + lon; tts.speak(speak, TextToSpeech.QUEUE_FLUSH, null); } } </code></pre> <p>And, modify this with your needs.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      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