Browse Source

上传会议记录代码

weicu
liwei1dao 5 months ago
parent
commit
a80237d09f
  1. 24
      lib/modules/meeting/controllers/meeting_record_controller.dart

24
lib/modules/meeting/controllers/meeting_record_controller.dart

@ -771,22 +771,26 @@ class MeetingRecordController extends GetxController
waveformController.notifyListeners(); waveformController.notifyListeners();
} }
/// 计算音频数据的振幅 /// 计算音频数据的振幅。
///
/// 输入是小端 PCM_S16LE 字节流,可能是 mono 或 stereo 交织(LRLR)。
/// 这里按"每个 16-bit 样本"遍历(步长 2 字节),不区分声道,把所有样本一起求 RMS:
/// - mono:等价于全采样能量
/// - stereo:L 和 R 都纳入计算,得到双方组合能量;任一边说话都能体现在波形里
///
/// 之前用 `i += 4` 想做 2× 跳跃采样减计算量,但碰到 stereo 时变成"只读 L 跳过 R",
/// 导致通话录音的图谱只反映本端(自己),听不到对端的波形——已修。
double _calculateAmplitude(Uint8List audioData) { double _calculateAmplitude(Uint8List audioData) {
if (audioData.isEmpty) return 0.0; if (audioData.isEmpty) return 0.0;
// 使用RMS (Root Mean Square) 算法,更准确反映音频能量
double sumSquares = 0.0; double sumSquares = 0.0;
int sampleCount = 0; int sampleCount = 0;
for (int i = 0; i < audioData.length; i += 4) { for (int i = 0; i + 1 < audioData.length; i += 2) {
// 跳跃采样,减少计算量 final int sample = (audioData[i + 1] << 8) | audioData[i];
if (i + 1 < audioData.length) { final int signedSample = sample > 32767 ? sample - 65536 : sample;
final int sample = (audioData[i + 1] << 8) | audioData[i]; sumSquares += (signedSample * signedSample);
final int signedSample = sample > 32767 ? sample - 65536 : sample; sampleCount++;
sumSquares += (signedSample * signedSample);
sampleCount++;
}
} }
if (sampleCount == 0) return 0.0; if (sampleCount == 0) return 0.0;

Loading…
Cancel
Save