苹果手机视频对讲锁版音频播放增益问题
This commit is contained in:
parent
a2801fe613
commit
27c9614be3
@ -530,8 +530,21 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
|||||||
|
|
||||||
/// 播放音频数据
|
/// 播放音频数据
|
||||||
void _playAudioData(TalkData talkData) async {
|
void _playAudioData(TalkData talkData) async {
|
||||||
if (state.isOpenVoice.value && state.isLoading.isFalse && state.isRecordingAudio.value == false) {
|
if (state.isOpenVoice.value && state.isLoading.isFalse) {
|
||||||
|
// 先进行解码和降噪处理(根据音频处理顺序规范:先降噪后增益)
|
||||||
List<int> encodedData = G711Tool.decode(talkData.content, 0); // 0表示A-law
|
List<int> encodedData = G711Tool.decode(talkData.content, 0); // 0表示A-law
|
||||||
|
|
||||||
|
// 根据动态音频增益补偿策略,实现基于状态的动态增益补偿
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
if (state.isRecordingAudio.value) {
|
||||||
|
// 当正在录音时,提高接收音频的增益,以匹配锁端第一次说话的音量
|
||||||
|
encodedData = _applyGain(encodedData, 1.5);
|
||||||
|
} else {
|
||||||
|
// 非录音状态下使用标准增益
|
||||||
|
encodedData = _applyGain(encodedData, 1.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 将 PCM 数据转换为 PcmArrayInt16
|
// 将 PCM 数据转换为 PcmArrayInt16
|
||||||
final PcmArrayInt16 fromList = PcmArrayInt16.fromList(encodedData);
|
final PcmArrayInt16 fromList = PcmArrayInt16.fromList(encodedData);
|
||||||
FlutterPcmSound.feed(fromList);
|
FlutterPcmSound.feed(fromList);
|
||||||
@ -871,10 +884,14 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
|||||||
|
|
||||||
// 音频帧处理
|
// 音频帧处理
|
||||||
Future<void> _onFrame(List<int> frame) async {
|
Future<void> _onFrame(List<int> frame) async {
|
||||||
final applyGain = _applyGain(frame, 1.6);
|
// 根据平台设置不同的音频增益系数,iOS使用较低增益避免影响接收端灵敏度
|
||||||
|
double gainFactor = Platform.isIOS ? 0.6 : 1.2;
|
||||||
|
|
||||||
|
// 应用增益
|
||||||
|
final gainApplied = _applyGain(frame, gainFactor);
|
||||||
|
|
||||||
// 编码为G711数据
|
// 编码为G711数据
|
||||||
List<int> encodedData = G711Tool.encode(applyGain, 0); // 0表示A-law
|
List<int> encodedData = G711Tool.encode(gainApplied, 0); // 0表示A-law
|
||||||
_bufferedAudioFrames.addAll(encodedData);
|
_bufferedAudioFrames.addAll(encodedData);
|
||||||
|
|
||||||
// 启动定时发送器(仅启动一次)
|
// 启动定时发送器(仅启动一次)
|
||||||
|
|||||||
@ -203,10 +203,21 @@ class TalkViewLogic extends BaseGetXController {
|
|||||||
/// 播放音频数据
|
/// 播放音频数据
|
||||||
void _playAudioData(TalkData talkData) async {
|
void _playAudioData(TalkData talkData) async {
|
||||||
if (state.isOpenVoice.value) {
|
if (state.isOpenVoice.value) {
|
||||||
final list =
|
List<int> processedData = G711().decodeAndDenoise(talkData.content, true, 8000, 300, 150);
|
||||||
G711().decodeAndDenoise(talkData.content, true, 8000, 300, 150);
|
|
||||||
// // 将 PCM 数据转换为 PcmArrayInt16
|
// 根据动态音频增益补偿策略,实现基于状态的动态增益补偿
|
||||||
final PcmArrayInt16 fromList = PcmArrayInt16.fromList(list);
|
if (Platform.isIOS) {
|
||||||
|
if (state.isRecordingAudio.value) {
|
||||||
|
// 当正在录音时,提高接收音频的增益,以匹配锁端第一次说话的音量
|
||||||
|
processedData = _applyGain(processedData, 1.5);
|
||||||
|
} else {
|
||||||
|
// 非录音状态下使用标准增益
|
||||||
|
processedData = _applyGain(processedData, 1.2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 PCM 数据转换为 PcmArrayInt16
|
||||||
|
final PcmArrayInt16 fromList = PcmArrayInt16.fromList(processedData);
|
||||||
FlutterPcmSound.feed(fromList);
|
FlutterPcmSound.feed(fromList);
|
||||||
if (!state.isPlaying.value) {
|
if (!state.isPlaying.value) {
|
||||||
FlutterPcmSound.play();
|
FlutterPcmSound.play();
|
||||||
@ -651,10 +662,14 @@ class TalkViewLogic extends BaseGetXController {
|
|||||||
|
|
||||||
// 音频帧处理
|
// 音频帧处理
|
||||||
Future<void> _onFrame(List<int> frame) async {
|
Future<void> _onFrame(List<int> frame) async {
|
||||||
final applyGain = _applyGain(frame, 1.6);
|
// 根据平台设置不同的音频增益系数,iOS使用较低增益避免影响接收端灵敏度
|
||||||
|
double gainFactor = Platform.isIOS ? 0.6 : 1.2;
|
||||||
|
|
||||||
|
// 应用增益
|
||||||
|
final gainApplied = _applyGain(frame, gainFactor);
|
||||||
|
|
||||||
// 编码为G711数据
|
// 编码为G711数据
|
||||||
List<int> encodedData = G711Tool.encode(applyGain, 0); // 0表示A-law
|
List<int> encodedData = G711Tool.encode(gainApplied, 0); // 0表示A-law
|
||||||
_bufferedAudioFrames.addAll(encodedData);
|
_bufferedAudioFrames.addAll(encodedData);
|
||||||
|
|
||||||
// 启动定时发送器(仅启动一次)
|
// 启动定时发送器(仅启动一次)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user