File size: 804 Bytes
b371670
 
59eba26
 
 
 
 
 
 
 
 
 
 
 
 
b371670
59eba26
 
254fd5f
 
b008c2b
254fd5f
 
 
 
 
 
 
 
b008c2b
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
pub(crate) mod aws;
#[cfg(feature = "whisper")]
pub(crate) mod whisper;

use async_trait::async_trait;
use tokio::sync::broadcast::Receiver;

#[derive(Debug, Clone)]
pub(crate) struct Event {
    pub(crate) transcript: String,
    pub(crate) is_final: bool,
}

#[async_trait]
pub(crate) trait ASR {
    async fn frame(&mut self, frame: Vec<i16>) -> anyhow::Result<()>;
    fn subscribe(&mut self) -> Receiver<Event>;
}


pub fn slice_i16_to_u8_le(slice: &[i16]) -> Vec<u8> {
    slice
        .iter()
        .flat_map(|&sample| {
            [sample as u8, (sample >> 8) as u8]
        })
        .collect()
}

pub fn slice_i16_to_u8_be(slice: &[i16]) -> Vec<u8> {
    slice
        .iter()
        .flat_map(|&sample| {
            [(sample >> 8) as u8, sample as u8]
        })
        .collect()
}