2012-07-16 2 views
0

텍스트를 음성 변환 앱으로 만들고 있습니다. 나는 사용자로부터 텍스트를 가져 와서 음성으로 바꾸고 싶다. 내가 입력 된 텍스트를 하드 코딩했을 때. 내 응용 프로그램이 완벽하게 작동합니다.android eclipse에서 edittext에서 배열 문자열로 텍스트 가져 오기

static final String[] texts = {"what's up dude"}; 
TextToSpeech tts; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Button b = (Button)findViewById(R.id.btexttovoice); 
    b.setOnClickListener(this); 
    tts = new TextToSpeech(textvoice.this,new TextToSpeech.OnInitListener(){ 

     @Override 
     public void onInit(int status) { 
      // TODO Auto-generated method stub 
      if(status!= TextToSpeech.ERROR) 
      { 
       tts.setLanguage(Locale.US); 

      } 
      } 
      }); 
} 

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    if(tts!= null) 
    { 
     tts.stop(); 
     tts.shutdown(); 
    } 
    super.onPause(); 
} 

@Override 
public void onClick(View v) { 
    // TODO Auto-generated method stub 
    Random r = new Random(); 
    String random = texts[r.nextInt(3)]; 
    tts.speak(random, TextToSpeech.QUEUE_FLUSH, null); 
} 

} 그것은 잘 작동하지만 난 텍스트 편집 를 통해 사용자로부터 입력을하려면 나는 다음과 같이 변경합니다 문자 배열 형식이기 때문에 여기에

String[] texts ; 
text = (EditText)findViewById(R.id.ttexttovoice); 
texts = text.getText().toString(); 

내가 오류가 발생합니다. 텍스트를 문자열의 배열 유형으로 편집 텍스트에서 가져올 수 있습니까? 내가 배열 문자열

String texts ; 
text = (EditText)findViewById(R.id.ttexttovoice); 
texts = text.getText().toString(); 

없이이 작업을 수행 할 경우 내가 오류를 얻을하지만 난 원하는 출력을 찾지 못했습니다. 실제로 목소리가 수신되지 않습니다.

간단한 문제인 것처럼 보이지만 여기에 붙어 있습니다. 친절하게 도와주세요. 미리 감사드립니다.

답변

0
String[] texts = new String[3]; 
text = (EditText)findViewById(R.id.ttexttovoice); 
texts[0] = text.getText().toString(); 
+0

고마워요. 이제는 내 프로젝트에 오류가 없지만 음성 변환 버튼을 클릭하면 원하는 출력을 찾을 수 없습니다. 프로젝트가 예기치 않게 닫힙니다. – dan

관련 문제