use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum TurnDetection {
ServerVad(ServerVadConfig),
SemanticVad(SemanticVadConfig),
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ServerVadConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub threshold: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prefix_padding_ms: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub silence_duration_ms: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub create_response: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub interrupt_response: Option<bool>,
}
impl ServerVadConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_threshold(mut self, threshold: f32) -> Self {
self.threshold = Some(threshold);
self
}
pub fn with_prefix_padding_ms(mut self, ms: u32) -> Self {
self.prefix_padding_ms = Some(ms);
self
}
pub fn with_silence_duration_ms(mut self, ms: u32) -> Self {
self.silence_duration_ms = Some(ms);
self
}
pub fn with_create_response(mut self, create: bool) -> Self {
self.create_response = Some(create);
self
}
pub fn with_interrupt_response(mut self, interrupt: bool) -> Self {
self.interrupt_response = Some(interrupt);
self
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SemanticVadConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub eagerness: Option<Eagerness>,
#[serde(skip_serializing_if = "Option::is_none")]
pub create_response: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub interrupt_response: Option<bool>,
}
impl SemanticVadConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_eagerness(mut self, eagerness: Eagerness) -> Self {
self.eagerness = Some(eagerness);
self
}
pub fn with_create_response(mut self, create: bool) -> Self {
self.create_response = Some(create);
self
}
pub fn with_interrupt_response(mut self, interrupt: bool) -> Self {
self.interrupt_response = Some(interrupt);
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum Eagerness {
Low,
Medium,
High,
#[default]
Auto,
}