新增对讲开始播放音频方法

录音插件更新版本
This commit is contained in:
Daisy 2024-04-16 09:07:38 +08:00
parent 4a4ccf808a
commit e0e4c32e7a
3 changed files with 14 additions and 26 deletions

View File

@ -148,9 +148,9 @@ class LockMonitoringLogic extends BaseGetXController {
//
Future<void> startProcessing() async {
if (state.isProcessing.value) {
CallTalk().stopPlaySound();
}
// if (state.isProcessing.value) {
// CallTalk().stopPlaySound();
// }
state.isButtonDisabled.value = true;
state.voiceProcessor?.addFrameListener(_onFrame);
@ -171,9 +171,9 @@ class LockMonitoringLogic extends BaseGetXController {
}
Future<void> _onFrame(List<int> frame) async {
if (state.isProcessing.value) {
CallTalk().stopPlaySound();
}
// if (state.isProcessing.value) {
// CallTalk().stopPlaySound();
// }
state.allFrames.add(frame); //
List<int> concatenatedFrames = concatenateFrames(state.allFrames); //
Get.log("pcm数据:$concatenatedFrames");
@ -204,9 +204,11 @@ class LockMonitoringLogic extends BaseGetXController {
}
Future<void> stopProcessing() async {
if (state.isProcessing.value) {
CallTalk().stopPlaySound();
}
// if (state.isProcessing.value) {
// CallTalk().stopPlaySound();
// } else {
// CallTalk().startPlaySound();
// }
state.isButtonDisabled.value = true;
try {
await state.voiceProcessor?.stop();

View File

@ -123,26 +123,12 @@ class CallTalk {
// Get.log('_initializeAudioPlayer audioData:$audioData');
PcmArrayInt16 fromList = PcmArrayInt16.fromList(audioData);
// FlutterPcmSound.setFeedCallback(onFeed);
await FlutterPcmSound.feed(fromList);
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.");
}
void startPlaySound() {
FlutterPcmSound.play();
}
void stopPlaySound() {

View File

@ -148,7 +148,7 @@ dependencies:
intl: ^0.18.0
# flutter_audio_capture: <1.1.5
flutter_voice_processor: ^1.1.0
flutter_voice_processor: ^1.1.1
#监听网络连接状态
connectivity_plus: ^5.0.2
#flutter_advanced_calendar: ^1.4.1