Commit 31d42f066b548015d4ad38cf8fad54321acf581c

Authored by liangchengyou
1 parent 6b0947ca

feat:视频跟读录音修改

assets/images/sorrow_face.png 0 → 100644

8.23 KB

ios/Runner/XSMessageMehtodChannel.swift
... ... @@ -30,10 +30,10 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
30 30 if (!dict.keys.isEmpty) {
31 31 appKey = dict["appKey"] as? String ?? ""
32 32 secretKey = dict["secretKey"] as? String ?? ""
  33 + service = dict["service"] as? String ?? ""
33 34 userId = dict["userId"] as? String ?? "guest"
34 35 frontTime = dict["frontTime"] as? String ?? "3"
35 36 backTime = dict["frontTime"] as? String ?? "3"
36   - service = dict["service"] as? String ?? ""
37 37 }
38 38 let config = SSOralEvaluatingManagerConfig.init()
39 39 config.vad = true
... ... @@ -102,6 +102,11 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
102 102 SSOralEvaluatingManager.share().stopEvaluate();
103 103 return
104 104 }
  105 +
  106 + if (call.method == "cancelVoice") {
  107 + SSOralEvaluatingManager.share().cancelEvaluate();
  108 + return;
  109 + }
105 110 }
106 111  
107 112 //评测结果回调
... ...
lib/common/core/app_consts.dart
... ... @@ -11,7 +11,7 @@ class AppConsts {
11 11 static const String userTermSdkUrl = 'http://page.kouyuxingqiu.com/term_sdk.html';
12 12  
13 13 /// 先声SDK
14   - static String xsAppKey = BasicConfig().isTestDev?'t418':'a418';
  14 + static String xsAppKey = 'a418';
15 15 static String xsAppSecretKey = BasicConfig().isTestDev?'1a16f31f2611bf32fb7b3fc38f5b2c81':'c11163aa6c834a028da4a4b30955be99';
16 16 static String xsAppService = BasicConfig().isTestDev?'ws://trial.cloud.ssapi.cn:8080':'"wss://api.cloud.ssapi.cn';
17 17 }
... ...
lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart
... ... @@ -35,6 +35,8 @@ enum XSVoiceCheckState {
35 35 unKnow,
36 36 ///测评开始
37 37 start,
  38 + ///评测结果
  39 + result,
38 40 ///测评结束
39 41 stop,
40 42 }
... ... @@ -111,6 +113,11 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo
111 113 if (call.method == 'voiceResult') {//评测结果
112 114 add(XSVoiceResultEvent(call.arguments));
113 115 add(PostFollowReadContentEvent());
  116 + return;
  117 + }
  118 +
  119 + if (call.method == 'voiceEnd') {
  120 + return;
114 121 }
115 122 });
116 123  
... ... @@ -166,7 +173,6 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo
166 173 try {
167 174 await loading(() async {
168 175 _entityList = await ListenDao.followResult(_recordNumber.toString(),courseLessonId);
169   -
170 176 });
171 177 } catch (e) {
172 178 if (e is ApiException) {
... ... @@ -227,6 +233,7 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo
227 233 final result = args['result'] as Map;
228 234 final overall = result['overall'].toString();
229 235 _voiceTestResult = {'overall':overall};
  236 + _xSCheckState = XSVoiceCheckState.result;
230 237 emitter(XSVoiceTestState());
231 238 }
232 239  
... ... @@ -275,16 +282,13 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo
275 282 }
276 283 Directory tempDir = await getTemporaryDirectory();
277 284 var time = DateTime.now().millisecondsSinceEpoch;
278   - String path = '${tempDir.path}/$time${ext[Codec.aacADTS.index]}';
  285 + String path = '${tempDir.path}/$time${ext[Codec.pcm16WAV.index]}';
