Java audio recording noise in completely quite room

485 views Asked by At

I'm trying audio recording with java. And the quality is not good at all. There is a continuous noise, even though it is completely quite here in the room. Any chance to remove/filter the noise?

I've discovered the same issue on cheap android phone and some recording app. Looks like it is general issue with audio recording

package test;

import javax.sound.sampled.*;
import java.io.*;

public class Tmp {

    AudioFileFormat.Type fileType = AudioFileFormat.Type.WAVE;


    AudioFormat getAudioFormat() {
        float sampleRate = 44100;
        int sampleSizeInBits = 16;
        int channels = 1;
        boolean signed = true;
        boolean bigEndian = true;
        AudioFormat format = new AudioFormat(sampleRate, sampleSizeInBits,
                                             channels, signed, bigEndian);
        return format;
    }

    void start(String n) {
        TargetDataLine line;
        File f = new File(n);
        try {
            AudioFormat format = getAudioFormat();
            DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
            line = (TargetDataLine) AudioSystem.getLine(info);
            line.open(format);
            line.start();
            AudioInputStream ais = new AudioInputStream(line);
            AudioSystem.write(ais, fileType, f);

        } catch (LineUnavailableException | IOException ex) {
            System.out.println(ex);
        }
    }

}
0

There are 0 answers