用java读取wav文件

use*_*269 4 java audio file wav

我是一个完全的java新手,谁能告诉我下面代码中wav文件名的位置,我的文件名是“p.wav”,它的位置是D:/p.wav;请帮助,我收到以下错误-:

线程“main”java.lang.Error 中的异常:

未解决的编译问题:

WavFile 无法解析为类型

WavFile 无法解析

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);
  }
Run Code Online (Sandbox Code Playgroud)

} }

Sio*_*733 5

您需要从这里下载 java 文件并将它们添加到与您的代码相同的包中。

然后改变这一行:

WavFile wavFile = WavFile.openWavFile(new File(args[0]));
Run Code Online (Sandbox Code Playgroud)

到:

WavFile wavFile = WavFile.openWavFile(new File("D:/p.wav"));
Run Code Online (Sandbox Code Playgroud)