|
|
|
@ -44,6 +44,9 @@ class AzureAsrHelper(private val context: Context) { |
|
|
|
|
|
|
|
private var useXunfei = false |
|
|
|
private var xunFeiAsrHelper: XunFeiAsrHelper? = null |
|
|
|
private var xunfeiAppId: String = "" |
|
|
|
private var xunfeiAccessKeyId: String = "" |
|
|
|
private var xunfeiAccessKeySecret: String = "" |
|
|
|
|
|
|
|
// 音频源配置 |
|
|
|
var audioSourceType = AudioSourceType.MICROPHONE |
|
|
|
@ -92,7 +95,10 @@ class AzureAsrHelper(private val context: Context) { |
|
|
|
subscriptionKey: String, |
|
|
|
region: String, |
|
|
|
supportedLanguages: Array<String> = arrayOf("zh-CN", "en-US"), |
|
|
|
audioSourceType: AudioSourceType = AudioSourceType.MICROPHONE |
|
|
|
audioSourceType: AudioSourceType = AudioSourceType.MICROPHONE, |
|
|
|
xunfeiAppId: String = "", |
|
|
|
xunfeiAccessKeyId: String = "", |
|
|
|
xunfeiAccessKeySecret: String = "" |
|
|
|
): Boolean { |
|
|
|
try { |
|
|
|
// 检查配置是否为空 |
|
|
|
@ -108,13 +114,19 @@ class AzureAsrHelper(private val context: Context) { |
|
|
|
this.subscriptionKey = subscriptionKey |
|
|
|
this.region = region |
|
|
|
this.audioSourceType = audioSourceType |
|
|
|
this.xunfeiAppId = xunfeiAppId |
|
|
|
this.xunfeiAccessKeyId = xunfeiAccessKeyId |
|
|
|
this.xunfeiAccessKeySecret = xunfeiAccessKeySecret |
|
|
|
|
|
|
|
// 设置语言 |
|
|
|
if (supportedLanguages.isNotEmpty()) { |
|
|
|
this.supportedLanguages = supportedLanguages |
|
|
|
} |
|
|
|
|
|
|
|
this.useXunfei = supportedLanguages.all { it == "zh-CN" || it == "en-US" } |
|
|
|
val xunfeiConfigReady = this.xunfeiAppId.isNotBlank() && |
|
|
|
this.xunfeiAccessKeyId.isNotBlank() && |
|
|
|
this.xunfeiAccessKeySecret.isNotBlank() |
|
|
|
this.useXunfei = supportedLanguages.all { it == "zh-CN" || it == "en-US" } && xunfeiConfigReady |
|
|
|
|
|
|
|
// 根据支持的语言数量决定是否启用自动语言检测 |
|
|
|
this.isAutoDetectLanguage = supportedLanguages.size >= 2 |
|
|
|
@ -283,7 +295,18 @@ class AzureAsrHelper(private val context: Context) { |
|
|
|
} |
|
|
|
|
|
|
|
if (xunFeiAsrHelper == null) { |
|
|
|
xunFeiAsrHelper = XunFeiAsrHelper(context) |
|
|
|
xunFeiAsrHelper = XunFeiAsrHelper( |
|
|
|
context = context, |
|
|
|
appId = xunfeiAppId, |
|
|
|
accessKeyId = xunfeiAccessKeyId, |
|
|
|
accessKeySecret = xunfeiAccessKeySecret |
|
|
|
) |
|
|
|
} else { |
|
|
|
xunFeiAsrHelper?.updateConfig( |
|
|
|
appId = xunfeiAppId, |
|
|
|
accessKeyId = xunfeiAccessKeyId, |
|
|
|
accessKeySecret = xunfeiAccessKeySecret |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
@ -904,4 +927,4 @@ class AzureAsrHelper(private val context: Context) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|