free web hosting | website hosting | Business Web Hosting | Free Website Submission | shopping cart | Coaching Institute | php hosting
affordable web hosting Pets web page hosting web hosting website hosting web hosting service web hosting web host
Processing a sound file (in WAVE format) in Java

Processing a sound file (in WAVE format) in Java

Once the data is safely retrieved from the sound file and is saved into a buffer, editing the data is easy. Just treat the buffer the same way as ordinary text buffer.

The wave form probably is the most familiar way to represent the sound wave. Shown on the applet screen is a recording of a human voice (short phrases with a pause in between each phrase).

Now let's edit and analyze this data. Take a look at WavSplit applet below. This applet processes the sound clip data and cut it into segments according to the algorithm below.

The function split(int threshold, int interval, int duration) takes three parameters and seeks clusters that should represent words. It looks for below-threshold period longer than the value of duration and above-threshold period longer than the value of interval.

    byte buf[];
    int length=buf.length;  

    public void split(int threshold, int interval, int duration)
    {	
	int k=0;
	int start=0,end=0;
	do
	    {
	        // loops above threshold values appear
		while(Math.abs(buf[k])<threshold && ++k<length);

		// if the above threshold value is found
		if(k<length)
		    {
			start=k;
			end=k;

			// loops until it founds out below 
			// threshold period longer than duration value
			while((Math.abs(buf[k])>threshold || k-end<duration) 
			       && ++k<length)
			    {
				if(Math.abs(buf[k])>threshold)
				    end=k;
			    }

			// if the above threshold period is longer than interval value 
			// and below threshold period is longer than duration value
			if(end-start>interval && (k-end>=duration || k>=length))
			    {
				add(new Segment(start, end));
			    }
		    }
	    }
	while(++k<length);	    
    }

Try out the effects of these three parameters yourself. Enter the values into the boxes in the WavSplit applet and press OK. Please be sure to turn off browser blocking (select "Allow Blocked Content..." if you are using InternetExplorer) before running this applet.


Return to Home Page
Erica Asai
Last Modified: Tue Dec 14 01:58:12 2004