1
This commit is contained in:
@@ -141,7 +141,7 @@
|
||||
|
||||
// 配置为录音+播放模式
|
||||
// Category: PlayAndRecord - 同时支持录音和播放
|
||||
// Mode: VoiceChat - 优化语音通话场景
|
||||
// Mode: VoiceChat - 允许系统进行 AGC/降噪,提升输入音量
|
||||
// Options:
|
||||
// - DefaultToSpeaker: 默认使用扬声器
|
||||
// - AllowBluetooth: 允许蓝牙设备
|
||||
@@ -162,6 +162,31 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
// 优先使用后端要求的采样率和缓冲时长,减少重采样误差
|
||||
NSError *sampleRateError = nil;
|
||||
[session setPreferredSampleRate:16000 error:&sampleRateError];
|
||||
if (sampleRateError) {
|
||||
NSLog(@"[AudioSessionManager] Failed to set sample rate: %@",
|
||||
sampleRateError.localizedDescription);
|
||||
}
|
||||
|
||||
NSError *bufferError = nil;
|
||||
[session setPreferredIOBufferDuration:0.02 error:&bufferError];
|
||||
if (bufferError) {
|
||||
NSLog(@"[AudioSessionManager] Failed to set IO buffer: %@",
|
||||
bufferError.localizedDescription);
|
||||
}
|
||||
|
||||
if ([session respondsToSelector:@selector(setPreferredInputNumberOfChannels:
|
||||
error:)]) {
|
||||
NSError *channelsError = nil;
|
||||
[session setPreferredInputNumberOfChannels:1 error:&channelsError];
|
||||
if (channelsError) {
|
||||
NSLog(@"[AudioSessionManager] Failed to set input channels: %@",
|
||||
channelsError.localizedDescription);
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -206,6 +231,15 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (session.isInputGainSettable) {
|
||||
NSError *gainError = nil;
|
||||
[session setInputGain:1.0 error:&gainError];
|
||||
if (gainError) {
|
||||
NSLog(@"[AudioSessionManager] Failed to set input gain: %@",
|
||||
gainError.localizedDescription);
|
||||
}
|
||||
}
|
||||
|
||||
self.isSessionActive = YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user