Guest User

Untitled

a guest
Jan 9th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package com.mrgreaper.twisted.handlers;
  2.  
  3. import com.sun.speech.freetts.Voice;
  4. import com.sun.speech.freetts.VoiceManager;
  5.  
  6. //this is one of the most complicated bits, we have to put the speech into its own thread or we hang the program, this means timing will be important for cc users :(
  7. //it also means if two cc`s start a sentence at the exact same nano second we will get only one of them...odds are slim that will be an issue but untill i can test in a
  8. //playable enviroment i cant really see if its an issue issue or ignorable and at this point cc doesnt even have a 1.7.2 api 08/1/14
  9.  
  10. public class speechThreaded implements Runnable{
  11.  
  12. public static double vVoice;
  13. public static float vPitch;
  14. public static float vPitchRange;
  15. public static float vPitchShift;
  16. public static String vSentence;
  17.  
  18. public static void speechSynth(double vVoice2,float vPitch2,float vPitchRange2,float vPitchShift2,String vSentence2 ) {
  19. vVoice = vVoice2;
  20. vPitch = vPitch2;
  21. vPitchRange = vPitchRange2;
  22. vPitchShift=vPitchShift2;
  23. vSentence = vSentence2;
  24. System.out.println(" set the values to "+vVoice+" "+vPitch+" "+vPitchRange+" "+vPitchShift+" "+vSentence);
  25.  
  26.  
  27. Thread t1 = new Thread(new speechThreaded());
  28.  
  29. t1.start();
  30. // try { //rejoining the thread causes the application to hang while the thread does its work (after all thats what join does! but that causes issues the same as we had before
  31. // t1.join();
  32. // } catch (InterruptedException e) {
  33. // // TODO Auto-generated catch block
  34. // e.printStackTrace();
  35. // }
  36.  
  37. }
  38.  
  39. @Override
  40. public void run() {
  41. System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
  42. System.out.println(" about to try "+vVoice+" "+vPitch+" "+vPitchRange+" "+vPitchShift+" "+vSentence);
  43. try {
  44. String VOICENAME = "kevin16";
  45. if (vVoice == 1) {VOICENAME = "kevin";}; //for now we wont use the low quality one, it would proberly not be used much and thus the removal of an augment will help players
  46. if (vVoice == 2) {VOICENAME = "kevin16";};
  47. //if (vVoice == 3) {VOICENAME = "alan";}; //REMed out as alan can only talk about the time
  48. Voice voice;
  49. VoiceManager vm= VoiceManager.getInstance();
  50. voice=vm.getVoice(VOICENAME);
  51. voice.allocate();
  52. voice.setPitch(vPitch);
  53. voice.setPitchRange(vPitchRange);
  54. voice.setPitchShift(vPitchShift);
  55. voice.speak(vSentence);
  56. return;
  57. } catch (Exception e) {
  58. // TODO Auto-generated catch block
  59. e.printStackTrace();
  60. }
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment