use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
use crate::audio::AudioFormat;
#[derive(Debug, Clone, Serialize)]
pub struct Capabilities {
pub batch: bool,
pub streaming_push: bool,
pub realtime_microphone: bool,
pub diarization: DiarizationSupport,
pub word_timestamps: bool,
pub utterance_timestamps: bool,
pub language_detection: bool,
pub languages: Languages,
pub punctuation: bool,
pub profanity_filter: bool,
pub max_audio_secs: Option<u32>,
pub max_concurrent_streams: Option<u16>,
pub real_time_factor: Option<f32>,
pub requires_network: bool,
pub supported_audio_formats: &'static [AudioFormat],
pub min_chunk_ms: Option<u32>,
pub partial_results: bool,
pub redaction: bool,
pub vad_endpointing: bool,
pub custom_vocabulary: bool,
pub cost_per_audio_min_usd: Option<f32>,
}
impl Capabilities {
pub const ZERO: Self = Self {
batch: false,
streaming_push: false,
realtime_microphone: false,
diarization: DiarizationSupport::None,
word_timestamps: false,
utterance_timestamps: false,
language_detection: false,
languages: Languages::All,
punctuation: false,
profanity_filter: false,
max_audio_secs: None,
max_concurrent_streams: None,
real_time_factor: None,
requires_network: true,
supported_audio_formats: &[],
min_chunk_ms: None,
partial_results: false,
redaction: false,
vad_endpointing: false,
custom_vocabulary: false,
cost_per_audio_min_usd: None,
};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum DiarizationSupport {
None,
SpeakerCount,
NamedSpeakers,
}
#[derive(Debug, Clone)]
pub enum Languages {
All,
Subset(&'static [&'static str]),
}
impl Languages {
pub fn supports(&self, bcp47: &str) -> bool {
match self {
Languages::All => true,
Languages::Subset(list) => list.iter().any(|l| l.eq_ignore_ascii_case(bcp47)),
}
}
}
impl Serialize for Languages {
fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
match self {
Languages::All => {
let mut m = ser.serialize_map(Some(1))?;
m.serialize_entry("kind", "all")?;
m.end()
}
Languages::Subset(codes) => {
let mut m = ser.serialize_map(Some(2))?;
m.serialize_entry("kind", "subset")?;
m.serialize_entry("codes", codes)?;
m.end()
}
}
}
}