Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/set asr properties #263

Merged
merged 8 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

allprojects {
group = "com.just-ai.jaicf"
version = "1.3.6"
version = "1.3.7"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.justai.jaicf.channel.jaicp.dto.config

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject

/**
* Configuration parameters for the automatic speech recognition (ASR) provider used in a telephone channel.
Expand All @@ -18,6 +19,8 @@ import kotlinx.serialization.Serializable
* @param azure configuration options for the Azure ASR provider, if used.
* @param asm configuration options for the ASM ASR provider, if used.
* @param sber configuration options for the Sber ASR provider, if used.
* @param asrProperties special properties used with selected ASR, if used.
* @param tokenData data used for ASR auth, if used.
**/
@Serializable
data class AsrConfig(
Expand All @@ -30,7 +33,9 @@ data class AsrConfig(
val mts: AsrMtsConfig? = null,
val azure: AsrAzureConfig? = null,
val asm: AsrAsmConfig? = null,
val sber: AsrSberConfig? = null
val sber: AsrSberConfig? = null,
val asrProperties: JsonObject? = null,
val tokenData: JsonObject? = null
) {
@Serializable
enum class AsrProviderType {
Expand Down Expand Up @@ -71,58 +76,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 @@ -10,6 +10,8 @@ import com.justai.jaicf.logging.SayReaction
import com.justai.jaicf.logging.currentState
import com.justai.jaicf.plugin.PathValue
import com.justai.jaicf.reactions.Reactions
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import java.time.DayOfWeek
import java.time.Duration
import java.time.Instant
Expand Down Expand Up @@ -201,6 +203,96 @@ class TelephonyReactions(private val bargeInDefaultProps: BargeInProperties) : J
)
}

/**
* This method overrides the ASR properties of the ASR used for the current call.
* example usage:
* ```
* state("asr") {
* action {
* reactions.telephony?.setAsrProperties(
* mapOf("enable_profanity_filter" to "true")
* )
* }
* }
* ```
* @param properties map of properties names with its assigned values.
* */
fun setAsrProperties(properties: Map<String, String>) {
val propertiesJson = JsonObject(properties.toMutableMap().mapValues { entry -> JsonPrimitive(entry.value) })
asrConfig = (executionContext.request as TelephonyBotRequest).asrConfig
when (checkNotNull(asrConfig?.type)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это копипаст с JAICP?
Так-то просится ввернуть какую-нибудь chain of responsibility или иным образом инкапсулировать логику выбора конфига.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Частично копипаст с JAICP, да. Вынести логику выбора конфига можно в другое место, но вроде особо некуда

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 -> {
asrConfig = asrConfig?.copy(
asrProperties = propertiesJson
)
}
}
}

/**
* Schedules a redial in outbound call campaign.
*
Expand Down
Loading