wolfplus 1 year ago
parent
commit
60f01f7b30
  1. 6
      lib/data/services/asr_service.dart
  2. 10
      lib/modules/translation/controllers/translation_controller.dart
  3. 11
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt

6
lib/data/services/asr_service.dart

@ -29,12 +29,6 @@ abstract class AsrService {
/// 检查连续识别是否活跃
bool isContinuousRecognitionActive();
/// 开启录音
Future<bool> enableRecord();
/// 停止录音
Future<bool> stopRecord();
/// 释放资源
Future<void> dispose();
}

10
lib/modules/translation/controllers/translation_controller.dart

@ -196,11 +196,11 @@ class TranslationController extends GetxController {
// 切换录音功能
Future<void> toggleisRecord() async {
isRecording.toggle();
if (isRecording.value) {
await _asrService.enableRecord();
} else {
await _asrService.stopRecord();
}
// if (isRecording.value) {
// await _asrService.enableRecord();
// } else {
// await _asrService.stopRecord();
// }
}
// 开始语音识别

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

@ -128,7 +128,6 @@ class AzureAsrHelper(private val context: Context) {
speechRecognitionLanguage = currentLanguage
}
// 优化:大幅减少静音超时时间(从800ms到300ms)
setProperty("SpeechServiceConnection_EndSilenceTimeoutMs", "300")
setProperty("Speech_SegmentationSilenceTimeoutMs", "300")
@ -256,14 +255,6 @@ class AzureAsrHelper(private val context: Context) {
}
}
/**
* 强制设置单一语言(优化语言检测逻辑)
*/
fun setForceLanguage(language: String) {
this.currentLanguage = language
this.isAutoDetectLanguage = false
speechConfig?.speechRecognitionLanguage = language
}
/**
* 设置外部音频流 - 使用拉流方式
@ -796,7 +787,6 @@ class AzureAsrHelper(private val context: Context) {
*/
override fun read(buffer: ByteArray): Int {
try {
// 修复:恢复阻塞等待,确保外部音频数据完整性
val chunk = queue.take()
// 检查是否是结束标志(空数组)
@ -806,7 +796,6 @@ class AzureAsrHelper(private val context: Context) {
val toCopy = minOf(chunk.size, buffer.size)
System.arraycopy(chunk, 0, buffer, 0, toCopy)
Log.i(tag, "外部音频:")
return toCopy
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()

Loading…
Cancel
Save