提交代码

This commit is contained in:
魏少阳 2023-12-22 14:26:58 +08:00
parent ae3b80b7b4
commit a6773da4fd
3 changed files with 42 additions and 29 deletions

View File

@ -223,6 +223,8 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
}), }),
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png", bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png",
"开锁", AppColors.mainColor, () { "开锁", AppColors.mainColor, () {
// _playRecording();
showDeletPasswordAlertDialog(context); showDeletPasswordAlertDialog(context);
}) })
]); ]);
@ -231,34 +233,22 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
String getAnswerBtnImg() { String getAnswerBtnImg() {
switch (state.udpStatus.value) { switch (state.udpStatus.value) {
case 8: case 8:
{
return "images/main/icon_lockDetail_monitoringUnTalkback.png"; return "images/main/icon_lockDetail_monitoringUnTalkback.png";
}
case 9: case 9:
{
return "images/main/icon_lockDetail_monitoringTalkback.png"; return "images/main/icon_lockDetail_monitoringTalkback.png";
}
default: default:
{
return "images/main/icon_lockDetail_monitoringAnswerCalls.png"; return "images/main/icon_lockDetail_monitoringAnswerCalls.png";
}
} }
} }
String getAnswerBtnName() { String getAnswerBtnName() {
switch (state.udpStatus.value) { switch (state.udpStatus.value) {
case 8: case 8:
{
return "长按说话"; return "长按说话";
}
case 9: case 9:
{
return "松开发送"; return "松开发送";
}
default: default:
{
return "接听"; return "接听";
}
} }
} }
@ -356,6 +346,9 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
await recorder.startRecorder( await recorder.startRecorder(
toFile: filePath, toFile: filePath,
codec: Codec.pcm16WAV, codec: Codec.pcm16WAV,
bitRate: 8000,
numChannels: 1,
sampleRate: 8000,
); );
} }
@ -363,9 +356,6 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
_stopRecording() async { _stopRecording() async {
await recorder.stopRecorder(); await recorder.stopRecorder();
var userMobileIP = await NetworkInfo().getWifiIP();
var userMobile = await Storage.getMobile();
// final file = File(filePath); // final file = File(filePath);
File file = File(filePath); // 使 create File file = File(filePath); // 使 create
@ -374,23 +364,13 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
final List<int> bytes = await file.readAsBytes(); final List<int> bytes = await file.readAsBytes();
print('Recorded audio bytes.length:${bytes.length} bytes: $bytes'); print('Recorded audio bytes.length:${bytes.length} bytes: $bytes');
// _sendRecordData(bytes);
UDPSenderManage.sendMainProtocol(
command: 150,
commandTypeIsCalling: 1,
subCommand: 8,
lockID: UDPManage().lockId,
lockIP: UDPManage().host,
userMobile: userMobile,
userMobileIP: userMobileIP,
endData: bytes
);
} }
} }
Future<String> getFilePath() async { Future<String> getFilePath() async {
final directory = await getApplicationDocumentsDirectory(); final directory = await getApplicationDocumentsDirectory();
final filePath = '${directory.path}/recording.mp3'; final filePath = '${directory.path}/recording.wav';
// //
File file = File(filePath); File file = File(filePath);
@ -425,4 +405,33 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
// _stopPlaying() async { // _stopPlaying() async {
// await player.stopPlayer(); // await player.stopPlayer();
// } // }
_sendRecordData(List<int> bytes) async {
//
var userMobileIP = await NetworkInfo().getWifiIP();
var userMobile = await Storage.getMobile();
// 57
List<int> topBytes = [
1, 1, 1, 1, //
1, 0, //
1, 0, //
64, 0, 0, 0, //
1, 0, //
1, 0, //
64, 1, //
176, 4, //
];
UDPSenderManage.sendMainProtocol(
command: 150,
commandTypeIsCalling: 1,
subCommand: 8,
lockID: UDPManage().lockId,
lockIP: UDPManage().host,
userMobile: userMobile,
userMobileIP: userMobileIP,
endData: bytes
);
}
} }

View File

@ -26,6 +26,7 @@ class CallTalk {
var growableList; var growableList;
bool getFirstFrame = false; // bool getFirstFrame = false; //
final FlutterSoundPlayer _audioPlayer = FlutterSoundPlayer(); final FlutterSoundPlayer _audioPlayer = FlutterSoundPlayer();
Uint8List? allPcmData = Uint8List(0);
CallTalk._init() { CallTalk._init() {
iframe = IframeInfo(); iframe = IframeInfo();
@ -53,8 +54,9 @@ class CallTalk {
Uint8List pcmData = G711Decoder().g711Decode(g711Data, G711Type.uLaw); Uint8List pcmData = G711Decoder().g711Decode(g711Data, G711Type.uLaw);
// 使 pcmData // 使 pcmData
print('得到的pcmData:$pcmData'); print('得到的pcmData:$pcmData');
allPcmData!.addAll(pcmData);
_playRawData(pcmData); await Future.delayed(const Duration(seconds: 3));
_playRawData(allPcmData!);
} }
// //
else { else {

View File

@ -62,6 +62,8 @@ class UDPMainProtocolCommand extends UDPSenderProtocol {
data.add(int.parse(element)); data.add(int.parse(element));
}); });
data.addAll(endData!);
// print("datadatadata:$data"); // print("datadatadata:$data");
return data; return data;
} }