Guest User

Untitled

a guest
Apr 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public void talk(String text, boolean voiceEnabled) {
  2. System.out.println(text);
  3.  
  4. // Create a new Thread as JLayer is running on the current Thread and will
  5. // make the application lag
  6. Thread thread = new Thread(() -> {
  7. try {
  8. // Create a JLayer instance
  9. AdvancedPlayer player = new AdvancedPlayer(synthesizer.getMP3Data(text));
  10. if (voiceEnabled) {
  11. player.play(); //Plays the TTS audio
  12. System.out.println("Successfully retrieved synthesizer data");
  13. }
  14. else {
  15. }
  16. } catch (IOException | JavaLayerException e) {
  17.  
  18. e.printStackTrace();
  19. }
  20. });
  21. // We don't want the application to terminate before this Thread terminates
  22. thread.setDaemon(false);
  23. // Start the Thread
  24. thread.start();
  25. }
Add Comment
Please, Sign In to add comment