279 286  
280 287 _path = path;
281 288 debugPrint('=====> 准备开始录音');
282 289 await _soundRecorder.startRecorder(
283 290 toFile: path,
284   - codec: Codec.aacADTS,
285   - bitRate: 8000,
286   - numChannels: 1,
287   - sampleRate: 8000,
  291 + codec: Codec.pcm16WAV,
288 292 );
289 293 debugPrint('=====> 开始录音');
290 294 _voiceRecordState = VoiceRecordState.voiceRecording;
... ...
lib/pages/repeataftercontent/repeat_after_content_page.dart
... ... @@ -27,7 +27,6 @@ class RepeatAfterContentPage extends StatelessWidget {
27 27 'appKey':AppConsts.xsAppKey,
28 28 'service':AppConsts.xsAppService,
29 29 'secretKey':AppConsts.xsAppSecretKey,
30   - 'userId':UserUtil.getUser()!.id.toString(),
31 30 }
32 31 )),
33 32 child: _RepeatAfterContentPage(),
... ... @@ -158,6 +157,12 @@ class _RepeatAfterContentPage extends StatelessWidget {
158 157 ///播放中
159 158 Widget _buildPlayVideoWidget() {
160 159 return BlocBuilder<RepeatAfterContentBloc,RepeatAfterContentState>(
  160 + buildWhen: (previous, current) {
  161 + if (current is ChangeVideoPlayIndexEvent) {
  162 + return true;
  163 + }
  164 + return false;
  165 + },
161 166 builder: (context,state){
162 167 final bloc = BlocProvider.of<RepeatAfterContentBloc>(context);
163 168 return Column(
... ... @@ -252,28 +257,46 @@ class _RepeatAfterContentPage extends StatelessWidget {
252 257 builder: (context,state){
253 258 final bloc = BlocProvider.of<RepeatAfterContentBloc>(context);
254 259 final voiceResult = bloc.voiceTestResult;
  260 + Color color;
  261 + if (int.parse(voiceResult?['overall'].toString()??'0') >= 60 || int.parse(voiceResult?['overall'].toString()??'0') <= 75) {
  262 + color = const Color(0xFFFF0000);
  263 + } else if (int.parse(voiceResult?['overall'].toString()??'0') > 75 || int.parse(voiceResult?['overall'].toString()??'0') <= 85) {
  264 + color = const Color(0xFFFFCC00);
  265 + } else {
  266 + color = const Color(0xFF40E04B);
  267 + }
255 268 return Column(
256 269 mainAxisAlignment: MainAxisAlignment.end,
257 270 children: [
258 271 Offstage(
259   - // offstage: false,
260   - offstage:!(bloc.voiceRecordState == VoiceRecordState.voiceRecordEnd && bloc.xSCheckState == XSVoiceCheckState.stop),
  272 + offstage:!(bloc.voiceRecordState == VoiceRecordState.voiceRecordEnd && bloc.xSCheckState == XSVoiceCheckState.result),
261 273 child: Column(
262 274 children: [
263   - Container(
264   - height: 45.h,
265   - width: 45.h,
266   - alignment: Alignment.center,
267   - decoration: BoxDecoration(
268   - color: const Color(0xFF40E04B),
269   - borderRadius: BorderRadius.circular(22.5.r)
  275 + Offstage(
  276 + offstage:int.parse(voiceResult?['overall'].toString()??'0') > 60,
  277 + child: Image.asset(
  278 + 'sorrow_face'.assetPng,
  279 + height: 46.h,
  280 + width: 46.w,
270 281 ),
271   - child: Text(
272   - voiceResult?['overall'].toString()??'0',
273   - textAlign: TextAlign.center,
274   - style: TextStyle(
275   - color: Colors.white,
276   - fontSize: 17.sp
  282 + ),
  283 + Offstage(
  284 + offstage: int.parse(voiceResult?['overall'].toString()??'0') < 60,
  285 + child: Container(
  286 + height: 45.h,
  287 + width: 45.h,
  288 + alignment: Alignment.center,
  289 + decoration: BoxDecoration(
  290 + color: color,
  291 + borderRadius: BorderRadius.circular(22.5.r)
  292 + ),
  293 + child: Text(
  294 + voiceResult?['overall'].toString()??'0',
  295 + textAlign: TextAlign.center,
  296 + style: TextStyle(
  297 + color: Colors.white,
  298 + fontSize: 17.sp
  299 + ),
277 300 ),
278 301 ),
279 302 ),
... ... @@ -299,7 +322,6 @@ class _RepeatAfterContentPage extends StatelessWidget {
299 322 ),
300 323 ),
301 324 Offstage(
302   - // offstage: true,
303 325 offstage: bloc.voiceRecordState == VoiceRecordState.voiceRecordUnkonw || bloc.xSCheckState != XSVoiceCheckState.unKnow,
304 326 child: Container(
305 327 color: Colors.grey,
... ...