我正在实时
将PC上的运行音频流式传输到Android手机但我的问题是来自PC的录制音频是每个样本32位。 这不能在Android上播放。
这是我在C#中的PC代码:
使用CSCore库,我也试过NAudio
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();
使用java的Android代码:
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();
当我将WasapiLoopbackCapture更改为WaveIn并从Mic录制时,此代码运行良好。因为WaveIn让我将波形格式改为合适的格式 有什么建议吗?