Selaa lähdekoodia

完善腾讯语音评测功能

hwh97 6 vuotta sitten
vanhempi
commit
7d337b3ab3

+ 16 - 16
.idea/workspace.xml

@@ -6,13 +6,12 @@
   </component>
   <component name="ChangeListManager">
     <list default="true" id="91fb8cbe-3946-4eca-a4cf-05dab52b73c6" name="Default Changelist" comment="">
-      <change afterPath="$PROJECT_DIR$/android/src/main/kotlin/cn/i2edu/speech_plugin/util/SmartOralAudioEvaluatorUtil.kt" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/android/src/main/assets/hello_guagua.mp3" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/android/.idea/caches/build_file_checksums.ser" beforeDir="false" afterPath="$PROJECT_DIR$/android/.idea/caches/build_file_checksums.ser" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/android/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/android/build.gradle" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/android/src/main/kotlin/cn/i2edu/speech_plugin/SpeechPlugin.kt" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/kotlin/cn/i2edu/speech_plugin/SpeechPlugin.kt" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/android/src/main/kotlin/cn/i2edu/speech_plugin/util/ChivoxAudioEvaluatorUtil.kt" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/kotlin/cn/i2edu/speech_plugin/util/ChivoxAudioEvaluatorUtil.kt" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/lib/speech_plugin.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/speech_plugin.dart" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/android/src/main/kotlin/cn/i2edu/speech_plugin/util/SmartOralAudioEvaluatorUtil.kt" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/kotlin/cn/i2edu/speech_plugin/util/SmartOralAudioEvaluatorUtil.kt" afterDir="false" />
     </list>
     <ignored path="$PROJECT_DIR$/.dart_tool/" />
     <ignored path="$PROJECT_DIR$/.idea/" />
@@ -36,8 +35,8 @@
       <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/lib/speech_plugin.dart">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="308">
-              <caret line="16" lean-forward="true" selection-start-line="16" selection-end-line="16" />
+            <state relative-caret-position="285">
+              <caret line="78" column="31" lean-forward="true" selection-start-line="78" selection-start-column="31" selection-end-line="78" selection-end-column="31" />
             </state>
           </provider>
         </entry>
@@ -56,6 +55,7 @@
   <component name="FindInProjectRecents">
     <findStrings>
       <find>invokeMethod</find>
+      <find>soeAppId</find>
     </findStrings>
   </component>
   <component name="Git.Settings">
@@ -80,9 +80,6 @@
       <foldersAlwaysOnTop value="true" />
     </navigator>
     <panes>
-      <pane id="Scope" />
-      <pane id="PackagesPane" />
-      <pane id="AndroidView" />
       <pane id="ProjectPane">
         <subPane>
           <expand>
@@ -103,12 +100,15 @@
           <select />
         </subPane>
       </pane>
+      <pane id="PackagesPane" />
+      <pane id="AndroidView" />
+      <pane id="Scope" />
     </panes>
   </component>
   <component name="PropertiesComponent">
     <property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
     <property name="dart.analysis.tool.window.force.activate" value="false" />
-    <property name="last_opened_file_path" value="$PROJECT_DIR$/android" />
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
     <property name="settings.editor.selected.configurable" value="flutter.settings" />
     <property name="show.migrate.to.gradle.popup" value="false" />
   </component>
@@ -154,7 +154,7 @@
       <window_info anchor="bottom" id="Run" order="1" weight="0.329718" />
       <window_info anchor="bottom" id="TODO" order="2" />
       <window_info anchor="bottom" id="Android Profiler" order="3" show_stripe_button="false" />
-      <window_info active="true" anchor="bottom" id="Logcat" order="4" visible="true" weight="0.329718" />
+      <window_info active="true" anchor="bottom" id="Logcat" order="4" visible="true" weight="0.3286334" />
       <window_info anchor="bottom" id="Debug" order="5" />
       <window_info anchor="bottom" id="Terminal" order="6" weight="0.329718" />
       <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
@@ -198,17 +198,17 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/.gitignore">
+    <entry file="file://$PROJECT_DIR$/lib/speech_plugin.dart">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="154">
-          <caret line="7" selection-start-line="7" selection-end-line="7" />
+        <state relative-caret-position="285">
+          <caret line="78" column="31" lean-forward="true" selection-start-line="78" selection-start-column="31" selection-end-line="78" selection-end-column="31" />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/lib/speech_plugin.dart">
+    <entry file="file://$PROJECT_DIR$/.gitignore">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="308">
-          <caret line="16" lean-forward="true" selection-start-line="16" selection-end-line="16" />
+        <state relative-caret-position="154">
+          <caret line="7" selection-start-line="7" selection-end-line="7" />
         </state>
       </provider>
     </entry>

