0

I'm working on streaming the running audio on PC to an android phone in Real Time

But my problem is the recorded audio which comes from PC is in 32 bits per sample. which can't be played on android.

This is my Code for PC in C#:

Using CSCore library, And i'v tried NAudio too

        var wasapiCapture = new WasapiLoopbackCapture();
        wasapiCapture.Initialize();
        var wasapiCaptureSource = new SoundInSource(wasapiCapture);
        WaveFormat waveFormat = wasapiCapture.WaveFormat;
        byte[] buffer = new byte[waveFormat.BytesPerSecond];
        wasapiCaptureSource.DataAvailable += (s, e) =>
        {

            int read = wasapiCaptureSource.Read(buffer, 0, buffer.Length);
            stream.Write(buffer, 0, read);
            stream.Flush();

        };

        wasapiCapture.Start();

My Code for android using java:

 int maxJitter = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);

        AudioTrack audioTrack =new AudioTrack(AudioManager.MODE_IN_COMMUNICATION,44100,1,AudioFormat.ENCODING_PCM_16BIT,maxJitter,AudioTrack.MODE_STREAM);
        audioTrack.play();
        while ((read = reader.read(bytes)) != -1) {
           audioTrack.write(bytes,0,read);
        }
        audioTrack.stop();

This code is running very good when i change WasapiLoopbackCapture to WaveIn and record from Mic. because WaveIn let me change wave format to a suitable one Any Suggestion ?

Ahmed Ali
  • 614
  • 1
  • 5
  • 17

0 Answers0