fix:调整音频发送缓冲区逻辑

This commit is contained in:
liyi 2025-04-07 14:44:49 +08:00
parent 68a13c4b6c
commit 59fb9384ca

View File

@ -659,32 +659,39 @@ class TalkViewLogic extends BaseGetXController {
// //
Future<void> _onFrame(List<int> frame) async { Future<void> _onFrame(List<int> frame) async {
//
if (_bufferedAudioFrames.length > state.frameLength * 3) {
_bufferedAudioFrames.clear(); //
return;
}
// //
List<int> amplifiedFrame = _applyGain(frame, 1.6); List<int> amplifiedFrame = _applyGain(frame, 1.6);
// G711数据 // G711数据
List<int> encodedData = G711Tool.encode(amplifiedFrame, 0); // 0A-law List<int> encodedData = G711Tool.encode(amplifiedFrame, 0); // 0A-law
_bufferedAudioFrames.addAll(encodedData); _bufferedAudioFrames.addAll(encodedData);
// 使
final int ms = DateTime.now().millisecondsSinceEpoch - final int ms = DateTime.now().millisecondsSinceEpoch % 1000000; // 使
state.startRecordingAudioTime.value.millisecondsSinceEpoch;
int getFrameLength = state.frameLength; int getFrameLength = state.frameLength;
if (Platform.isIOS) { if (Platform.isIOS) {
getFrameLength = state.frameLength * 2; getFrameLength = state.frameLength * 2;
} }
if (_bufferedAudioFrames.length >= getFrameLength) { //
// UDP if (_bufferedAudioFrames.length >= state.frameLength) {
await StartChartManage() try {
.sendTalkDataMessage( await StartChartManage().sendTalkDataMessage(
talkData: TalkData( talkData: TalkData(
content: _bufferedAudioFrames, content: _bufferedAudioFrames,
contentType: TalkData_ContentTypeE.G711, contentType: TalkData_ContentTypeE.G711,
durationMs: ms, durationMs: ms,
), ),
) );
.then((value) { } finally {
_bufferedAudioFrames.clear(); _bufferedAudioFrames.clear(); //
}); }
} else {
_bufferedAudioFrames.addAll(encodedData);
} }
} }