BIN
android/.idea/caches/build_file_checksums.ser


+ 1 - 1
android/build.gradle

@@ -46,6 +46,6 @@ dependencies {
     implementation 'com.googlecode.mp4parser:isoparser:1.0-RC-37'
     api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
     implementation 'com.alibaba:fastjson:1.1.71.android'
-    implementation 'com.tencent.taisdk:taisdk:1.2.0.61'
+    implementation 'com.tencent.taisdk:taisdk:1.2.3.3'
     implementation fileTree(dir: 'src\\main\\jniLibs', include: ['*.aar', '*.jar'], exclude: [])
 }

+ 7 - 6
android/src/main/kotlin/cn/i2edu/speech_plugin/SpeechPlugin.kt

@@ -3,6 +3,7 @@ package cn.i2edu.speech_plugin
 import android.app.Activity
 import android.content.Context
 import android.text.TextUtils
+import android.util.Log
 import cn.i2edu.dubbing_lib.bean.SimpleWord
 import cn.i2edu.speech_plugin.audioUtils.audioEvaluator.resultParse.ReadSentenceResult
 import cn.i2edu.speech_plugin.audioUtils.audioEvaluator.resultParse.XmlResultParser
@@ -62,7 +63,7 @@ class SpeechPlugin : MethodCallHandler {
                 val sdkType = call.argument<Int>("sdkType")!!
                 evaluatorType = call.argument<Int>("evaluatorType")!!
 
-                evaluatorRecord(pathEvaluatorDecode, index, recordPath, en, false, if (sdkType == 1) SpeechSdk.Chivox else SpeechSdk.IFly)
+                evaluatorRecord(pathEvaluatorDecode, index, recordPath, en, false, if (sdkType == 1) SpeechSdk.Chivox else if (sdkType == 2) SpeechSdk.SmartOral else SpeechSdk.IFly)
             }
             call.method == "evaluatorByMp4" -> {
                 val pathEvaluatorDecode = call.argument<String>("pathEvaluatorDecode")!!
@@ -73,7 +74,7 @@ class SpeechPlugin : MethodCallHandler {
                 val sdkType = call.argument<Int>("sdkType")!!
                 evaluatorType = call.argument<Int>("evaluatorType")!!
 
-                evaluatorVideoRecord(pathEvaluatorDecode, index, videoId, recordPath, en, if (sdkType == 1) SpeechSdk.Chivox else SpeechSdk.IFly)
+                evaluatorVideoRecord(pathEvaluatorDecode, index, videoId, recordPath, en, if (sdkType == 1) SpeechSdk.Chivox else if (sdkType == 2) SpeechSdk.SmartOral else SpeechSdk.IFly)
             }
             else -> result.notImplemented()
         }
