2016-09-27 1 views
-3
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_image_preview); 
     touch_color = (TextView) findViewById(R.id.touch_color); 


     picTaken = (ImageView) findViewById(R.id.picTaken); 

     // bitmap = fixRotation(MainActivity.IMG_FILE); 
     //picTaken.setImageBitmap(bitmap); 

     String toSpeak = touch_color.getText().toString(); 
     t1.speak(toSpeak, TextToSpeech.QUEUE_ADD, null); 


     t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { 
      @Override 
      public void onInit(int status) { 
       if (status != TextToSpeech.ERROR) { 
        t1.setLanguage(Locale.US); 
        t1.setLanguage(Locale.UK); 

       } 

      } 
     }); 

    } 

    public void onPause() { 
     if (t1 != null) { 
      t1.stop(); 
      t1.shutdown(); 
     } 
     super.onPause(); 
    } 

Run c 

나는 실제로 원하는 텍스트를 사용하여 안드로이드의 버튼을 클릭하지 않고 텍스트 필드를 읽고 싶습니다. 활동이 시작될 때 텍스트가 음성 변환기로 표시됩니다. 텍스트보기 textfield에서 누구든지 도울 수 있습니까? 이 코드를 사용했지만 오류가 발생합니다.이 코드 줄을 "t1.speak (toSpeak, TextToSpeech.QUEUE_FLUSH, null);" 도와주세요.안드로이드에서 새로운 활동을 시작하면 텍스트를 음성으로 변환합니다.

+1

질문 요청하는 방법을 여기 봐 : http://stackoverflow.com/help/how-to-ask – 476rick

+0

여기를 참조 http://www.androidhive.info/2012/01/android-text-을 –

+0

...'실행 c' ?? 그게 뭐야?! –

답변

0

사용할 수 있습니다. link, 유용한 텍스트 정보가 있습니다.

private void promptSpeechInput() { 
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); 
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, 
      getString(R.string.speech_prompt)); 
    try { 
     startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); 
    } catch (ActivityNotFoundException a) { 
     Toast.makeText(getApplicationContext(), 
       getString(R.string.speech_not_supported), 
       Toast.LENGTH_SHORT).show(); 
    } 
} 
0

다음 코드 스 니펫을 사용하여 텍스트 음성 변환 도구를 구현할 수 있습니다.

public class MainActivity extends Activity { 
TextToSpeech t1; 
EditText ed1;  
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    ed1=(EditText)findViewById(R.id.editText);  
    t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { 
    @Override 
    public void onInit(int status) { 
     if(status != TextToSpeech.ERROR) { 
      t1.setLanguage(Locale.UK); 
     } 
    } 
    }); 


    String toSpeak = ed1.getText().toString(); 
    Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show(); 
    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null); 

} 

public void onPause(){ 
    if(t1 !=null){ 
    t1.stop(); 
    t1.shutdown(); 
    } 
    super.onPause(); 
} 
} 
+0

작동하지 않습니다. –

+0

어떤 문제가 있습니까? – Jaydroid

+0

t1.speak (toSpeak, TextToSpeech.QUEUE_FLUSH, null); 대기열이없고 항목이 변경되지 않아이 줄을 변경해야합니다. –