新增对讲开始播放音频方法
录音插件更新版本
This commit is contained in:
parent
4a4ccf808a
commit
e0e4c32e7a
@ -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();
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user