Tuesday, October 05, 2004

Adding sound to a boring build

Well, the builds that I do at my day job take a couple of minutes and I hate wating for build to complete. So i decided to add a simple voice notification mechanism at the end of the build so that I can go back to poor dos prompt.

I was left with three options:

1. Using optional ant task Sound.
Using sound task is little boring since you need the audio files for what your build process want to say to you. Also this requires modifying the original build which could be annoying for other team members who don't prefer the sound notification.

2. Writing a custom ant task using FreeTTS.
Writing a custom ant task would help me relearn how to write custom ant task as it has been 2 years since i wrote a custom ant task. But the problem is this also requires modifying the original build which could be annoying for other team members who don't prefer the sound notification.

3. Writing a custom logger.
Well this option probably is simplest and doesn't require any change to regular build file. So this works great for me.


Its really amazing how simeple this task is using FreeTTS and Ant. Write a simple logger extending DefaultLogger. Extending DefaultLogger helps because you only need to listen to events that you want to add sound to. Here is my code for providing sound to build complete event:


package org.js.build;

import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.DefaultLogger;

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;


public class FreeTTSLogger extends DefaultLogger {

    public void buildFinished(BuildEvent e)
    {
      //Let default logger do what ever it doing.
        super.buildFinished(e);

        String voiceName = "kevin16";
        //create voice 
        Voice buildVoice = VoiceManager.getInstance().getVoice(voiceName);

        if (buildVoice == null) {
            System.err.println("Cannot load a voice named " + voiceName + ".");
            return;
        }
        //Allocate the resources for the voice.
        buildVoice.allocate();

        /* Synthesize speech based on whether or not build is successful
         */
        if(e.getException() == null)
          buildVoice.speak("Build completed Mr. Kumar.");
        else
          buildVoice.speak("Build failed.");

        //cleanup. Be a good citizen.
        buildVoice.deallocate();

    }

}


For using the logger copile this code into a jar file of its own. You can download my jar file. copy this jar file into lib directory of your ANT_HOME. Now you need to copy FreeTTS libraries (all jars under freetts\lib directory) to ANT_HOME\lib directory. But ant 1.6 and FreeTTS 1.2Beta2, this throws a unexpected Exception:

java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.Vector.toArray(Vector.java:688)
at com.sun.speech.freetts.UniqueVector.toArray(VoiceManager.java:840)
at com.sun.speech.freetts.VoiceManager.getVoiceDirectories(VoiceManager.java:203)
at com.sun.speech.freetts.VoiceManager.getVoices(VoiceManager.java:109)
at com.sun.speech.freetts.VoiceManager.getVoice(VoiceManager.java:519)
at org.js.build.FreeTTSLogger.buildFinished(FreeTTSLogger.java:55)
at org.apache.tools.ant.Project.fireBuildFinished(Project.java:1796)
at org.apache.tools.ant.Main.runBuild(Main.java:693)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)

A simple way to get around this is by copying FreeTTS libraries to JRE\lib\ext directory. Now to use this new logger, just use the command:

ant -logger org.js.build.FreeTTSLogger

5 comments:

Anonymous said...

Awesome. I am going to add the same to my build process.

/Chris

Anonymous said...

The Usual Suspects, right?

Mats

Anonymous said...

Do you know or have you ever heard of Gotting Money from foundation grants ..If you are interested in finding out how to get more info on foundation grants visit us at http://grantsnloans4u.com... There are so many things you can get grants for.. Homes, school, work, business, college..ect.. Find out how everybody is getting money from foundation grants today... Quit living in poverty educate yourself and improve your life..

Anonymous said...

Dear Blogers

Great fallbrook contractors advice can be founf at http://fallbrookremodeling.com/sitemap_1.html . We are starting a home improvement site for home remodeling experts and home owners.

Anonymous said...

Hello General Contractors

One of the most popular home improvements where home improvement contractors come in handy are the re styling of your home. If you really wish to give your home a total professional new style then there are lots of interior designers out there who are very willing to help you re furnish and style you house to get the look that you are looking for. However, the problem is that they tend to be quite expensive even though they are really only consultants. As with any other home improvement project, you're the one that will have to pay for all materials and the hours that the contractors spend telling you how to choose fabrics and so on.

No matter what type of home improvement project you plan on doing - a large or small job, the home improvement contractors you choose will have a great impact on the results you get for your home improvements. Always make sure that you see their certificates and the materials that they use. Do this both before the job is started and while the project is in progress as well. If you don't like something they are doing you have the decision to stop their work.

http://fallbrook.rgcont.com/