]>
code.octet-stream.net Git - m17rt/blob - m17codec2/src/lib.rs
1 pub(crate) use codec2
::{Codec2
, Codec2Mode
};
6 pub fn decode_codec2
<P
: AsRef
<Path
>>(data
: &[u8], out_path
: P
) {
7 let codec2
= Codec2
::new(Codec2Mode
::MODE_3200
);
9 let mut codec
= var_name
;
10 let mut all_samples
: Vec
<i16> = vec
![];
11 for i
in 0..(data
.len() / 8) {
12 let mut samples
= vec
![0; codec
.samples_per_frame()];
13 codec
.decode(&mut samples
, &data
[i
* 8..((i
+ 1) * 8)]);
14 all_samples
.append(&mut samples
);
18 let mut speech_out
= File
::create(out_path
).unwrap
();
19 for b
in all_samples
{
20 speech_out
.write_all(&b
.to_le_bytes()).unwrap
();