File size: 844 Bytes
ee7230e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
use whisper_rs::WhisperContext;
use crate::config::Config;

pub(crate) async fn run_whisper(config: &Config) {
    let ctx = WhisperContext::new(&*config.whisper.model).expect("failed to load whisper context");
    let mut _state = ctx.create_state().expect("failed to create state");
    let params = (&config.whisper).to_full_params();
    _state.full(params, &[]).expect("TODO: panic message");
}

async fn pcm_i16_to_f32(input: &Vec<u8>) -> Vec<f32> {
    let pcm_i16 = input
        .chunks_exact(2)
        .map(|chunk| {
            let mut buf = [0u8; 2];
            buf.copy_from_slice(chunk);
            i16::from_le_bytes(buf)
        })
        .collect::<Vec<i16>>();
    let pcm_f32 = pcm_i16
        .iter()
        .map(|i| *i as f32 / i16::MAX as f32)
        .collect::<Vec<f32>>();
    pcm_f32
}

struct WhisperHandler {

}