gpt4 book ai didi

android - 如何传输音频缓冲区以直接播放

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:48:47 25 4
gpt4 key购买 nike

我试图创建一个音频缓冲区并将他发送到一个新类(class)。在本类(class)中,我将使用 AudioTracker 播放此缓冲区,但它不起作用。我可以准时听到声音,但声音就像是一种霍尔效应。我对我的错误没有想法,也没有找到这个问题的答案。我希望你能帮助我。(对不起,我的英语不是最好的)源代码:

public class input {
private static final String TAG = "Aufnahme";
private AudioRecord recorder = null;
private boolean isRecording = false;
private int SAMPLERATE = 8000;
private int CHANNELS = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
private int bufferSize = AudioRecord.getMinBufferSize(SAMPLERATE, CHANNELS,
AUDIO_FORMAT);
private Thread recordingThread = null;

public void startRecording() {
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLERATE,
CHANNELS, AUDIO_FORMAT, bufferSize);

recorder.startRecording();
isRecording = true;

recordingThread = new Thread(new Runnable()

{
public void run() {
writeAudioData();
}

});
recordingThread.start();

}

public void stopRecording() {
isRecording = false;
recorder.stop();
recorder.release();
recorder = null;
recordingThread = null;
}

private void writeAudioData() {

byte data[] = new byte[bufferSize];

while (isRecording) {

recorder.read(data, 0, bufferSize);
send(data);

}
}

private void send(byte[] data) {

int minBufferSize = AudioTrack.getMinBufferSize(8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);

AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, minBufferSize,
AudioTrack.MODE_STREAM);

at.play();
at.write(data, 0, bufferSize);
at.stop();
at.release();

}

最佳答案

好的,我想出了问题。霍尔效应来自实时记录的扬声器声音。严重错误。

关于android - 如何传输音频缓冲区以直接播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10511753/

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