优化对讲接收音频
This commit is contained in:
parent
719246ea82
commit
2723c0b058
@ -47,7 +47,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
|||||||
// 接听成功了,然后刷新界面的时间 60秒以后自动挂断
|
// 接听成功了,然后刷新界面的时间 60秒以后自动挂断
|
||||||
state.oneMinuteTimeTimer = Timer.periodic(const Duration(seconds:1), (Timer t) async {
|
state.oneMinuteTimeTimer = Timer.periodic(const Duration(seconds:1), (Timer t) async {
|
||||||
state.oneMinuteTime.value++;
|
state.oneMinuteTime.value++;
|
||||||
Get.log('state.oneMinuteTime.value:${state.oneMinuteTime.value}');
|
// Get.log('state.oneMinuteTime.value:${state.oneMinuteTime.value}');
|
||||||
if(state.oneMinuteTime.value >= 60){
|
if(state.oneMinuteTime.value >= 60){
|
||||||
// 超过60秒了
|
// 超过60秒了
|
||||||
state.oneMinuteTimeTimer.cancel();
|
state.oneMinuteTimeTimer.cancel();
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
import 'package:star_lock/talk/call/g711.dart';
|
import 'package:star_lock/talk/call/g711.dart';
|
||||||
import 'package:star_lock/talk/call/iFrameInfo.dart';
|
import 'package:star_lock/talk/call/iFrameInfo.dart';
|
||||||
import '../../tools/eventBusEventManage.dart';
|
import '../../tools/eventBusEventManage.dart';
|
||||||
@ -22,6 +23,7 @@ class CallTalk {
|
|||||||
IframeInfo? iframe; // 假设有这个成员变量
|
IframeInfo? iframe; // 假设有这个成员变量
|
||||||
var growableList;
|
var growableList;
|
||||||
bool getFirstFrame = false; //是否得到了第一帧
|
bool getFirstFrame = false; //是否得到了第一帧
|
||||||
|
List<int> allDataBytes = <int>[]; //音频数据
|
||||||
|
|
||||||
CallTalk._init() {
|
CallTalk._init() {
|
||||||
iframe = IframeInfo();
|
iframe = IframeInfo();
|
||||||
@ -47,6 +49,14 @@ class CallTalk {
|
|||||||
try {
|
try {
|
||||||
// 将 ALaw 转为 Linear
|
// 将 ALaw 转为 Linear
|
||||||
pcmBytes = G711().convertList(g711Data);
|
pcmBytes = G711().convertList(g711Data);
|
||||||
|
allDataBytes.addAll(pcmBytes);
|
||||||
|
|
||||||
|
// String filePath = 'assets/s10-g711.bin';
|
||||||
|
//
|
||||||
|
// List<int> audioData = await G711().readAssetFile(filePath);
|
||||||
|
// pcmBytes = G711().convertList(audioData);
|
||||||
|
// allDataBytes = pcmBytes.sublist(0, 640);
|
||||||
|
|
||||||
_initializeAudioPlayer(pcmBytes);
|
_initializeAudioPlayer(pcmBytes);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error decoding G.711 to PCM: $e');
|
print('Error decoding G.711 to PCM: $e');
|
||||||
@ -118,9 +128,28 @@ class CallTalk {
|
|||||||
|
|
||||||
//音频相关处理
|
//音频相关处理
|
||||||
Future<void> _initializeAudioPlayer(List<int> audioData) async {
|
Future<void> _initializeAudioPlayer(List<int> audioData) async {
|
||||||
PcmArrayInt16 fromList = PcmArrayInt16.fromList(audioData);
|
Get.log('_initializeAudioPlayer audioData:$audioData');
|
||||||
await FlutterPcmSound.feed(fromList);
|
|
||||||
|
|
||||||
|
PcmArrayInt16 fromList = PcmArrayInt16.fromList(audioData);
|
||||||
|
// FlutterPcmSound.setFeedCallback(onFeed);
|
||||||
|
await FlutterPcmSound.feed(fromList);
|
||||||
FlutterPcmSound.play();
|
FlutterPcmSound.play();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void onFeed(int remainingFrames) async {
|
||||||
|
int framesToFeed = 320;
|
||||||
|
|
||||||
|
if (allDataBytes.length >= framesToFeed) {
|
||||||
|
List<int> frames = allDataBytes.sublist(0, framesToFeed);
|
||||||
|
allDataBytes.removeRange(0, framesToFeed);
|
||||||
|
|
||||||
|
// 将数据传递给 FlutterPcmSound
|
||||||
|
PcmArrayInt16 fromList = PcmArrayInt16.fromList(frames);
|
||||||
|
await FlutterPcmSound.feed(fromList);
|
||||||
|
FlutterPcmSound.play();
|
||||||
|
} else {
|
||||||
|
// 处理长度不足的情况,可以等待更多数据或者采取其他措施
|
||||||
|
print("Not enough data in allPcmData.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user