use crate::config::Device;
use crate::recognizer::Language;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug)]
pub struct Config {
pub(crate) device: Device,
pub(crate) languages: Vec<Language>,
pub(crate) output_format: OutputFormat,
pub(crate) mode: RecognitionMode,
pub(crate) language_detect_mode: Option<LanguageDetectMode>,
pub(crate) phrases: Option<Vec<String>>,
pub(crate) custom_models: Option<Vec<(String, String)>>,
pub(crate) connection_id: Option<String>,
pub(crate) store_audio: bool,
pub(crate) profanity: Profanity,
}
impl Default for Config {
fn default() -> Self {
Config {
languages: vec![Language::default()],
output_format: OutputFormat::Simple,
mode: RecognitionMode::Conversation,
language_detect_mode: None,
phrases: None,
custom_models: None,
connection_id: None,
store_audio: false,
device: Device::default(),
profanity: Profanity::Masked,
}
}
}
impl Config {
pub fn enable_audio_logging(mut self) -> Self {
self.store_audio = true;
self
}
pub fn set_device(mut self, device: Device) -> Self {
self.device = device;
self
}
pub fn set_profanity(mut self, profanity: Profanity) -> Self {
self.profanity = profanity;
self
}
pub fn set_language(mut self, language: Language) -> Self {
self.languages = vec![language];
self
}
pub fn set_detect_languages(
mut self,
languages: Vec<Language>,
language_detect_mode: LanguageDetectMode,
) -> Self {
self.languages = languages;
self.language_detect_mode = Some(language_detect_mode);
self
}
pub fn set_phrases(mut self, phrases: Vec<String>) -> Self {
self.phrases = Some(phrases);
self
}
pub fn set_custom_models(mut self, custom_models: Vec<(String, String)>) -> Self {
self.custom_models = Some(custom_models);
self
}
#[allow(dead_code)]
pub fn set_recognition_mode(mut self, mode: RecognitionMode) -> Self {
self.mode = mode;
self
}
pub fn set_output_format(mut self, format: OutputFormat) -> Self {
self.output_format = format;
self
}
}
#[derive(Debug, Clone, Default)]
pub enum Profanity {
#[allow(missing_docs)]
#[default]
Masked,
#[allow(missing_docs)]
Removed,
#[allow(missing_docs)]
Raw,
}
impl Profanity {
pub(crate) fn as_str(&self) -> &'static str {
match self {
Profanity::Masked => "masked",
Profanity::Removed => "removed",
Profanity::Raw => "raw",
}
}
}
#[derive(Debug, Clone)]
pub struct Silence {
#[allow(missing_docs)]
pub initial_timeout_ms: Option<i32>,
#[allow(missing_docs)]
pub end_timeout_ms: Option<i32>,
#[allow(missing_docs)]
pub segmentation_timeout_ms: Option<i32>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
pub enum RecognitionMode {
#[serde(rename = "conversation")]
#[default]
Conversation,
#[serde(rename = "interactive")]
Interactive,
#[serde(rename = "dictation")]
Dictation,
}
impl RecognitionMode {
pub(crate) fn as_str(self) -> &'static str {
match self {
RecognitionMode::Conversation => "conversation",
RecognitionMode::Interactive => "interactive",
RecognitionMode::Dictation => "dictation",
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub enum OutputFormat {
#[allow(missing_docs)]
#[default]
Simple,
#[allow(missing_docs)]
Detailed,
}
impl OutputFormat {
pub(crate) fn as_str(&self) -> &'static str {
match self {
OutputFormat::Simple => "simple",
OutputFormat::Detailed => "detailed",
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub enum LanguageDetectMode {
#[serde(rename = "DetectContinuous")]
#[default]
Continuous,
#[serde(rename = "DetectAtAudioStart")]
AtStart,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct AudioDevice {
pub(crate) name: String,
pub(crate) model: String,
pub(crate) manufacturer: String,
#[serde(rename = "type")]
pub(crate) source: SourceType,
pub(crate) connectivity: ConnectionType,
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize)]
pub enum ConnectionType {
Bluetooth,
Wired,
WiFi,
Cellular,
InBuilt,
#[default]
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize)]
pub enum SourceType {
Phone,
Speaker,
Car,
Headset,
Thermostat,
Microphones,
Deskphone,
RemoteControl,
#[default]
Unknown,
File,
Stream,
}
impl AudioDevice {
pub fn new(source: SourceType) -> Self {
AudioDevice {
source,
..Default::default()
}
}
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = name.into();
self
}
pub fn with_model(mut self, model: impl Into<String>) -> Self {
self.model = model.into();
self
}
pub fn with_manufacturer(mut self, manufacturer: impl Into<String>) -> Self {
self.manufacturer = manufacturer.into();
self
}
pub fn with_connectivity(mut self, connectivity: ConnectionType) -> Self {
self.connectivity = connectivity;
self
}
pub fn with_source(mut self, source: SourceType) -> Self {
self.source = source;
self
}
#[allow(missing_docs)]
pub fn unknown() -> Self {
AudioDevice::new(SourceType::Unknown)
}
#[allow(missing_docs)]
pub fn stream() -> Self {
AudioDevice::new(SourceType::Stream)
}
#[allow(missing_docs)]
pub fn microphone(
name: impl Into<String>,
manufacture: impl Into<String>,
connectivity: ConnectionType,
) -> Self {
AudioDevice::new(SourceType::Microphones)
.with_connectivity(connectivity)
.with_manufacturer(manufacture)
.with_name(name)
}
#[allow(missing_docs)]
pub fn file() -> Self {
AudioDevice::new(SourceType::File)
}
}