Question

I am a complete newbie in java can someone tell me where to put the wav file name in the following code ,my file name is "p.wav" and its location is D:/p.wav; plz help ,i am getting the following error-:

Exception in thread "main" java.lang.Error:

Unresolved compilation problems:

WavFile cannot be resolved to a type

WavFile cannot be resolved

import java.io.*;

public class ReadExample
{

   public static void main(String[] args)
{

  try
  {
     // Open the wav file specified as the first argument
     WavFile wavFile = WavFile.openWavFile(new File(args[0]));

     // Display information about the wav file
     wavFile.display();

     // Get the number of audio channels in the wav file
     int numChannels = wavFile.getNumChannels();

     // Create a buffer of 100 frames
     double[] buffer = new double[100 * numChannels];

     int framesRead;
     double min = Double.MAX_VALUE;
     double max = Double.MIN_VALUE;

     do
     {
        // Read frames into buffer
        framesRead = wavFile.readFrames(buffer, 100);

        // Loop through frames and look for minimum and maximum value
        for (int s=0 ; s<framesRead * numChannels ; s++)
        {
           if (buffer[s] > max) max = buffer[s];
           if (buffer[s] < min) min = buffer[s];
        }
     }
     while (framesRead != 0);

     // Close the wavFile
     wavFile.close();

     // Output the minimum and maximum value
     System.out.printf("Min: %f, Max: %f\n", min, max);
  }
  catch (Exception e)
  {
     System.err.println(e);
  }

} }

Was it helpful?

Solution

You need to download the java files from HERE and add them to the same package as your code.

then change this line:

WavFile wavFile = WavFile.openWavFile(new File(args[0]));

to:

WavFile wavFile = WavFile.openWavFile(new File("D:/p.wav"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top