2016-02-27 29 views

回答

0

試試這個:

public class YourActivity extends Activity { 
    private TextToSpeech tts; 

    public static void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_your); 

     tts = new TextToSpeech(YourActivity.this, InitListener); 
    } 

    private TextToSpeech.OnInitListener InitListener = new TextToSpeech.OnInitListener() { 
     public void onInit(int status) { 
      if (status == TextToSpeech.SUCCESS) { 
       int res = tts.setLanguage("en", "US", ""); 
       if (res >= TextToSpeech.LANG_AVAILABLE) { 
        String text = "Input text what you want to say."; 
        tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); 
       } 
      } 
     } 
    } 
} 

這個應用程序並不需要用戶界面,並執行應用程序時,會進行語音一次。

相關問題