public static void listAllVoices() { System.out.println(); System.out.println("All voices available:"); VoiceManager voiceManager = VoiceManager.getInstance(); Voice[] voices = voiceManager.getVoices(); for (int i = 0; i < voices.length; i++) { System.out.println(" " + voices[i].getName() + " (" + voices[i].getDomain() + " domain)"); } }
public static void main(String[] args) { VoiceManager voiceManager = VoiceManager.getInstance(); Voice helloVoice = voiceManager.getVoice(VOICE_NAME); if (helloVoice == null) { System.err.println( "Cannot find a voice named " + VOICE_NAME + ". Please specify a different voice."); return; } helloVoice.allocate(); helloVoice.speak("Thank you for giving me a voice. I'm so glad to say hello to this world."); helloVoice.deallocate(); }
@SuppressWarnings("unused") public static int speak( String msg, Double rate, Double pitch, Double range, Double shift, Double volume) { System.setProperty( "freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory"); VoiceManager voiceManager = VoiceManager.getInstance(); com.sun.speech.freetts.Voice voice = voiceManager.getVoice("kevin16"); System.out.println("Rate " + voice.getRate()); System.out.println("Pitch hertz " + voice.getPitch()); System.out.println("PitchRange " + voice.getPitchRange()); System.out.println("PitchShift " + voice.getPitchShift()); System.out.println("Volume " + voice.getVolume()); if (voice != null) { voice.setRate(rate.floatValue()); voice.setPitch(pitch.floatValue()); voice.setPitchRange(range.floatValue()); voice.setPitchShift(shift.floatValue()); voice.setVolume(volume.floatValue()); voice.allocate(); voice.speak(msg); voice.deallocate(); } else { System.out.println("All voices available:"); com.sun.speech.freetts.Voice[] voices = voiceManager.getVoices(); for (int i = 0; i < voices.length; i++) { System.out.println( " " + voices[i].getName() + " (" + voices[i].getDomain() + " domain)"); } } // WordNumSyls feature = // (WordNumSyls)voice.getFeatureProcessor("word_numsyls"); // if(feature!=null) // try { // // System.out.println("Syllables# = "+feature.process(null)); // } catch (ProcessException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // return 0; }
private void constructVoice() { /* The VoiceManager manages all the voices for FreeTTS. */ VoiceManager voiceManager = VoiceManager.getInstance(); String voiceName = "mbrola_us1"; Voice[] vs = voiceManager.getVoices(); for (Voice v : vs) { System.out.println(v.getName()); } voice = voiceManager.getVoice(voiceName); if (voice == null) { System.err.println( "Cannot find a voice named " + voiceName + ". Please specify a different voice."); System.exit(1); } /* Allocates the resources for the voice. */ voice.allocate(); }
public void read() { int i, j, k; String temp = ""; String temp1 = ""; msg = s3.toCharArray(); for (i = 0; i < s3.length(); i++) { try { dos.write(msg[i]); // System.out.println(msg[i]); } catch (Exception e) { System.out.print("read send" + e); } } try { while ((rs = dis.readLine()) != null) { temp += rs; if (rs.equals("OK")) break; if (rs.equals("ERROR")) break; } k = 0; StringTokenizer t = new StringTokenizer(temp, "\""); while (t.hasMoreTokens()) { temp1 = "" + t.nextToken().trim(); k++; if (k == 7) { System.out.println(temp1); VoiceManager voiceManager = VoiceManager.getInstance(); Voice helloVoice = voiceManager.getVoice("kevin"); helloVoice.allocate(); helloVoice.speak(temp1); helloVoice.deallocate(); } } } catch (Exception e) { System.out.print("read rec" + e); } }
public void initializeVoice() { // listAllVoices(); voice = voiceManager.getVoice("kevin16"); voice.setDurationStretch(1.0f); /* * voice.setPitch(100.0f); voice.setPitchRange(11.0f); * voice.setPitchShift(1.0f); voice.setDurationStretch(1.0f); */ voice.setPitch(100.0f); voice.setPitchRange(11.0f); voice.setPitchShift(1.0f); voice.setDurationStretch(1f); // System.out.println() voice.allocate(); }
public void listAllVoices() { VoiceManager voiceManager = VoiceManager.getInstance(); Voice[] voices = voiceManager.getVoices(); }
public class Snitcher implements ActionListener { VoiceManager voiceManager = VoiceManager.getInstance(); Voice voice = null; static Random random = new Random(); SnitcherView view = null; private boolean running = true; private JenkinsMonitor monitor = new JenkinsMonitor(); private int iterationDelay = 1000; private Timer timer = new Timer(iterationDelay, this); private ArduinoSnitcher arduino = new ArduinoSnitcher(); private String host = null; private String comPort = null; private int iterationsBetweenQuery = 2; private int currentIterations = 0; /** @param args */ @SuppressWarnings("unchecked") public void readSettingsFromXML() { String settingsFilename = "snitcher.xml"; File xml = new File(settingsFilename); if (!xml.exists()) { createDefaultXMLFile(settingsFilename); } try { SAXReader reader = new SAXReader(); Document doc; doc = reader.read(xml); Element root = doc.getRootElement(); comPort = root.elementText("com"); host = root.elementText("host"); System.out.println("Monitoring: " + host); System.out.println("Arduino on: " + comPort); Element projectsElement = root.element("projects"); List<Element> projects = (List<Element>) projectsElement.elements("project"); for (Element project : projects) { System.out.println("Project: " + project.elementText("display")); addProject( new JenkinsProject( host, project.elementText("display"), project.elementText("jenkins"))); } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } monitor.sortProjects(); arduino.initialize(comPort); } private void addProject(JenkinsProject project) { monitor.addProject(project); } private void createDefaultXMLFile(String settingsFilename) { try { FileOutputStream fos = new FileOutputStream(settingsFilename); OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8"); out.write( "<snitcher>\n" + " <host>http://winhudson.stonethree.com:8080</host>\n" + " <com>COM14</com>\n" + " <projects>\n" + " <project>\n" + " <display>Lynxx</display>\n" + " <jenkins>Lynxx</jenkins>\n" + " </project>\n" + " <project>\n" + " <display>Froth Sensor</display>\n" + " <jenkins>FrothSensor</jenkins>\n" + " </project>\n" + " </projects>\n" + "</snitcher>\n"); out.close(); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public Snitcher() { view = new SnitcherView(this); view.createAndShowGUI(); readSettingsFromXML(); addProjectsToView(); view.setVisible(true); initializeVoice(); timer.start(); monitor.updateStatus(); } private void addProjectsToView() { for (JenkinsProject project : monitor.projects) { System.out.println("Adding: " + project.getName()); view.addProject(project); } } public void start() { while (running) { int offset = 0; boolean buildInterrupted = false; boolean buildFailed = false; boolean building = false; List<String> blames = new ArrayList<String>(); String sayString = ""; try { for (JenkinsProject project : monitor.projects) { if (project.isBuilding()) { // arduino.setChannelToState(offset, // ProjectState.BUILDING); building = true; } else if (project.getStatus().equals("SUCCESS")) { // arduino.setChannelToState(offset, // / ProjectState.BUILD_SUCCEEDED); } else if (project.getStatus().equals("ABORTED")) { // arduino.setChannelToState(offset, // ProjectState.BUILD_INTERRUPTED); buildInterrupted = true; } else { // arduino.setChannelToState(offset, // ProjectState.BUILD_FAILED); buildFailed = true; String person = project.getLastUser(); if ((!person.equals("anonymous")) && (!blames.contains(person))) { blames.add(person); } } if (project.mustNotify()) { if (sayString.equals("")) { sayString = "Attention please! "; } String notifyString = project.getNotifyString(); sayString += notifyString + "! "; project.setNotified(true); } offset += 1; } ProjectState serverState = ProjectState.BUILD_SUCCEEDED; if (buildFailed) { serverState = ProjectState.BUILD_FAILED; } if (!sayString.equals("")) { say(sayString); } view.setBlames(blames); arduino.setChannelToState(0, serverState); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } arduino.sendStatus(); // view.update(); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void listAllVoices() { System.out.println(); System.out.println("All voices available:"); VoiceManager voiceManager = VoiceManager.getInstance(); Voice[] voices = voiceManager.getVoices(); for (int i = 0; i < voices.length; i++) { System.out.println(" " + voices[i].getName() + " (" + voices[i].getDomain() + " domain)"); } } public void initializeVoice() { // listAllVoices(); voice = voiceManager.getVoice("kevin16"); voice.setDurationStretch(1.0f); /* * voice.setPitch(100.0f); voice.setPitchRange(11.0f); * voice.setPitchShift(1.0f); voice.setDurationStretch(1.0f); */ voice.setPitch(100.0f); voice.setPitchRange(11.0f); voice.setPitchShift(1.0f); voice.setDurationStretch(1f); // System.out.println() voice.allocate(); } /* * public void start() { * * say("Started"); * * while (running) { System.out.println("Check"); * * * try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO * Auto-generated catch block e.printStackTrace(); } } } */ public void say(String text) { System.out.println("Stitcher: " + text); voice.speak(text); } public void destroy() { System.out.println("Destroy called!"); view.dispose(); running = false; voice.deallocate(); timer.stop(); arduino.close(); } String secondsToTimeString(int milliseconds) { int minutes = milliseconds / 60000; int seconds = (int) (milliseconds / 1000) % 60; return minutes + " minutes and " + seconds + " seconds"; } public static void main(String[] args) { // Schedule a job for event dispatch thread: // creating and showing this application's GUI. final Snitcher snitcher = new Snitcher(); snitcher.start(); } @Override public void actionPerformed(ActionEvent arg0) { if (currentIterations > iterationsBetweenQuery) { monitor.updateStatus(); currentIterations = 0; } currentIterations += 1; } }