0

現在の場所を見つけるためのコードがあります。次に、コード内で TextToSpeech を初期化します。しかし、現在の場所のテキストを音声に変換できませんでした。現在の場所の緯度、経度を TextToSpeech に挿入する方法。

マイコード:

public class SpeakActivity extends Activity implements OnInitListener{
         private TextToSpeech tts;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_speak);   

        LocationManager locationManager; 
        String context = Context.LOCATION_SERVICE; 
        locationManager = (LocationManager)getSystemService(context); 

        Criteria crta = new Criteria(); 
        crta.setAccuracy(Criteria.ACCURACY_FINE); 
        crta.setAltitudeRequired(false); 
        crta.setBearingRequired(false); 
        crta.setCostAllowed(true); 
        crta.setPowerRequirement(Criteria.POWER_LOW); 
        String provider = locationManager.getBestProvider(crta, true); 

         //String provider = LocationManager.GPS_PROVIDER; 
        Location location = locationManager.getLastKnownLocation(provider); 
        updateWithNewLocation(location);

        tts = new TextToSpeech(this, this);


    }

    public void say(String text2say){

              tts.speak(text2say, TextToSpeech.QUEUE_FLUSH, null);

            }

    @Override

       public void onInit(int status) {

          say("latLongString");    

       }



       @Override

       public void onDestroy() {

          if (tts!= null) {

             tts.stop();

             tts.shutdown();

          }   

          super.onDestroy();

       }



    private void updateWithNewLocation(Location location) { 
        String latLongString;
        TextView myLocation; 
        myLocation = (TextView) findViewById(R.id.myLocation);



        if(location!=null) { 
        double lat = location.getLatitude(); 
        double lon = location.getLongitude(); 
        latLongString = "Lat:" + lat + "\nLong:" + lon;     

        }else{
            latLongString="no location found";
        }
        myLocation.setText("Your current position is:\n" + latLongString);
        say(latLongString);

    }
4

0 に答える 0