Skip to content

Commit

Permalink
feature: add asr properties in asr provider config
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamakuprina committed May 16, 2024
1 parent 19d82a2 commit e1043b8
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,58 +74,68 @@ data class AsrConfig(
* Subclasses contain provider-specific settings that are used to configure the ASR provider for the current session.
**/
@Serializable
sealed class AsrProviderConfig
sealed class AsrProviderConfig{
abstract val asrProperties: JsonObject?
}

@Serializable
data class AsrGoogleConfig(
val model: String? = null,
val lang: String? = null
val lang: String? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()

@Serializable
data class AsrZitechConfig(
val model: String? = null,
val lang: String? = null
val lang: String? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()

@Serializable
data class AsrYandexConfig(
val model: String? = null,
val lang: String? = null,
val numbersAsWords: Boolean? = null,
val sensitivityReduction: Boolean? = null
val sensitivityReduction: Boolean? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()

@Serializable
data class AsrMtsConfig(
val model: String? = null,
val lang: String? = null,
val transferType: String? = null
val transferType: String? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()

@Serializable
data class AsrAimyvoiceConfig(
val codec: String? = null,
val mode: String? = null,
val grammarFileNames: String? = null
val grammarFileNames: String? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()

@Serializable
data class AsrAzureConfig(
val language: String? = null,
val outputFormat: String? = null,
val profanityOption: String? = null,
val enableDictation: Boolean? = null
val enableDictation: Boolean? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()

@Serializable
data class AsrAsmConfig(
val sampleRate: Long? = null,
val model: String? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()

@Serializable
data class AsrSberConfig(
val language: String? = null,
val model: String? = null
val model: String? = null,
override val asrProperties: JsonObject? = null
) : AsrProviderConfig()
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,74 @@ class TelephonyReactions(private val bargeInDefaultProps: BargeInProperties) : J
* */
fun setAsrProperties(properties: Map<String, String>) {
val propertiesJson = JsonObject(properties.toMutableMap().mapValues { entry -> JsonPrimitive(entry.value) })
asrConfig = asrConfig?.copy(asrProperties = propertiesJson)
asrConfig = (executionContext.request as TelephonyBotRequest).asrConfig
when (checkNotNull(asrConfig?.type)) {
AsrConfig.AsrProviderType.SBER -> {
val asrProviderConfig: AsrSberConfig = checkNotNull(asrConfig?.sber)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
sber = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.YANDEX -> {
val asrProviderConfig: AsrYandexConfig = checkNotNull(asrConfig?.yandex)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
yandex = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.GOOGLE -> {
val asrProviderConfig: AsrGoogleConfig = checkNotNull(asrConfig?.google)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
google = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.MTS -> {
val asrProviderConfig: AsrMtsConfig = checkNotNull(asrConfig?.mts)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
mts = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.ZITECH -> {
val asrProviderConfig: AsrZitechConfig = checkNotNull(asrConfig?.zitech)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
zitech = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.AIMYVOICE -> {
val asrProviderConfig: AsrAimyvoiceConfig = checkNotNull(asrConfig?.aimyvoice)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
aimyvoice = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.AZURE -> {
val asrProviderConfig: AsrAzureConfig = checkNotNull(asrConfig?.azure)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
azure = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.ASM -> {
val asrProviderConfig: AsrAsmConfig = checkNotNull(asrConfig?.asm)
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson,
asm = asrProviderConfig.copy(asrProperties = propertiesJson)
)
}

AsrConfig.AsrProviderType.KALDI, AsrConfig.AsrProviderType.TINKOFF -> {}
}
}

/**
Expand Down

0 comments on commit e1043b8

Please sign in to comment.