Browse Source

add

newdev_shunjiawei
fdp 1 year ago
parent
commit
21b7077a4f
  1. 11
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt
  2. 21
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt
  3. 13
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/tools/RecordFile.kt
  4. 4
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt
  5. 3
      local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt

11
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt

@ -587,13 +587,14 @@ class AzureAsrHelper(private val context: Context) {
recordfile!!.creatingFiles(filePath)
}
/**
* 移动文件到新路径
*/
fun moveFile(sourcePath: String, destPath: String): Boolean {
Log.i(tag, "移动文件到新路径:")
recordfile!!.moveFile(sourcePath,destPath)
recordfile!!.moveFile(sourcePath, destPath)
return true
}
@ -605,7 +606,7 @@ class AzureAsrHelper(private val context: Context) {
Log.i(tag, "重命名指定路径的音频文件:")
recordfile!!.renameFile(filePath,newName)
recordfile!!.renameFile(filePath, newName)
return true
}
@ -615,17 +616,17 @@ class AzureAsrHelper(private val context: Context) {
fun pauseRecord() {
Log.i(tag, "停止连续录音:")
recordfile!!.isPause=true
recordfile!!.isPause = true
}
/**
* 关闭录音
*/
fun stopRecord(isSave:Boolean) {
fun stopRecord(isSave: Boolean) {
Log.i(tag, "关闭录音:")
recordfile!!.isPause=false
recordfile!!.isPause = false
recordfile!!.closeFile(isSave)
}

21
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt

@ -11,7 +11,6 @@ import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.EventChannel
import com.microsoft.cognitiveservices.speech.audio.*
import com.deep_voice.speech.tts.TtsEvent
import com.deep_voice.speech.tts.TtsEventListener
import com.deep_voice.speech.tts.TtsEventType
@ -356,30 +355,32 @@ class AzureSpeechPlugin : BleService.Callback, FlutterPlugin {
"renameFile" -> {
val filePath = call.argument<String>("filePath")?: ""
val newName = call.argument<String>("newName")?: ""
val filePath = call.argument<String>("filePath") ?: ""
val newName = call.argument<String>("newName") ?: ""
try {
FileLogger.d(tag, "音频文件名称为: ${filePath}") //
azureAsrHelper.renameFile(filePath,newName)
azureAsrHelper.renameFile(filePath, newName)
result.success(true)
} catch (e: Exception) {
result.error("ENABLERECORD_ERROR", e.message, null)
}
}
"moveFile" -> {
val sourcePath = call.argument<String>("sourcePath")?: ""
val destPath = call.argument<String>("destPath")?: ""
val sourcePath = call.argument<String>("sourcePath") ?: ""
val destPath = call.argument<String>("destPath") ?: ""
try {
FileLogger.d(tag, "音频文件名称为: ${sourcePath}") //
azureAsrHelper.moveFile(sourcePath,destPath)
azureAsrHelper.moveFile(sourcePath, destPath)
result.success(true)
} catch (e: Exception) {
result.error("ENABLERECORD_ERROR", e.message, null)
}
}
"enableRecord" -> {
val filePath = call.argument<String>("filePath")?: ""
val filePath = call.argument<String>("filePath") ?: ""
try {
FileLogger.d(tag, "音频文件名称为: ${filePath}") //
@ -389,12 +390,14 @@ class AzureSpeechPlugin : BleService.Callback, FlutterPlugin {
result.error("ENABLERECORD_ERROR", e.message, null)
}
}
"pauseRecord" -> {
azureAsrHelper.pauseRecord()
result.success(true)
}
"stopRecord" -> {
val isSave = call.argument<Boolean>("isSave")?:false
val isSave = call.argument<Boolean>("isSave") ?: false
try {
azureAsrHelper.stopRecord(isSave)
result.success(true)

13
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/tools/RecordFile.kt

@ -1,4 +1,5 @@
package com.yunqiinnovation.azure_speech.tools
import java.io.File
import java.io.FileOutputStream
import java.io.RandomAccessFile
@ -8,7 +9,7 @@ import java.io.FileInputStream
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.atomic.AtomicBoolean
object RecordFile {
object RecordFile {
private var currentAudioFile: File? = null
private var fos: FileOutputStream? = null
@ -156,7 +157,8 @@ import java.util.concurrent.atomic.AtomicBoolean
false
}
}
/**
/**
* 移动文件到新路径
* @param sourcePath 原始文件完整路径
* @param destPath 目标文件完整路径
@ -213,7 +215,8 @@ import java.util.concurrent.atomic.AtomicBoolean
false
}
}
internal fun closeFile( isSave:Boolean): Boolean {
internal fun closeFile(isSave: Boolean): Boolean {
try {
if (fos == null || currentAudioFile == null) {
return false
@ -223,7 +226,7 @@ import java.util.concurrent.atomic.AtomicBoolean
fos?.close()
currentAudioFile?.let { file ->
if (file.length() <= 44||isSave==false) {
if (file.length() <= 44 || isSave == false) {
file.delete()
Log.d("tag", "音频文件过小已删除: ${file.absolutePath}")
return false
@ -248,4 +251,4 @@ import java.util.concurrent.atomic.AtomicBoolean
}
return false
}
}
}

4
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt

@ -16,14 +16,10 @@ import com.jieli.jl_audio_decode.exceptions.OpusException
import java.io.File
import java.io.FileOutputStream
import java.io.RandomAccessFile
import java.text.SimpleDateFormat
import java.util.Date
import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.TimeUnit
import android.os.Handler
import android.os.HandlerThread
import java.util.concurrent.atomic.AtomicBoolean
import android.util.Log
/**

3
local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt

@ -297,8 +297,7 @@ class OtaPlugin : BleService.Callback, FlutterPlugin, MethodCallHandler {
Log.i("TAG", "onAttachedToEngine")
result.success("")
}
else if (call.method == "startUpgrading") {
} else if (call.method == "startUpgrading") {
Log.d("TAG", "startUpgrading")
// 接收传入的参数
val arguments = call.arguments as? Map<String, Any>

Loading…
Cancel
Save