2015-02-05 5 views
0

TextTo 음성 작동하지 않습니다. 서비스가 시작되지 않았으며 google play.it에서 음성 텍스트를 설치했음을 보여줍니다. 버튼으로 연결되었을 때 올바르게 작동했지만 onCreate에서 이동할 때 작동하지 않습니다. (가) .IT 바운드 TTS 엔진 successfulu 및 표시 텍스트 길이TextToSpeech 서비스가 시작되지 않았습니다.

public class MainActivity extends Activity implements SensorEventListener{ 
    private ImageView image; 

    // record the compass picture angle turned 
    private float currentDegree = 0f; 

    // device sensor manager 
    private SensorManager mSensorManager; 

    TextView tvHeading; 

    Campus_guide_Databasehelper cgh; 
    float []array=new float[50]; 
    Button btnShowLocation; 
    Button addLocation; 
    Button btnshow; 
    Button btnNearest_point; 
    EditText lat; 
    EditText longi; 
    EditText texte; 
    TextToSpeech ttsobj; 
    float bearing; 
    // GPSTracker class 
    GPSTracker gps; 
    Location location; 
    Location curr_loc; 
    Location dest_loc; 
    double latitude; 
    double longitude; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.compass); 
     cgh=new Campus_guide_Databasehelper(this); 

     gps = new GPSTracker(MainActivity.this); 
     image = (ImageView) findViewById(R.id.imageViewCompass); 

     // TextView that will tell the user what degree is he heading 
     tvHeading = (TextView) findViewById(R.id.tvHeading); 

     // initialize your android device sensor capabilities 
     mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); 

     ttsobj=new TextToSpeech(getApplicationContext(),new TextToSpeech.OnInitListener() { 

     @Override 
     public void onInit(int status) { 
      // TODO Auto-generated method stub 
      if(status==TextToSpeech.SUCCESS) 
      { 
       int result=ttsobj.setLanguage(Locale.US); 
       if(result==TextToSpeech.LANG_MISSING_DATA || result==TextToSpeech.LANG_NOT_SUPPORTED) 
       { 
        Log.e("TTS","This Language is Not supported"); 
        Intent installation=new Intent(); 
        installation.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
        startActivity(installation); 
       } 
       else{ 
        Log.e("TTS","Installation Failed"); 
       } 
      } 

     } 
     }); 

     ttsobj.speak("speak some thing",TextToSpeech.QUEUE_FLUSH, null); 
     // check if GPS enabled  
     if(gps.canGetLocation()){ 

     latitude = gps.getLatitude(); 
     longitude = gps.getLongitude(); 
     latitude=Math.round(latitude*1000000.0)/1000000.0; 
     longitude=Math.round(longitude*1000000.0)/1000000.0; 
     curr_loc=new Location(" "); 
     dest_loc=new Location(" "); 
     curr_loc.setLatitude(latitude); 
     curr_loc.setLongitude(longitude); 
     String data=cgh.Nearest_point(latitude, longitude); 
     String[] split=data.split(":"); 
     for(int i=1;i<split.length;i++) 
     { 
      String [] fur_split=split[i].split(" "); 
      Double llti=Double.parseDouble(fur_split[0]); 
      Double llong=Double.parseDouble(fur_split[1]); 
      dest_loc.setLatitude(llti); 
      dest_loc.setLongitude(llong); 
      bearing=curr_loc.bearingTo(dest_loc); 
      Toast.makeText(this,split[i-1], Toast.LENGTH_LONG).show(); 
      Toast.makeText(this,String.valueOf(bearing), Toast.LENGTH_LONG).show(); 


      ttsobj.speak("text to speech works",TextToSpeech.QUEUE_FLUSH,null); 

      i++; 
     } 
     // \n is for new line 


     Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();  
     }else{ 
     // can't get location 
     // GPS or Network is not enabled 
     // Ask user to enable GPS/network in settings 
     gps.showSettingsAlert(); 
     } 

답변

0

먼저 당신의 else 잘못된 장소에, 그것은 두 번째로 첫 번째 if

ttsobj=new TextToSpeech(getApplicationContext(),new TextToSpeech.OnInitListener() { 

    @Override 
    public void onInit(int status) { 
     // TODO Auto-generated method stub 
     if(status==TextToSpeech.SUCCESS) 
     { 
      int result=ttsobj.setLanguage(Locale.US); 
      if(result==TextToSpeech.LANG_MISSING_DATA || result==TextToSpeech.LANG_NOT_SUPPORTED) 
      { 
       Log.e("TTS","This Language is Not supported"); 
       Intent installation=new Intent(); 
       installation.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
       startActivity(installation); 
      } 

     } 
     else{ 
       Log.e("TTS","Installation Failed"); 
      } 
    } 
    }); 

와 일치해야합니다, 당신은 speak를 호출 할 수 없습니다 유엔 까지 onInit이 호출됩니다.

+0

onInit called.logcat 메시지 표시 oninit successfuly 음성 텍스트의 길이 표시 또한 그 이후에는 서비스가 시작되지 않았 음을 나타냅니다. –

+0

어떤 서비스입니까? 귀하의 logcat을 게시하십시오. –

관련 문제