@@ -140,11 +141,11 @@ class SpeechPlugin : MethodCallHandler {
                         override fun onResult(result: TAIOralEvaluationRet?) {
                             val formatWords = arrayListOf<SimpleWord>()
                             for (detail in result!!.words) {
-                                formatWords.add(SimpleWord(detail.word, if (detail.pronAccuracy == -1.0 ) 0f else (detail.pronAccuracy * 5).toFloat()))
+                                formatWords.add(SimpleWord(detail.word, if (detail.pronAccuracy == -1.0 ) 0f else (detail.pronAccuracy / 20).toFloat()))
                             }
-                            val pronAccuracy = if (result.pronAccuracy == -1.0 ) 0f else (result.pronAccuracy * 5).toFloat()
-                            val pronFluency = result.pronFluency
-                            val pronCompletion = result.pronCompletion
+                            val pronAccuracy = if (result.pronAccuracy == -1.0 ) 0f else (result.pronAccuracy / 20).toFloat()
+                            val pronFluency = (result.pronFluency * 5).toFloat()
+                            val pronCompletion = (result.pronCompletion * 5).toFloat()
 
                             val totalScore = (pronAccuracy + pronFluency + pronCompletion) / 3
                             invokeEvaluatorResult(index, score = totalScore.toFloat(), integrityScore = pronCompletion.toFloat(),

+ 27 - 17
android/src/main/kotlin/cn/i2edu/speech_plugin/util/SmartOralAudioEvaluatorUtil.kt

@@ -5,6 +5,7 @@ import android.util.Log
 import cn.i2edu.speech_plugin.audioUtils.audiotransfer.DecodeEngine
 import cn.i2edu.speech_plugin.audioUtils.audiotransfer.DecodeOperateInterface
 import com.tencent.taisdk.*
+import com.tencent.taisdk.TAIErrCode.SUCC
 import java.io.File
 import java.io.FileInputStream
 import com.tencent.taisdk.TAIOralEvaluationFileType
@@ -12,10 +13,12 @@ import com.tencent.taisdk.TAIOralEvaluationServerType
 import com.tencent.taisdk.TAIOralEvaluationStorageMode
 import com.tencent.taisdk.TAIOralEvaluationEvalMode
 import com.tencent.taisdk.TAIOralEvaluationWorkMode
-import java.util.UUID
 import com.tencent.taisdk.TAIOralEvaluationParam
-
-
+import java.util.*
+import android.system.Os.close
+import java.io.InputStream
+import android.system.Os.close
+import java.io.IOException
 
 interface SmartOralEvaluatorCallBack {
     fun onResult(result: TAIOralEvaluationRet?)
@@ -43,27 +46,35 @@ class SmartOralAudioEvaluatorUtil private constructor(val context: Context) {
 
     fun startEvaluator(en: String, filePath: String, decodedFilePath: String) {
         oral = TAIOralEvaluation()
-        oral?.setListener(object : TAIOralEvaluationListener {
-            override fun onEvaluationData(data: TAIOralEvaluationData?, result: TAIOralEvaluationRet?, error: TAIError?) {
-                if (data?.bEnd == true) {
-                    smartOralEvaluatorCallBack?.onResult(result)
+        oral?.setListener(object: TAIOralEvaluationListener {
+            override fun onVolumeChanged(p0: Int) {
+            }
+
+            override fun onEvaluationData(p0: TAIOralEvaluationData?, p1: TAIOralEvaluationRet?, p2: TAIError?) {
+                if (p0?.bEnd == true && p2?.code == SUCC) {
+                    Log.d(TAG, "result: ${p1?.pronFluency}, ${p1?.pronCompletion}, ${p1?.pronAccuracy}")
+                    smartOralEvaluatorCallBack?.onResult(p1)
                 } else {
-                    Log.e(TAG, "error code: ${error?.code} message: ${error?.desc}")
-                    smartOralEvaluatorCallBack?.onError(error?.desc ?: "")
+                    Log.e(TAG, "error code: ${p2?.code} message: ${p2?.desc}")
+                    smartOralEvaluatorCallBack?.onError(p2?.desc ?: "")
                 }
             }
+
+            override fun onEndOfSpeech() {
+            }
         })
         val param = TAIOralEvaluationParam()
         param.context = context
-        param.appId = ""
-        param.secretId = ""
-        param.secretKey = ""
+        param.appId = "1301049120"
+        param.secretId = "AKIDUf0EEzc8NMpPmu4Po1zhXBZicKp5G7xZ"
+        param.secretKey = "WnsjKaqtgDVbV9cMtABwVptarwpWyBAt"
         param.sessionId = UUID.randomUUID().toString()
         param.workMode = TAIOralEvaluationWorkMode.ONCE
         param.evalMode = TAIOralEvaluationEvalMode.SENTENCE
         param.storageMode = TAIOralEvaluationStorageMode.DISABLE
         param.serverType = TAIOralEvaluationServerType.ENGLISH
-        param.fileType = TAIOralEvaluationFileType.MP3//只支持mp3
+        param.fileType = TAIOralEvaluationFileType.WAV// 只支持mp3
+        param.soeAppId = "soe_1002252"
         param.scoreCoeff = 1.0
         param.refText = en
         Thread {
@@ -73,20 +84,19 @@ class SmartOralAudioEvaluatorUtil private constructor(val context: Context) {
 
                 override fun decodeSuccess() {
                     try {
+
                         val file = File(decodedFilePath)
-                        val fileInputStream = FileInputStream(file)
-                        val buffer = ByteArray(fileInputStream.available())
+                        val bytes: ByteArray = file.readBytes()
 
                         val data = TAIOralEvaluationData()
                         data.seqId = 1
                         data.bEnd = true
-                        data.audio = buffer
+                        data.audio = bytes
                         oral?.oralEvaluation(param, data, TAIOralEvaluationCallback {
                             //接口调用结果返回
                             Log.d(TAG, "oralEvaluation call result: ${it?.code ?: "error null"}")
                         })
                         file.delete()
-                        fileInputStream.close()
                     } catch (e: Exception) {
                         e.printStackTrace()
                         smartOralEvaluatorCallBack?.onError("failed ${e.message}")