Recording pcm audio - s76/libgdx GitHub Wiki

You can access PCM data from the microphone on a PC or Android phone via the AudioRecorder (code) interface. To create an instance of that interface use:

AudioRecorder recorder = Gdx.audio.newAudioRecorder(22050, true);

This will create an AudioRecorder with a sampling rate of 22.05khz, in mono mode. If the recorder couldn't be created, a GdxRuntimeException will be thrown.

Samples can be read as 16-bit signed PCM:

short[] shortPCM = new short[1024]; // 1024 samples
recorder.readSamples(shortPCM, 0, shortPCM.length);

Stereo samples are interleaved as usual (first sample -> left channel, second sample -> right channel).

An AudioRecorder is a native resource and needs to be disposed of if no longer in use:

recorder.dispose();

Audio recording is not supported in the JavaScript/WebGL backend.