pub mod request;
pub mod response;
#[cfg(test)]
mod tests {
use crate::audio::request::{AudioFormat, SttModel, TimestampGranularity, TranscriptionFormat, TtsModel, Voice};
use crate::audio::response::TranscriptionResponse;
#[test]
fn test_transcription_response_deserialization() {
let json = r#"{
"text": "Hello, world!"
}"#;
let response: TranscriptionResponse = serde_json::from_str(json).expect("Should deserialize TranscriptionResponse");
assert_eq!(response.text, "Hello, world!");
assert!(response.language.is_none());
assert!(response.duration.is_none());
}
#[test]
fn test_transcription_response_verbose() {
let json = r#"{
"text": "Hello, world!",
"language": "en",
"duration": 1.5
}"#;
let response: TranscriptionResponse = serde_json::from_str(json).expect("Should deserialize verbose response");
assert_eq!(response.text, "Hello, world!");
assert_eq!(response.language, Some("en".to_string()));
assert_eq!(response.duration, Some(1.5));
}
#[test]
fn test_transcription_response_with_words() {
let json = r#"{
"text": "Hello world",
"words": [
{"word": "Hello", "start": 0.0, "end": 0.5},
{"word": "world", "start": 0.6, "end": 1.0}
]
}"#;
let response: TranscriptionResponse = serde_json::from_str(json).expect("Should deserialize with words");
let words = response.words.expect("Should have words");
assert_eq!(words.len(), 2);
assert_eq!(words[0].word, "Hello");
assert_eq!(words[0].start, 0.0);
assert_eq!(words[1].word, "world");
}
#[test]
fn test_tts_model_serialization() {
assert_eq!(serde_json::to_string(&TtsModel::Tts1).unwrap(), "\"tts-1\"");
assert_eq!(serde_json::to_string(&TtsModel::Tts1Hd).unwrap(), "\"tts-1-hd\"");
assert_eq!(serde_json::to_string(&TtsModel::Gpt4oMiniTts).unwrap(), "\"gpt-4o-mini-tts\"");
}
#[test]
fn test_voice_serialization() {
assert_eq!(serde_json::to_string(&Voice::Alloy).unwrap(), "\"alloy\"");
assert_eq!(serde_json::to_string(&Voice::Nova).unwrap(), "\"nova\"");
assert_eq!(serde_json::to_string(&Voice::Shimmer).unwrap(), "\"shimmer\"");
}
#[test]
fn test_audio_format_serialization() {
assert_eq!(serde_json::to_string(&AudioFormat::Mp3).unwrap(), "\"mp3\"");
assert_eq!(serde_json::to_string(&AudioFormat::Wav).unwrap(), "\"wav\"");
assert_eq!(serde_json::to_string(&AudioFormat::Flac).unwrap(), "\"flac\"");
}
#[test]
fn test_stt_model_serialization() {
assert_eq!(serde_json::to_string(&SttModel::Whisper1).unwrap(), "\"whisper-1\"");
assert_eq!(serde_json::to_string(&SttModel::Gpt4oTranscribe).unwrap(), "\"gpt-4o-transcribe\"");
}
#[test]
fn test_transcription_format_serialization() {
assert_eq!(serde_json::to_string(&TranscriptionFormat::Json).unwrap(), "\"json\"");
assert_eq!(serde_json::to_string(&TranscriptionFormat::VerboseJson).unwrap(), "\"verbose_json\"");
assert_eq!(serde_json::to_string(&TranscriptionFormat::Srt).unwrap(), "\"srt\"");
}
#[test]
fn test_defaults() {
assert_eq!(TtsModel::default(), TtsModel::Tts1);
assert_eq!(Voice::default(), Voice::Alloy);
assert_eq!(AudioFormat::default(), AudioFormat::Mp3);
assert_eq!(SttModel::default(), SttModel::Whisper1);
assert_eq!(TranscriptionFormat::default(), TranscriptionFormat::Json);
}
#[test]
fn test_audio_format_file_extension() {
assert_eq!(AudioFormat::Mp3.file_extension(), "mp3");
assert_eq!(AudioFormat::Wav.file_extension(), "wav");
assert_eq!(AudioFormat::Flac.file_extension(), "flac");
}
#[test]
fn test_timestamp_granularity() {
assert_eq!(TimestampGranularity::Word.as_str(), "word");
assert_eq!(TimestampGranularity::Segment.as_str(), "segment");
}
}