1

I am using Java Sound API to record audio through a microphone. But why am I getting false as an output for the below snippet of code?

AudioFormat getAudioFormat() {
    float sampleRate = 8000;
    int sampleSizeInBits = 16;
    int channels = 1; //1 for mono, 2 for stereo
    boolean signed = true;
    boolean bigEndian = true;
    AudioFormat format = new AudioFormat(sampleRate, sampleSizeInBits,
                channels, signed, bigEndian);
    return format;
}

void myTest() {
    AudioFormat format = getAudioFormat();
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
    System.out.println(AudioSystem.isLineSupported(info));
}

public static void main(String[] args) {
    new JavaApplication20().myTest();
}

Thanks in advance.

Hendrik
  • 5,085
  • 24
  • 56
Naveen
  • 346
  • 2
  • 10
  • 2
    Runs OK on my Mac so possibly your test machine just doesn't support that format. Try running code like in [this answer](https://stackoverflow.com/a/39510109/2670892) to list all the supported formats. – greg-449 Jun 02 '20 at 15:57
  • What kind of machine is this? – Hendrik Jun 02 '20 at 15:58

0 Answers0