Commit 6b0947ca40abfc92245504b958cccc6af9e6b574

Authored by 吴启风
1 parent dae7f2fd

feat:绘本增加initVoiceSdk(ios需要);页面销毁时取消先声评测

android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt
... ... @@ -44,22 +44,22 @@ class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEn
44 44 }
45 45 "startVoice" -> {
46 46 val paramMap = call.arguments as HashMap<String, String>
47   - Log.d(TAG, "SingSoungMethodChannel startVoice=${call.arguments.javaClass} paramMap=$paramMap")
48 47 paramMap["word"]?.let { SingEngineHelper.startRecord(it) }
49 48 }
50 49 "stopVoice" -> {
51   - Log.d(TAG, "SingSoungMethodChannel stopVoice")
52 50 SingEngineHelper.stopRecord()
53 51 }
54 52 "startLocalVoice" -> {
55 53 val paramMap = call.arguments as HashMap<String, String>
56   - Log.d(TAG, "SingSoungMethodChannel startLocalVoice=${call.arguments.javaClass} paramMap=$paramMap")
57 54 paramMap["voicePath"]?.let { voiceFilePath ->
58 55 paramMap["word"]?.let { evaluateContent ->
59 56 SingEngineHelper.evaluate(voiceFilePath, evaluateContent) }
60 57 }
61 58  
62 59 }
  60 + "cancelVoice" -> {
  61 + SingEngineHelper.cancel()
  62 + }
63 63 else -> {
64 64 result.notImplemented()
65 65 }
... ...
lib/pages/practice/bloc/topic_picture_bloc.dart
... ... @@ -124,6 +124,7 @@ class TopicPictureBloc extends Bloc&lt;TopicPictureEvent, TopicPictureState&gt; {
124 124 pageController.dispose();
125 125 audioPlayer.release();
126 126 audioPlayer.dispose();
  127 + _voiceXsCancel();
127 128 return super.close();
128 129 }
129 130  
... ... @@ -195,6 +196,11 @@ class TopicPictureBloc extends Bloc&lt;TopicPictureEvent, TopicPictureState&gt; {
195 196 methodChannel.invokeMethod('stopVoice');
196 197 }
197 198  
  199 + ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作)
  200 + void _voiceXsCancel() {
  201 + methodChannel.invokeMethod('cancelVoice');
  202 + }
  203 +
198 204 ///先声评测结果
199 205 void _voiceXsResult(XSVoiceResultEvent event,Emitter<TopicPictureState> emitter) async {
200 206 final Map args = event.message as Map;
... ...
lib/pages/reading/bloc/reading_bloc.dart
... ... @@ -167,6 +167,7 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
167 167 pageController.dispose();
168 168 audioPlayer.release();
169 169 audioPlayer.dispose();
  170 + _voiceXsCancel();
170 171 return super.close();
171 172 }
172 173  
... ... @@ -322,6 +323,11 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
322 323 methodChannel.invokeMethod('stopVoice');
323 324 }
324 325  
  326 + ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作)
  327 + void _voiceXsCancel() {
  328 + methodChannel.invokeMethod('cancelVoice');
  329 + }
  330 +
325 331 void _voicePlayStateChange(VoicePlayStateChangeEvent event,
326 332 Emitter<ReadingPageState> emitter) async {
327 333 emitter(VoicePlayStateChange());
... ...
lib/pages/reading/reading_page.dart
... ... @@ -5,6 +5,7 @@ import &#39;package:wow_english/common/extension/string_extension.dart&#39;;
5 5 import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart';
6 6 import 'package:wow_english/pages/reading/widgets/reading_dialog_widget.dart';
7 7  
  8 +import '../../common/core/app_consts.dart';
8 9 import '../../common/core/user_util.dart';
9 10 import '../../models/course_process_entity.dart';
10 11 import '../../utils/log_util.dart';
... ... @@ -20,7 +21,15 @@ class ReadingPage extends StatelessWidget {
20 21 return BlocProvider(
21 22 create: (_) => ReadingPageBloc(context, PageController(), courseLessonId ?? '')
22 23 ..add(InitBlocEvent())
23   - ..add(RequestDataEvent()),
  24 + ..add(RequestDataEvent())
  25 + ..add(XSVoiceInitEvent(
  26 + {
  27 + 'appKey':AppConsts.xsAppKey,
  28 + 'service':AppConsts.xsAppService,
  29 + 'secretKey':AppConsts.xsAppSecretKey,
  30 + 'userId':UserUtil.getUser()!.id.toString(),
  31 + }
  32 + )),
24 33 child: _ReadingPage(),
25 34 );
26 35 }
... ...
lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart
... ... @@ -100,6 +100,7 @@ class RepeatAfterContentBloc extends Bloc&lt;RepeatAfterContentEvent, RepeatAfterCo
100 100 @override
101 101 Future<void> close() {
102 102 _releaseFlauto();
  103 + _voiceXsCancel();
103 104 return super.close();
104 105 }
105 106  
... ... @@ -215,6 +216,11 @@ class RepeatAfterContentBloc extends Bloc&lt;RepeatAfterContentEvent, RepeatAfterCo
215 216 methodChannel.invokeMethod('stopVoice');
216 217 }
217 218  
  219 + ///取消评测(用于处理退出页面后录音未停止等异常情况的保护操作)
  220 + void _voiceXsCancel() {
  221 + methodChannel.invokeMethod('cancelVoice');
  222 + }
  223 +
218 224 ///先声评测结果
219 225 void _voiceXsResult(XSVoiceResultEvent event,Emitter<RepeatAfterContentState> emitter) async {
220 226 final Map args = event.message as Map;
... ...