Commit dae7f2fdfad70424942de10f37b470be6421d580
1 parent
cacfac41
feat:增加android端先声评测(自己录音,先声只评测)
Showing
7 changed files
with
43 additions
and
16 deletions
android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/methodChannels/SingSoungMethodChannel.kt
@@ -18,6 +18,7 @@ import java.lang.ref.WeakReference | @@ -18,6 +18,7 @@ import java.lang.ref.WeakReference | ||
18 | */ | 18 | */ |
19 | class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEngine): SingEngineLifecycles.OnSingEngineAdapter() { | 19 | class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEngine): SingEngineLifecycles.OnSingEngineAdapter() { |
20 | private var methodChannel: MethodChannel? = null | 20 | private var methodChannel: MethodChannel? = null |
21 | + private val TAG = "SingSoungMethodChannel" | ||
21 | 22 | ||
22 | companion object { | 23 | companion object { |
23 | var channel: WeakReference<SingSoungMethodChannel>? = null | 24 | var channel: WeakReference<SingSoungMethodChannel>? = null |
@@ -36,20 +37,29 @@ class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEn | @@ -36,20 +37,29 @@ class SingSoungMethodChannel(activity: FlutterActivity, flutterEngine: FlutterEn | ||
36 | ) | 37 | ) |
37 | init(activity) | 38 | init(activity) |
38 | methodChannel?.setMethodCallHandler { call, result -> | 39 | methodChannel?.setMethodCallHandler { call, result -> |
40 | + Log.d(TAG, "SingSoungMethodChannel CALL=${call.method} ${call.arguments}") | ||
39 | when (call.method) { | 41 | when (call.method) { |
40 | "initVoiceSdk" -> { | 42 | "initVoiceSdk" -> { |
41 | 43 | ||
42 | } | 44 | } |
43 | "startVoice" -> { | 45 | "startVoice" -> { |
44 | val paramMap = call.arguments as HashMap<String, String> | 46 | val paramMap = call.arguments as HashMap<String, String> |
45 | - Log.d("WQF", "SingSoungMethodChannel startVoice=${call.arguments.javaClass} paramMap=$paramMap") | 47 | + Log.d(TAG, "SingSoungMethodChannel startVoice=${call.arguments.javaClass} paramMap=$paramMap") |
46 | paramMap["word"]?.let { SingEngineHelper.startRecord(it) } | 48 | paramMap["word"]?.let { SingEngineHelper.startRecord(it) } |
47 | - //do nothing | ||
48 | } | 49 | } |
49 | "stopVoice" -> { | 50 | "stopVoice" -> { |
50 | - Log.d("WQF", "SingSoungMethodChannel stopVoice") | 51 | + Log.d(TAG, "SingSoungMethodChannel stopVoice") |
51 | SingEngineHelper.stopRecord() | 52 | SingEngineHelper.stopRecord() |
52 | } | 53 | } |
54 | + "startLocalVoice" -> { | ||
55 | + val paramMap = call.arguments as HashMap<String, String> | ||
56 | + Log.d(TAG, "SingSoungMethodChannel startLocalVoice=${call.arguments.javaClass} paramMap=$paramMap") | ||
57 | + paramMap["voicePath"]?.let { voiceFilePath -> | ||
58 | + paramMap["word"]?.let { evaluateContent -> | ||
59 | + SingEngineHelper.evaluate(voiceFilePath, evaluateContent) } | ||
60 | + } | ||
61 | + | ||
62 | + } | ||
53 | else -> { | 63 | else -> { |
54 | result.notImplemented() | 64 | result.notImplemented() |
55 | } | 65 | } |
android/app/src/main/kotlin/com/kouyuxingqiu/wow_english/singsound/SingEngineHelper.kt
@@ -106,8 +106,29 @@ object SingEngineHelper : | @@ -106,8 +106,29 @@ object SingEngineHelper : | ||
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | - // 开始语音评测 | ||
110 | - fun startRecord(originText: String, @EvalTargetType evalTargetType: Int? = EvalTargetType.SENTENCE) { | 109 | + // 开始语音评测(先声录音+评测) |
110 | + fun startRecord(originText: String, @EvalTargetType evalTargetType: Int? = EvalTargetType.SENTENCE, userId: String? = VoiceConfig.UserID) { | ||
111 | + buildEvaluateConfig(originText, evalTargetType, userId) | ||
112 | + //开始测评 | ||
113 | + mSingEngine?.start() | ||
114 | + mCurEvalType = evalTargetType | ||
115 | + Log.w(TAG, "startRecord originText=$originText evalTargetType =$evalTargetType") | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * 评测外部录音文件 | ||
120 | + * @param voiceFilePath 录音文件路径 | ||
121 | + */ | ||
122 | + fun evaluate(voiceFilePath: String, originText: String, @EvalTargetType evalTargetType: Int? = EvalTargetType.SENTENCE, userId: String? = VoiceConfig.UserID) { | ||
123 | + buildEvaluateConfig(originText, evalTargetType, userId) | ||
124 | + if (mIsReady) { | ||
125 | + mSingEngine?.startWithPCM(voiceFilePath) | ||
126 | + Log.w(TAG, "startWithPCM") | ||
127 | + } | ||
128 | + mCurEvalType = evalTargetType | ||
129 | + } | ||
130 | + | ||
131 | + private fun buildEvaluateConfig(originText: String, @EvalTargetType evalTargetType: Int? = EvalTargetType.SENTENCE, userId: String? = VoiceConfig.UserID) { | ||
111 | try { | 132 | try { |
112 | val request = JSONObject() | 133 | val request = JSONObject() |
113 | when (evalTargetType) { | 134 | when (evalTargetType) { |
@@ -130,7 +151,6 @@ object SingEngineHelper : | @@ -130,7 +151,6 @@ object SingEngineHelper : | ||
130 | .put("typeThres", SingSoundConfig.BASE_TYPETHRES) | 151 | .put("typeThres", SingSoundConfig.BASE_TYPETHRES) |
131 | .put("precision", 1) // 评分精度,默认1 | 152 | .put("precision", 1) // 评分精度,默认1 |
132 | .put("attachAudioUrl", 1) // 评分结果中是否包含音频 url | 153 | .put("attachAudioUrl", 1) // 评分结果中是否包含音频 url |
133 | - .put("userId", "test") | ||
134 | .put("phones", jsonObj) // 指定单词的发音。 | 154 | .put("phones", jsonObj) // 指定单词的发音。 |
135 | .put("rank", 100) | 155 | .put("rank", 100) |
136 | } else { | 156 | } else { |
@@ -161,16 +181,12 @@ object SingEngineHelper : | @@ -161,16 +181,12 @@ object SingEngineHelper : | ||
161 | } | 181 | } |
162 | 182 | ||
163 | //构建评测请求参数 | 183 | //构建评测请求参数 |
164 | - val startCfg = mSingEngine?.buildStartJson(VoiceConfig.UserID, request) | 184 | + val startCfg = mSingEngine?.buildStartJson(userId, request) |
165 | //设置评测请求参数 | 185 | //设置评测请求参数 |
166 | mSingEngine?.setStartCfg(startCfg) | 186 | mSingEngine?.setStartCfg(startCfg) |
167 | - //开始测评 | ||
168 | - mSingEngine?.start() | ||
169 | - mCurEvalType = evalTargetType | ||
170 | } catch (e: Exception) { | 187 | } catch (e: Exception) { |
171 | e.printStackTrace() | 188 | e.printStackTrace() |
172 | } | 189 | } |
173 | - Log.w(TAG, "startRecord originText=$originText evalTargetType =$evalTargetType") | ||
174 | } | 190 | } |
175 | 191 | ||
176 | fun stopRecord() { // 停止录音(有回调) | 192 | fun stopRecord() { // 停止录音(有回调) |
ios/Runner/XSMessageMehtodChannel.swift
@@ -93,7 +93,7 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { | @@ -93,7 +93,7 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { | ||
93 | return | 93 | return |
94 | } | 94 | } |
95 | 95 | ||
96 | - if (call.method == "starLocalVoice") { | 96 | + if (call.method == "startLocalVoice") { |
97 | self.evaluateLocalVoice(dict: call.arguments as! Dictionary<String, Any>) | 97 | self.evaluateLocalVoice(dict: call.arguments as! Dictionary<String, Any>) |
98 | return | 98 | return |
99 | } | 99 | } |
lib/pages/reading/bloc/reading_bloc.dart
@@ -7,6 +7,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; | @@ -7,6 +7,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; | ||
7 | import 'package:permission_handler/permission_handler.dart'; | 7 | import 'package:permission_handler/permission_handler.dart'; |
8 | import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart'; | 8 | import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart'; |
9 | 9 | ||
10 | +import '../../../common/core/user_util.dart'; | ||
10 | import '../../../common/request/dao/listen_dao.dart'; | 11 | import '../../../common/request/dao/listen_dao.dart'; |
11 | import '../../../common/request/exception.dart'; | 12 | import '../../../common/request/exception.dart'; |
12 | import '../../../models/course_process_entity.dart'; | 13 | import '../../../models/course_process_entity.dart'; |
@@ -296,7 +297,7 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { | @@ -296,7 +297,7 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> { | ||
296 | ); | 297 | ); |
297 | if (result) { | 298 | if (result) { |
298 | methodChannel.invokeMethod( | 299 | methodChannel.invokeMethod( |
299 | - 'startVoice', {'word': content, 'type': '0', 'userId': '1'}); | 300 | + 'startVoice', {'word': content, 'type': '0', 'userId': UserUtil.getUser()?.id.toString()}); |
300 | } | 301 | } |
301 | } | 302 | } |
302 | 303 |
lib/pages/reading/bloc/reading_event.dart
@@ -38,7 +38,7 @@ class XSVoiceResultEvent extends ReadingPageEvent { | @@ -38,7 +38,7 @@ class XSVoiceResultEvent extends ReadingPageEvent { | ||
38 | class XSVoiceStartEvent extends ReadingPageEvent { | 38 | class XSVoiceStartEvent extends ReadingPageEvent { |
39 | final String content; | 39 | final String content; |
40 | final String type; | 40 | final String type; |
41 | - final String userId; | 41 | + final String? userId; |
42 | XSVoiceStartEvent(this.content,this.type,this.userId); | 42 | XSVoiceStartEvent(this.content,this.type,this.userId); |
43 | } | 43 | } |
44 | 44 |
lib/pages/reading/reading_page.dart
@@ -179,7 +179,7 @@ class _ReadingPage extends StatelessWidget { | @@ -179,7 +179,7 @@ class _ReadingPage extends StatelessWidget { | ||
179 | bloc.add(XSVoiceStartEvent( | 179 | bloc.add(XSVoiceStartEvent( |
180 | bloc.currentPageData()?.word ?? '', | 180 | bloc.currentPageData()?.word ?? '', |
181 | '0', | 181 | '0', |
182 | - UserUtil.getUser()!.id.toString())); | 182 | + UserUtil.getUser()?.id.toString())); |
183 | } | 183 | } |
184 | }, | 184 | }, |
185 | child: Image.asset( | 185 | child: Image.asset( |
lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart
@@ -197,7 +197,7 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo | @@ -197,7 +197,7 @@ class RepeatAfterContentBloc extends Bloc<RepeatAfterContentEvent, RepeatAfterCo | ||
197 | ///先声测试 | 197 | ///先声测试 |
198 | void _voiceXsTest(XSVoiceTestEvent event,Emitter<RepeatAfterContentState> emitter) async { | 198 | void _voiceXsTest(XSVoiceTestEvent event,Emitter<RepeatAfterContentState> emitter) async { |
199 | await methodChannel.invokeMethod( | 199 | await methodChannel.invokeMethod( |
200 | - 'starLocalVoice', | 200 | + 'startLocalVoice', |
201 | { | 201 | { |
202 | 'type':event.type, | 202 | 'type':event.type, |
203 | 'word':event.testWord, | 203 | 'word':event.testWord, |