Commit 37b78a156574d282e2faf00fdace9de421818ce4

Authored by liangchengyou
1 parent c948a9ea

feat:添加录音插件

ios/Runner/XSMessageMehtodChannel.swift
@@ -65,6 +65,24 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { @@ -65,6 +65,24 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
65 SSOralEvaluatingManager.share().startEvaluateOral(with: config) 65 SSOralEvaluatingManager.share().startEvaluateOral(with: config)
66 } 66 }
67 67
  68 + //开始评测(本地音频文件)
  69 + func evaluateLocalVoice(dict:Dictionary<String, Any>) {
  70 + let text = dict["word"] as? String ?? ""
  71 + let type = dict["type"] as? String ?? "0"
  72 + let userId = dict["userId"] as? String ?? "guest"
  73 + let voicePath = dict["voicePath"] as? String ?? ""
  74 + let config = SSOralEvaluatingConfig()
  75 + config.oralContent = text
  76 + if (type == "0") {
  77 + config.oralType = .word
  78 + } else {
  79 + config.oralType = .sentence
  80 + }
  81 + config.oralType = .kidSent
  82 + config.userId = userId
  83 + SSOralEvaluatingManager.share().startEvaluateOral(withWavPath: voicePath, config: config)
  84 + }
  85 +
68 func handle(_ call: FlutterMethodCall,_ result: @escaping FlutterResult) { 86 func handle(_ call: FlutterMethodCall,_ result: @escaping FlutterResult) {
69 if (call.method == "initVoiceSdk") { 87 if (call.method == "initVoiceSdk") {
70 self.setEvaluateConfig(dict:call.arguments as! Dictionary<String, Any>) 88 self.setEvaluateConfig(dict:call.arguments as! Dictionary<String, Any>)
@@ -75,6 +93,11 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { @@ -75,6 +93,11 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
75 return 93 return
76 } 94 }
77 95
  96 + if (call.method == "starLocalVoice") {
  97 + self.evaluateLocalVoice(dict: call.arguments as! Dictionary<String, Any>)
  98 + return
  99 + }
  100 +
78 if (call.method == "stopVoice") { 101 if (call.method == "stopVoice") {
79 SSOralEvaluatingManager.share().stopEvaluate(); 102 SSOralEvaluatingManager.share().stopEvaluate();
80 return 103 return
lib/pages/repeatafter/widgets/repeat_after_item.dart
@@ -19,12 +19,13 @@ class RepeatAfterItem extends StatelessWidget { @@ -19,12 +19,13 @@ class RepeatAfterItem extends StatelessWidget {
19 ), 19 ),
20 child: GestureDetector( 20 child: GestureDetector(
21 onTap: (){ 21 onTap: (){
22 - if (entity != null) {  
23 - // if (!entity!.lock!) {  
24 - // tapEvent?.call();  
25 - // }  
26 - tapEvent?.call();  
27 - } 22 + ///todo 暂时注释调,测试用
  23 + // if (entity != null) {
  24 + // if (!entity!.lock!) {
  25 + // tapEvent?.call();
  26 + // }
  27 + // }
  28 + tapEvent?.call();
28 }, 29 },
29 child: Stack( 30 child: Stack(
30 children: [ 31 children: [
lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart
@@ -3,7 +3,6 @@ import &#39;package:flutter/cupertino.dart&#39;; @@ -3,7 +3,6 @@ import &#39;package:flutter/cupertino.dart&#39;;
3 import 'package:flutter/services.dart'; 3 import 'package:flutter/services.dart';
4 import 'package:flutter_bloc/flutter_bloc.dart'; 4 import 'package:flutter_bloc/flutter_bloc.dart';
5 import 'package:wow_english/common/request/dao/listen_dao.dart'; 5 import 'package:wow_english/common/request/dao/listen_dao.dart';
6 -  
7 import '../../../common/request/exception.dart'; 6 import '../../../common/request/exception.dart';
8 import '../../../models/read_content_entity.dart'; 7 import '../../../models/read_content_entity.dart';
9 import '../../../utils/loading.dart'; 8 import '../../../utils/loading.dart';
@@ -196,8 +195,8 @@ class RepeatAfterContentBloc extends Bloc&lt;RepeatAfterContentEvent, RepeatAfterCo @@ -196,8 +195,8 @@ class RepeatAfterContentBloc extends Bloc&lt;RepeatAfterContentEvent, RepeatAfterCo
196 void _voiceXsResult(XSVoiceResultEvent event,Emitter<RepeatAfterContentState> emitter) async { 195 void _voiceXsResult(XSVoiceResultEvent event,Emitter<RepeatAfterContentState> emitter) async {
197 final Map args = event.message as Map; 196 final Map args = event.message as Map;
198 final result = args['result'] as Map; 197 final result = args['result'] as Map;
199 - final overall = result['overall'].toString()??'';  
200 - final audioUrl = args['audioUrl'].toString()??''; 198 + final overall = result['overall'].toString();
  199 + final audioUrl = args['audioUrl'].toString();
201 _voiceTestResult = {'overall':overall,'audioUrl':audioUrl}; 200 _voiceTestResult = {'overall':overall,'audioUrl':audioUrl};
202 emitter(XSVoiceTestState()); 201 emitter(XSVoiceTestState());
203 } 202 }
pubspec.yaml
@@ -93,6 +93,10 @@ dependencies: @@ -93,6 +93,10 @@ dependencies:
93 responsive_framework: ^1.0.0 93 responsive_framework: ^1.0.0
94 # 音频播放 https://pub.dev/packages/audioplayers 94 # 音频播放 https://pub.dev/packages/audioplayers
95 audioplayers: ^4.1.0 95 audioplayers: ^4.1.0
  96 + # 语音录制 https://pub.dev/packages/flutter_sound
  97 + flutter_sound: ^9.2.13
  98 + # 文件管理 https://pub.dev/packages/path_provider
  99 + path_provider: ^2.0.15
96 100
97 dev_dependencies: 101 dev_dependencies:
98 build_runner: ^2.4.4 102 build_runner: ^2.4.4