add photo
This commit is contained in:
@@ -6,6 +6,7 @@ import android.util.Log
|
||||
import com.digitalperson.BuildConfig
|
||||
import com.digitalperson.audio.AudioProcessor
|
||||
import com.digitalperson.config.AppConfig
|
||||
import com.digitalperson.env.RuntimeEnv
|
||||
import com.digitalperson.engine.SenseVoiceEngineRKNN
|
||||
import com.digitalperson.util.FileHelper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -23,7 +24,6 @@ class AsrManager(private val context: Context) {
|
||||
|
||||
private var senseVoice: SenseVoiceEngineRKNN? = null
|
||||
private val nativeLock = Any()
|
||||
|
||||
private val asrQueue = Channel<Pair<FloatArray, FloatArray>>(capacity = Channel.UNLIMITED)
|
||||
|
||||
private var audioProcessor: AudioProcessor? = null
|
||||
@@ -48,6 +48,10 @@ class AsrManager(private val context: Context) {
|
||||
}
|
||||
|
||||
fun initSenseVoiceModel(): Boolean {
|
||||
if (RuntimeEnv.isEmulator()) {
|
||||
Log.w(TAG, "ASR: emulator detected; skip local RKNN init and use cloud ASR")
|
||||
return false
|
||||
}
|
||||
return try {
|
||||
Log.i(TAG, "ASR: init SenseVoice RKNN (scheme A)")
|
||||
|
||||
@@ -133,23 +137,47 @@ class AsrManager(private val context: Context) {
|
||||
Log.d(TAG, "ASR started: processing audio segment")
|
||||
|
||||
saveAsrAudio(originalSeg, processedSeg)
|
||||
|
||||
val raw = synchronized(nativeLock) {
|
||||
|
||||
val localText = synchronized(nativeLock) {
|
||||
val e = senseVoice
|
||||
if (e == null || !e.isInitialized) {
|
||||
Log.e(TAG, "ASR failed: SenseVoice engine not initialized")
|
||||
""
|
||||
} else {
|
||||
try {
|
||||
e.transcribeBuffer(processedSeg)
|
||||
} catch (e: Throwable) {
|
||||
Log.e(TAG, "ASR transcribe failed: ${e.message}")
|
||||
removeTokens(e.transcribeBuffer(processedSeg))
|
||||
} catch (t: Throwable) {
|
||||
Log.e(TAG, "ASR transcribe failed: ${t.message}")
|
||||
""
|
||||
}
|
||||
}
|
||||
}.trim()
|
||||
|
||||
val text = if (localText.isNotBlank()) {
|
||||
localText
|
||||
} else {
|
||||
// 模拟器或本地 RKNN 未就绪:使用腾讯云「一句话识别」SDK(app/libs/asr-one-sentence-release.aar)
|
||||
val shouldTryTencent =
|
||||
BuildConfig.HAS_TENCENT_ASR_SDK && (RuntimeEnv.isEmulator() || !isInitialized())
|
||||
if (!shouldTryTencent) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"ASR failed: local RKNN not ready and Tencent SDK unavailable " +
|
||||
"(add libs/asr-one-sentence-release.aar or fix SenseVoice init)"
|
||||
)
|
||||
""
|
||||
} else {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
// 云端 ASR 使用原始录音(未经 AEC/NS):
|
||||
// 模拟器上 AEC/NS 不可用,processedSeg 可能被处理成近似静音
|
||||
TencentOneSentenceAsr.transcribePcm16Mono(originalSeg)
|
||||
} catch (t: Throwable) {
|
||||
Log.e(TAG, "Tencent ASR failed: ${t.message}")
|
||||
""
|
||||
}
|
||||
}.trim()
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "ASR raw result: $raw")
|
||||
val text = removeTokens(raw)
|
||||
|
||||
val filterResult = filterText(text)
|
||||
if (filterResult != null) {
|
||||
@@ -220,4 +248,5 @@ class AsrManager(private val context: Context) {
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user