gpt4 book ai didi

android - AudioFlinger 无法创建记录轨道,状态 : -1 , 需要 ifx 帮助

转载 作者:IT老高 更新时间:2023-10-28 23:27:01 25 4
gpt4 key购买 nike

public class AudioRecorderActivity extends Activity {

private static final int RECORDER_SAMPLERATE = 8000;
private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
private AudioRecord recorder = null;
private static final String TAG = "AudioRecorderActivity";
short[][] buffers = new short[256][160];
int ix = 0;
private boolean stopped = false;

private void startRecording() {

android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
try {
int N = AudioRecord.getMinBufferSize (
RECORDER_SAMPLERATE,
RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING) * 20;

recorder = new AudioRecord(AudioSource.MIC,
RECORDER_SAMPLERATE,
RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING,N );

recorder.startRecording();

while(!stopped) {
short[] buffer = buffers[ix++ % buffers.length];
N = recorder.read(buffer,0,buffer.length);
}

}
catch(Throwable x) {
Log.v(TAG,"Error reading voice audio",x);
x.printStackTrace();
}
finally {
stopped = true;
stopRecording();
}
}
}

问题:虽然代码 fragment 基于 StackOverflow 的示例,但它不起作用请让我知道可能是什么错误?

这是错误信息

12-20 03:44:32.271: E/AudioRecord(224): AudioFlinger could not create record track, status: -1
12-20 03:44:32.271: E/AudioRecord-JNI(224): Error creating AudioRecord instance: initialization check failed.
12-20 03:44:32.271: E/AudioRecord-Java(224): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.

最佳答案

为AndroidManifest.xml添加record_audio权限

<uses-permission android:name="android.permission.RECORD_AUDIO" />

关于android - AudioFlinger 无法创建记录轨道,状态 : -1 , 需要 ifx 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20693001/

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