1use serde::{Deserialize, Serialize};
2
3pub mod ambiance;
4pub mod asr_processor;
5pub mod cache;
6pub mod denoiser;
7pub mod dtmf;
8pub mod engine;
9pub mod inactivity;
10pub mod loader;
11pub mod negotiate;
12pub mod processor;
13pub mod realtime_processor;
14pub mod recorder;
15pub mod stream;
16#[cfg(test)]
17mod tests;
18pub mod track;
19pub mod vad;
20pub mod volume_control;
21pub use audio_codec::PcmBuf;
22pub use audio_codec::Sample;
23pub const INTERNAL_SAMPLERATE: u32 = 16000;
24pub type TrackId = String;
25pub type PayloadBuf = Vec<u8>;
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub enum Samples {
29 PCM {
30 samples: PcmBuf,
31 },
32 RTP {
33 sequence_number: u16,
34 payload_type: u8,
35 payload: PayloadBuf,
36 },
37 Empty,
38}
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct SourcePacket {
41 pub sequence_number: u16,
42 pub payload_type: u8,
43 pub payload: PayloadBuf,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct AudioFrame {
48 pub track_id: TrackId,
49 pub samples: Samples,
50 pub src_packet: Option<SourcePacket>,
51 pub timestamp: u64,
52 pub sample_rate: u32,
53 pub channels: u16,
54}
55
56impl Samples {
57 pub fn payload_type(&self) -> Option<u8> {
58 match self {
59 Samples::RTP { payload_type, .. } => Some(*payload_type),
60 _ => None,
61 }
62 }
63}
64
65pub fn get_timestamp() -> u64 {
67 let now = std::time::SystemTime::now();
68 now.duration_since(std::time::UNIX_EPOCH)
69 .expect("Time went backwards")
70 .as_millis() as u64
71}