The linked tutorial worked for me. In it, a sound is recorded and saved to a .wav.
The key to having this stream to a speaker would be opening a SourceDataLine
and outputting to that instead of writing to a wav file. So, instead of outputting on line 59 to AudioSystem.write
, output to a SourceDataLine
write method.
IDK if there will be a feedback issue. Probably good to output to headphones and not your speakers!
To add an effect, the AudioInputLine
has to be accessed and processed in segments. In each segment the following needs to happen:
- obtain the byte array from the
AudioInputLine
- convert the audio bytes to PCM
- apply your audio effect to the PCM (if the effect is a volume change over time, this could be done by progressively altering a volume factor between 0 to 1, multiplying the factor against the PCM)
- convert back to audio bytes
- write to the
SourceDataLine
All these steps have been covered in StackOverflow posts.
The link tutorial does some simplification in how file locations, threads, and the stopping and starting are handled. But most importantly, it shows a working, live audio line from the microphone.