Hi there...
Well, found the following code from stackoverflow... says that record everything "output at speakers" and send via socket...
Well i need to transform it someway different... record to bytes (chunk...buffer) and the send with MQTT.... and play at other MQTT client...
But I am not trying to touch it... because my JAVA knowledge is so little... :-(
Any help will make me happy!
Well, found the following code from stackoverflow... says that record everything "output at speakers" and send via socket...
Well i need to transform it someway different... record to bytes (chunk...buffer) and the send with MQTT.... and play at other MQTT client...
But I am not trying to touch it... because my JAVA knowledge is so little... :-(
Any help will make me happy!
B4X:
public class Server {
ServerSocket MyService;
Socket clientSocket = null;
InputStream input;
AudioFormat audioFormat;
SourceDataLine sourceDataLine;
byte tempBuffer[] = new byte[10000];
static Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
Server() throws LineUnavailableException {
try {
Mixer mixer_ = AudioSystem.getMixer(mixerInfo[0]);
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
MyService = new ServerSocket(500);
clientSocket = MyService.accept();
input = new BufferedInputStream(clientSocket.getInputStream());
while (input.read(tempBuffer) != -1) {
sourceDataLine.write(tempBuffer, 0, 10000);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private AudioFormat getAudioFormat() {
float sampleRate = 8000.0F;
int sampleSizeInBits = 8;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(
sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian);
}
public static void main(String s[]) throws LineUnavailableException {
Server s2 = new Server();
}}