2012-06-17 2 views
6

문서의 텍스트를 읽는 앱을 개발 중이며 일시 중지 및 기능을 추가하고 싶지만 TTS에서 pause() 메소드를 찾을 수 없습니다. 내가 멈출 수있는 방법이 있니?.TTS에서 일시 중지 android

답변

5

일시 중지 할 수있는 방법이 있습니다. TextToSpeech.playSilence()으로 전화 하시려면 here에서 아래 코드를 참조하십시오.

일부 침묵과 함께 실제 텍스트를 말합니다.

private void playScript() 
{ 
    Log.d(TAG, "started script"); 
// setup 

// id to send back when saying the last phrase 
// so the app can re-enable the "speak" button 
HashMap<String, String> lastSpokenWord = new HashMap<String, String>(); 
lastSpokenWord.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, 
     LAST_SPOKEN); 

// add earcon 
final String EARCON_NAME = "[tone]"; 
tts.addEarcon(EARCON_NAME, "root.gast.playground", R.raw.tone); 

// add prerecorded speech 
final String CLOSING = "[Thank you]"; 
tts.addSpeech(CLOSING, "root.gast.playground", 
     R.raw.enjoytestapplication); 

// pass in null to most of these because we do not want a callback to 
// onDone 
tts.playEarcon(EARCON_NAME, TextToSpeech.QUEUE_ADD, null); 
tts.playSilence(1000, TextToSpeech.QUEUE_ADD, null); 
tts.speak("Attention readers: Use the try button to experiment with" 
     + " Text to Speech. Use the diagnostics button to see " 
     + "detailed Text to Speech engine information.", 
     TextToSpeech.QUEUE_ADD, null); 
tts.playSilence(500, TextToSpeech.QUEUE_ADD, null); 
tts.speak(CLOSING, TextToSpeech.QUEUE_ADD, lastSpokenWord); 

}

3

TextToSpeech 클래스는, 당신은 TTS의 utterence이 완료되면 청취자를 연결 한 다음 두 번째 utterence, 또는 일시 정지를 시작할 수 있도록하는 setOnUtteranceCompletedListener (나에 대한 API 레벨 15 + setOnUtteranceProgressListener)를 추가 할 수있는 기능을 가지고 또는 무엇이든 필요합니다.

관련 문제