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) recordfile!!.creatingFiles(filePath)
} }
/** /**
* 移动文件到新路径 * 移动文件到新路径
*/ */
fun moveFile(sourcePath: String, destPath: String): Boolean { fun moveFile(sourcePath: String, destPath: String): Boolean {
Log.i(tag, "移动文件到新路径:") Log.i(tag, "移动文件到新路径:")
recordfile!!.moveFile(sourcePath,destPath) recordfile!!.moveFile(sourcePath, destPath)
return true return true
} }
@ -605,7 +606,7 @@ class AzureAsrHelper(private val context: Context) {
Log.i(tag, "重命名指定路径的音频文件:") Log.i(tag, "重命名指定路径的音频文件:")
recordfile!!.renameFile(filePath,newName) recordfile!!.renameFile(filePath, newName)
return true return true
} }
@ -615,17 +616,17 @@ class AzureAsrHelper(private val context: Context) {
fun pauseRecord() { fun pauseRecord() {
Log.i(tag, "停止连续录音:") Log.i(tag, "停止连续录音:")
recordfile!!.isPause=true recordfile!!.isPause = true
} }
/** /**
* 关闭录音 * 关闭录音
*/ */
fun stopRecord(isSave:Boolean) { fun stopRecord(isSave: Boolean) {
Log.i(tag, "关闭录音:") Log.i(tag, "关闭录音:")
recordfile!!.isPause=false recordfile!!.isPause = false
recordfile!!.closeFile(isSave) 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.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.EventChannel 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.TtsEvent
import com.deep_voice.speech.tts.TtsEventListener import com.deep_voice.speech.tts.TtsEventListener
import com.deep_voice.speech.tts.TtsEventType import com.deep_voice.speech.tts.TtsEventType
@ -356,30 +355,32 @@ class AzureSpeechPlugin : BleService.Callback, FlutterPlugin {
"renameFile" -> { "renameFile" -> {
val filePath = call.argument<String>("filePath")?: "" val filePath = call.argument<String>("filePath") ?: ""
val newName = call.argument<String>("newName")?: "" val newName = call.argument<String>("newName") ?: ""
try { try {
FileLogger.d(tag, "音频文件名称为: ${filePath}") // FileLogger.d(tag, "音频文件名称为: ${filePath}") //
azureAsrHelper.renameFile(filePath,newName) azureAsrHelper.renameFile(filePath, newName)
result.success(true) result.success(true)
} catch (e: Exception) { } catch (e: Exception) {
result.error("ENABLERECORD_ERROR", e.message, null) result.error("ENABLERECORD_ERROR", e.message, null)
} }
} }
"moveFile" -> { "moveFile" -> {
val sourcePath = call.argument<String>("sourcePath")?: "" val sourcePath = call.argument<String>("sourcePath") ?: ""
val destPath = call.argument<String>("destPath")?: "" val destPath = call.argument<String>("destPath") ?: ""
try { try {
FileLogger.d(tag, "音频文件名称为: ${sourcePath}") // FileLogger.d(tag, "音频文件名称为: ${sourcePath}") //
azureAsrHelper.moveFile(sourcePath,destPath) azureAsrHelper.moveFile(sourcePath, destPath)
result.success(true) result.success(true)
} catch (e: Exception) { } catch (e: Exception) {
result.error("ENABLERECORD_ERROR", e.message, null) result.error("ENABLERECORD_ERROR", e.message, null)
} }
} }
"enableRecord" -> { "enableRecord" -> {
val filePath = call.argument<String>("filePath")?: "" val filePath = call.argument<String>("filePath") ?: ""
try { try {
FileLogger.d(tag, "音频文件名称为: ${filePath}") // FileLogger.d(tag, "音频文件名称为: ${filePath}") //
@ -389,12 +390,14 @@ class AzureSpeechPlugin : BleService.Callback, FlutterPlugin {
result.error("ENABLERECORD_ERROR", e.message, null) result.error("ENABLERECORD_ERROR", e.message, null)
} }
} }
"pauseRecord" -> { "pauseRecord" -> {
azureAsrHelper.pauseRecord() azureAsrHelper.pauseRecord()
result.success(true) result.success(true)
} }
"stopRecord" -> { "stopRecord" -> {
val isSave = call.argument<Boolean>("isSave")?:false val isSave = call.argument<Boolean>("isSave") ?: false
try { try {
azureAsrHelper.stopRecord(isSave) azureAsrHelper.stopRecord(isSave)
result.success(true) 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 package com.yunqiinnovation.azure_speech.tools
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.RandomAccessFile import java.io.RandomAccessFile
@ -8,7 +9,7 @@ import java.io.FileInputStream
import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
object RecordFile { object RecordFile {
private var currentAudioFile: File? = null private var currentAudioFile: File? = null
private var fos: FileOutputStream? = null private var fos: FileOutputStream? = null
@ -156,7 +157,8 @@ import java.util.concurrent.atomic.AtomicBoolean
false false
} }
} }
/**
/**
* 移动文件到新路径 * 移动文件到新路径
* @param sourcePath 原始文件完整路径 * @param sourcePath 原始文件完整路径
* @param destPath 目标文件完整路径 * @param destPath 目标文件完整路径
@ -213,7 +215,8 @@ import java.util.concurrent.atomic.AtomicBoolean
false false
} }
} }
internal fun closeFile( isSave:Boolean): Boolean {
internal fun closeFile(isSave: Boolean): Boolean {
try { try {
if (fos == null || currentAudioFile == null) { if (fos == null || currentAudioFile == null) {
return false return false
@ -223,7 +226,7 @@ import java.util.concurrent.atomic.AtomicBoolean
fos?.close() fos?.close()
currentAudioFile?.let { file -> currentAudioFile?.let { file ->
if (file.length() <= 44||isSave==false) { if (file.length() <= 44 || isSave == false) {
file.delete() file.delete()
Log.d("tag", "音频文件过小已删除: ${file.absolutePath}") Log.d("tag", "音频文件过小已删除: ${file.absolutePath}")
return false return false
@ -248,4 +251,4 @@ import java.util.concurrent.atomic.AtomicBoolean
} }
return false 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.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.RandomAccessFile
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.TimeUnit
import android.os.Handler import android.os.Handler
import android.os.HandlerThread
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import android.util.Log 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") Log.i("TAG", "onAttachedToEngine")
result.success("") result.success("")
} } else if (call.method == "startUpgrading") {
else if (call.method == "startUpgrading") {
Log.d("TAG", "startUpgrading") Log.d("TAG", "startUpgrading")
// 接收传入的参数 // 接收传入的参数
val arguments = call.arguments as? Map<String, Any> val arguments = call.arguments as? Map<String, Any>

Loading…
Cancel
Save