develop_sky #1
@ -602,12 +602,23 @@ class ImageTransmissionLogic extends BaseGetXController {
|
||||
} on PlatformException catch (ex) {
|
||||
// state.errorMessage.value = 'Failed to stop recorder: $ex';
|
||||
} finally {
|
||||
// 延迟关闭定时器,确保剩余数据能发送出去
|
||||
if (_startProcessingAudioTimer != null) {
|
||||
// 插入5个320长度的全0数据包
|
||||
for (int i = 0; i < 5; i++) {
|
||||
_bufferedAudioFrames.addAll(List.filled(chunkSize, 0));
|
||||
}
|
||||
Future.delayed(const Duration(milliseconds: 300), () {
|
||||
_startProcessingAudioTimer?.cancel();
|
||||
_startProcessingAudioTimer = null;
|
||||
_bufferedAudioFrames.clear();
|
||||
});
|
||||
} else {
|
||||
_bufferedAudioFrames.clear();
|
||||
}
|
||||
final bool? isRecording = await state.voiceProcessor?.isRecording();
|
||||
state.isRecordingAudio.value = isRecording!;
|
||||
}
|
||||
_startProcessingAudioTimer?.cancel();
|
||||
_startProcessingAudioTimer = null;
|
||||
_bufferedAudioFrames.clear();
|
||||
}
|
||||
|
||||
static const int chunkSize = 320; // 每次发送320字节(10ms G.711)
|
||||
@ -656,27 +667,11 @@ class ImageTransmissionLogic extends BaseGetXController {
|
||||
AppLog.log(error.message!);
|
||||
}
|
||||
|
||||
// 添加音频增益处理方法
|
||||
List<int> _applyGain(List<int> pcmData, double gainFactor) {
|
||||
List<int> result = List<int>.filled(pcmData.length, 0);
|
||||
|
||||
for (int i = 0; i < pcmData.length; i++) {
|
||||
// PCM数据通常是有符号的16位整数
|
||||
int sample = pcmData[i];
|
||||
|
||||
// 应用增益
|
||||
double amplified = sample * gainFactor;
|
||||
|
||||
// 限制在有效范围内,防止溢出
|
||||
if (amplified > 32767) {
|
||||
amplified = 32767;
|
||||
} else if (amplified < -32768) {
|
||||
amplified = -32768;
|
||||
}
|
||||
|
||||
result[i] = amplified.toInt();
|
||||
}
|
||||
|
||||
return result;
|
||||
return pcmData.map((sample) {
|
||||
// 增益并裁剪
|
||||
int amplified = (sample * gainFactor).round();
|
||||
return amplified.clamp(-32768, 32767);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -782,12 +782,23 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
||||
} on PlatformException catch (ex) {
|
||||
// state.errorMessage.value = 'Failed to stop recorder: $ex';
|
||||
} finally {
|
||||
// 延迟关闭定时器,确保剩余数据能发送出去
|
||||
if (_startProcessingAudioTimer != null) {
|
||||
// 插入5个320长度的全0数据包
|
||||
for (int i = 0; i < 5; i++) {
|
||||
_bufferedAudioFrames.addAll(List.filled(chunkSize, 0));
|
||||
}
|
||||
Future.delayed(const Duration(milliseconds: 300), () {
|
||||
_startProcessingAudioTimer?.cancel();
|
||||
_startProcessingAudioTimer = null;
|
||||
_bufferedAudioFrames.clear();
|
||||
});
|
||||
} else {
|
||||
_bufferedAudioFrames.clear();
|
||||
}
|
||||
final bool? isRecording = await state.voiceProcessor?.isRecording();
|
||||
state.isRecordingAudio.value = isRecording!;
|
||||
}
|
||||
_startProcessingAudioTimer?.cancel();
|
||||
_startProcessingAudioTimer = null;
|
||||
_bufferedAudioFrames.clear();
|
||||
}
|
||||
|
||||
// 添加音频增益处理方法
|
||||
|
||||
@ -599,12 +599,23 @@ class TalkViewLogic extends BaseGetXController {
|
||||
} on PlatformException catch (ex) {
|
||||
// state.errorMessage.value = 'Failed to stop recorder: $ex';
|
||||
} finally {
|
||||
// 延迟关闭定时器,确保剩余数据能发送出去
|
||||
if (_startProcessingAudioTimer != null) {
|
||||
// 插入5个320长度的全0数据包
|
||||
for (int i = 0; i < 5; i++) {
|
||||
_bufferedAudioFrames.addAll(List.filled(chunkSize, 0));
|
||||
}
|
||||
Future.delayed(const Duration(milliseconds: 300), () {
|
||||
_startProcessingAudioTimer?.cancel();
|
||||
_startProcessingAudioTimer = null;
|
||||
_bufferedAudioFrames.clear();
|
||||
});
|
||||
} else {
|
||||
_bufferedAudioFrames.clear();
|
||||
}
|
||||
final bool? isRecording = await state.voiceProcessor?.isRecording();
|
||||
state.isRecordingAudio.value = isRecording!;
|
||||
}
|
||||
_startProcessingAudioTimer?.cancel();
|
||||
_startProcessingAudioTimer = null;
|
||||
_bufferedAudioFrames.clear();
|
||||
}
|
||||
|
||||
static const int chunkSize = 320; // 每次发送320字节(10ms G.711)
|
||||
@ -656,25 +667,10 @@ class TalkViewLogic extends BaseGetXController {
|
||||
|
||||
// 添加音频增益处理方法
|
||||
List<int> _applyGain(List<int> pcmData, double gainFactor) {
|
||||
List<int> result = List<int>.filled(pcmData.length, 0);
|
||||
|
||||
for (int i = 0; i < pcmData.length; i++) {
|
||||
// PCM数据通常是有符号的16位整数
|
||||
int sample = pcmData[i];
|
||||
|
||||
// 应用增益
|
||||
double amplified = sample * gainFactor;
|
||||
|
||||
// 限制在有效范围内,防止溢出
|
||||
if (amplified > 32767) {
|
||||
amplified = 32767;
|
||||
} else if (amplified < -32768) {
|
||||
amplified = -32768;
|
||||
}
|
||||
|
||||
result[i] = amplified.toInt();
|
||||
}
|
||||
|
||||
return result;
|
||||
return pcmData.map((sample) {
|
||||
// 增益并裁剪
|
||||
int amplified = (sample * gainFactor).round();
|
||||
return amplified.clamp(-32768, 32767);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user