|
|
|
@ -59,6 +59,9 @@ public class AzureAsrHelper: NSObject { |
|
|
|
|
|
|
|
private var useXunfei = false |
|
|
|
private var xunFeiAsrHelper: XunFeiAsrHelper? |
|
|
|
private var xunfeiAppId: String = "" |
|
|
|
private var xunfeiAccessKeyId: String = "" |
|
|
|
private var xunfeiAccessKeySecret: String = "" |
|
|
|
|
|
|
|
// 音频源配置 |
|
|
|
public enum AudioSourceType { |
|
|
|
@ -94,7 +97,10 @@ public class AzureAsrHelper: NSObject { |
|
|
|
subscriptionKey: String, |
|
|
|
region: String, |
|
|
|
supportedLanguages: [String] = ["zh-CN", "en-US"], |
|
|
|
audioSourceType: AudioSourceType = .microphone |
|
|
|
audioSourceType: AudioSourceType = .microphone, |
|
|
|
xunfeiAppId: String = "", |
|
|
|
xunfeiAccessKeyId: String = "", |
|
|
|
xunfeiAccessKeySecret: String = "" |
|
|
|
) -> Bool { |
|
|
|
do { |
|
|
|
// 检查配置是否为空 |
|
|
|
@ -109,6 +115,9 @@ public class AzureAsrHelper: NSObject { |
|
|
|
self.subscriptionKey = subscriptionKey |
|
|
|
self.region = region |
|
|
|
self.audioSourceType = audioSourceType |
|
|
|
self.xunfeiAppId = xunfeiAppId |
|
|
|
self.xunfeiAccessKeyId = xunfeiAccessKeyId |
|
|
|
self.xunfeiAccessKeySecret = xunfeiAccessKeySecret |
|
|
|
|
|
|
|
// 设置语言 |
|
|
|
if !supportedLanguages.isEmpty { |
|
|
|
@ -116,7 +125,10 @@ public class AzureAsrHelper: NSObject { |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否只包含中文或英文,如果是则使用讯飞 |
|
|
|
self.useXunfei = supportedLanguages.allSatisfy { $0 == "zh-CN" || $0 == "en-US" } |
|
|
|
let xunfeiConfigReady = !self.xunfeiAppId.isEmpty && |
|
|
|
!self.xunfeiAccessKeyId.isEmpty && |
|
|
|
!self.xunfeiAccessKeySecret.isEmpty |
|
|
|
self.useXunfei = supportedLanguages.allSatisfy { $0 == "zh-CN" || $0 == "en-US" } && xunfeiConfigReady |
|
|
|
|
|
|
|
// 根据支持的语言数量决定是否启用自动语言检测 |
|
|
|
self.isAutoDetectLanguage = supportedLanguages.count >= 2 |
|
|
|
@ -430,7 +442,17 @@ public class AzureAsrHelper: NSObject { |
|
|
|
} |
|
|
|
|
|
|
|
if xunFeiAsrHelper == nil { |
|
|
|
xunFeiAsrHelper = XunFeiAsrHelper() |
|
|
|
xunFeiAsrHelper = XunFeiAsrHelper( |
|
|
|
appId: xunfeiAppId, |
|
|
|
accessKeyId: xunfeiAccessKeyId, |
|
|
|
accessKeySecret: xunfeiAccessKeySecret |
|
|
|
) |
|
|
|
} else { |
|
|
|
xunFeiAsrHelper?.updateConfig( |
|
|
|
appId: xunfeiAppId, |
|
|
|
accessKeyId: xunfeiAccessKeyId, |
|
|
|
accessKeySecret: xunfeiAccessKeySecret |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
// 启动讯飞识别 |
|
|
|
|