Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void talk(String text, boolean voiceEnabled) {
- System.out.println(text);
- // Create a new Thread as JLayer is running on the current Thread and will
- // make the application lag
- Thread thread = new Thread(() -> {
- try {
- // Create a JLayer instance
- AdvancedPlayer player = new AdvancedPlayer(synthesizer.getMP3Data(text));
- if (voiceEnabled) {
- player.play(); //Plays the TTS audio
- System.out.println("Successfully retrieved synthesizer data");
- }
- else {
- }
- } catch (IOException | JavaLayerException e) {
- e.printStackTrace();
- }
- });
- // We don't want the application to terminate before this Thread terminates
- thread.setDaemon(false);
- // Start the Thread
- thread.start();
- }
Add Comment
Please, Sign In to add comment