From 37b78a156574d282e2faf00fdace9de421818ce4 Mon Sep 17 00:00:00 2001 From: lcy <2503978335@qq.com> Date: Fri, 7 Jul 2023 13:36:23 +0800 Subject: [PATCH] feat:添加录音插件 --- ios/Runner/XSMessageMehtodChannel.swift | 23 +++++++++++++++++++++++ lib/pages/repeatafter/widgets/repeat_after_item.dart | 13 +++++++------ lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart | 5 ++--- pubspec.yaml | 4 ++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/ios/Runner/XSMessageMehtodChannel.swift b/ios/Runner/XSMessageMehtodChannel.swift index 774e8a7..2b0f76f 100644 --- a/ios/Runner/XSMessageMehtodChannel.swift +++ b/ios/Runner/XSMessageMehtodChannel.swift @@ -65,6 +65,24 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { SSOralEvaluatingManager.share().startEvaluateOral(with: config) } + //开始评测(本地音频文件) + func evaluateLocalVoice(dict:Dictionary) { + let text = dict["word"] as? String ?? "" + let type = dict["type"] as? String ?? "0" + let userId = dict["userId"] as? String ?? "guest" + let voicePath = dict["voicePath"] as? String ?? "" + let config = SSOralEvaluatingConfig() + config.oralContent = text + if (type == "0") { + config.oralType = .word + } else { + config.oralType = .sentence + } + config.oralType = .kidSent + config.userId = userId + SSOralEvaluatingManager.share().startEvaluateOral(withWavPath: voicePath, config: config) + } + func handle(_ call: FlutterMethodCall,_ result: @escaping FlutterResult) { if (call.method == "initVoiceSdk") { self.setEvaluateConfig(dict:call.arguments as! Dictionary) @@ -75,6 +93,11 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { return } + if (call.method == "starLocalVoice") { + self.evaluateLocalVoice(dict: call.arguments as! Dictionary) + return + } + if (call.method == "stopVoice") { SSOralEvaluatingManager.share().stopEvaluate(); return diff --git a/lib/pages/repeatafter/widgets/repeat_after_item.dart b/lib/pages/repeatafter/widgets/repeat_after_item.dart index 9d28556..26c99f6 100644 --- a/lib/pages/repeatafter/widgets/repeat_after_item.dart +++ b/lib/pages/repeatafter/widgets/repeat_after_item.dart @@ -19,12 +19,13 @@ class RepeatAfterItem extends StatelessWidget { ), child: GestureDetector( onTap: (){ - if (entity != null) { - // if (!entity!.lock!) { - // tapEvent?.call(); - // } - tapEvent?.call(); - } + ///todo 暂时注释调,测试用 + // if (entity != null) { + // if (!entity!.lock!) { + // tapEvent?.call(); + // } + // } + tapEvent?.call(); }, child: Stack( children: [ diff --git a/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart b/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart index dcfd250..d47eb23 100644 --- a/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart +++ b/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart @@ -3,7 +3,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:wow_english/common/request/dao/listen_dao.dart'; - import '../../../common/request/exception.dart'; import '../../../models/read_content_entity.dart'; import '../../../utils/loading.dart'; @@ -196,8 +195,8 @@ class RepeatAfterContentBloc extends Bloc emitter) async { final Map args = event.message as Map; final result = args['result'] as Map; - final overall = result['overall'].toString()??''; - final audioUrl = args['audioUrl'].toString()??''; + final overall = result['overall'].toString(); + final audioUrl = args['audioUrl'].toString(); _voiceTestResult = {'overall':overall,'audioUrl':audioUrl}; emitter(XSVoiceTestState()); } diff --git a/pubspec.yaml b/pubspec.yaml index a2df7f6..9b1fdb1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -93,6 +93,10 @@ dependencies: responsive_framework: ^1.0.0 # 音频播放 https://pub.dev/packages/audioplayers audioplayers: ^4.1.0 + # 语音录制 https://pub.dev/packages/flutter_sound + flutter_sound: ^9.2.13 + # 文件管理 https://pub.dev/packages/path_provider + path_provider: ^2.0.15 dev_dependencies: build_runner: ^2.4.4 -- libgit2 0.22.2