gpt4 book ai didi

android - 不支持的配置,采样率11025,格式1,ChannelMask 0x10

转载 作者:行者123 更新时间:2023-12-03 00:51:42 25 4
gpt4 key购买 nike

我在我的应用程序中实现了录音机。它可以正常工作几天,但是现在显示错误Unsupported Configuration,Sample rate 11025, format 1,ChannelMask 0x10.
这是我的日志:

 12-17 09:04:26.325: E/AudioRecord(1195): Unsupported configuration: sampleRate 11025, format 1, channelMask 0x10
12-17 09:04:26.335: W/dalvikvm(1195): threadid=17: thread exiting with uncaught exception (group=0x40a71930)
12-17 09:04:26.385: E/AndroidRuntime(1195): FATAL EXCEPTION: Thread-117
12-17 09:04:26.385: E/AndroidRuntime(1195): java.lang.NegativeArraySizeException: -2
12-17 09:04:26.385: E/AndroidRuntime(1195): at com.example.sms.OtherActivity.startRecord(OtherActivity.java:196)
12-17 09:04:26.385: E/AndroidRuntime(1195): at com.example.sms.OtherActivity.access$5(OtherActivity.java:180)
12-17 09:04:26.385: E/AndroidRuntime(1195): at com.example.sms.OtherActivity$1$1.run(OtherActivity.java:142)
12-17 09:04:26.385: E/AndroidRuntime(1195): at java.lang.Thread.run(Thread.java:856)

这是我用于实现录音的代码,
 private void startRecord()
{
File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");

try
{
file.createNewFile();

OutputStream outputStream = new FileOutputStream(file);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);

int minBufferSize = AudioRecord.getMinBufferSize(11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);

short[] audioData = new short[minBufferSize];

AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);

audioRecord.startRecording();

while(recording)
{
int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
for(int i = 0; i < numberOfShort; i++)
{
dataOutputStream.writeShort(audioData[i]);
}
}
audioRecord.stop();
dataOutputStream.close();

}
catch (IOException e)
{
e.printStackTrace();
}

}

void playRecord()
{
File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");

int shortSizeInBytes = Short.SIZE/Byte.SIZE;

int bufferSizeInBytes = (int)(file.length()/shortSizeInBytes);
short[] audioData = new short[bufferSizeInBytes];

try {
InputStream inputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);

int i = 0;
while(dataInputStream.available() > 0)
{
audioData[i] = dataInputStream.readShort();
i++;
}

dataInputStream.close();

AudioTrack audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
bufferSizeInBytes,
AudioTrack.MODE_STREAM);

audioTrack.play();
audioTrack.write(audioData, 0, bufferSizeInBytes);


} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}



}

是什么导致此错误,我该如何纠正?

最佳答案

您正在将无效(不受支持)的参数传递给getMinBufferSize(),并且它返回-2 ERROR_BAD_VALUE。尝试为数组分配负数个元素会导致NegativeArraySizeException

现在, CHANNEL_CONFIGRATION_MONO 已被弃用很长时间了。您应该改为使用CHANNEL_IN_MONO。这可能是ERROR_BAD_VALUE的原因。

关于android - 不支持的配置,采样率11025,格式1,ChannelMask 0x10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20630009/

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