fix:调整音频发送缓冲区逻辑
This commit is contained in:
parent
68a13c4b6c
commit
59fb9384ca
@ -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); // 0表示A-law
|
List<int> encodedData = G711Tool.encode(amplifiedFrame, 0); // 0表示A-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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user