gpt4 book ai didi

android - Android和PC之间的音频路由会产生白噪声

转载 作者:行者123 更新时间:2023-12-03 12:07:10 29 4
gpt4 key购买 nike

我正在尝试在Windows和Android之间发送音频,我能够成功地将Windows切换到Windows,但是当我从Android流式传输音频时,它只会产生白噪声。我认为这是Android和Windows中AudioFormat的问题,因为我将示例位更改为8时,我想我听到了耳机一侧的声音,但随后声音也消失了。
在Android方面

        int BUFFER_MS = 15; // do not buffer more than BUFFER_MS milliseconds
int bufferSize = 48000 * 2 * BUFFER_MS / 1000;
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 48000, 2,
AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM);


byte[] buffer = new byte[bufferSize];
int bytesRead;
audioTrack.play();
while (socket.isConnected()) {
bytesRead = inputStream.read(buffer, 0, buffer.length);
audioTrack.write(buffer,0,bytesRead);
}
在Windows端
        AudioFormat format = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

// checks if system supports the data line
if (!AudioSystem.isLineSupported(info)) {
throw new LineUnavailableException(
"The system does not support the specified format.");
}
TargetDataLine audioLine = AudioSystem.getTargetDataLine(format);

audioLine.open(format);
audioLine.start();

byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;

while (socket.isConnected()) {
bytesRead = audioLine.read(buffer, 0, buffer.length);
outputStream.write(buffer,0,bytesRead);
}
而getAudioFormat函数是
AudioFormat getAudioFormat() {
float sampleRate = 48000;
int sampleSizeInBits = 16;
int channels = 2;
boolean signed = true;
boolean bigEndian = true;
return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,
bigEndian);
}
如果有人可以帮助,请只听到白声。

最佳答案

好的,我发现了问题所在。我只需要将bigEndian设置为假-_-
这是字节顺序的差异。我不明白为什么它在android和pc中会有所不同,但似乎可以解决问题。

关于android - Android和PC之间的音频路由会产生白噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65937832/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com