Skip to main content

artificial_core/provider/
transcription.rs

1use std::{future::Future, pin::Pin};
2
3use crate::error::Result;
4
5/// Provider-agnostic audio transcription request.
6#[derive(Debug, Clone)]
7pub struct TranscriptionRequest {
8    pub audio: Vec<u8>,
9    pub mime_type: String,
10    pub filename: Option<String>,
11    pub language: Option<String>,
12    pub prompt: Option<String>,
13    pub model: Option<String>,
14}
15
16impl TranscriptionRequest {
17    pub fn new(audio: Vec<u8>, mime_type: impl Into<String>) -> Self {
18        Self {
19            audio,
20            mime_type: mime_type.into(),
21            filename: None,
22            language: None,
23            prompt: None,
24            model: None,
25        }
26    }
27
28    pub fn with_filename(mut self, filename: impl Into<String>) -> Self {
29        self.filename = Some(filename.into());
30        self
31    }
32
33    pub fn with_language(mut self, language: impl Into<String>) -> Self {
34        self.language = Some(language.into());
35        self
36    }
37
38    pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
39        self.prompt = Some(prompt.into());
40        self
41    }
42
43    pub fn with_model(mut self, model: impl Into<String>) -> Self {
44        self.model = Some(model.into());
45        self
46    }
47}
48
49#[derive(Debug, Clone)]
50pub struct TranscriptionSegment {
51    pub start_seconds: Option<f64>,
52    pub end_seconds: Option<f64>,
53    pub text: String,
54}
55
56#[derive(Debug, Clone)]
57pub struct TranscriptionResult {
58    pub text: String,
59    pub language: Option<String>,
60    pub duration_seconds: Option<f64>,
61    pub segments: Option<Vec<TranscriptionSegment>>,
62    pub metadata: Option<serde_json::Value>,
63}
64
65/// Provider capability for converting audio to text.
66pub trait TranscriptionProvider: Send + Sync {
67    fn transcribe<'s>(
68        &'s self,
69        request: TranscriptionRequest,
70    ) -> Pin<Box<dyn Future<Output = Result<TranscriptionResult>> + Send + 's>>;
71}