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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
extern crate libc; use libc::{c_char,c_void}; ///Device #[repr(C)] pub struct ad_rec_t(c_void); ///Uses for ad_open function pub const DEFAULT_SAMPLES_PER_SEC:i32 = 16000; pub const AD_OK:i32 = 0; pub const AD_EOF:i32 = -1; pub const AD_ERR_GEN:i32 = -1; pub const AD_ERR_NOT_OPEN:i32 = -2; pub const AD_ERR_WAVE:i32 = -3; #[link(name = "sphinxad")] extern { ///Open a specific audio device with a given name and sampling rate. /// ///The device is opened in non-blocking mode and placed in idle state. ///The return value to be used as the first argument to ///other recording functions. /// # Safety /// ///Return pointer to read-only ad_rec_t structure if successful, NULL ///otherwise. pub fn ad_open_dev(device_name: *const c_char, samples_per_sec: u32) -> *const ad_rec_t; ///Open the default audio device with a given sampling rate. /// ///The device is opened in non-blocking mode and placed in idle state. ///The return value to be used as the first argument to ///other recording functions. /// # Safety /// ///Return pointer to read-only ad_rec_t structure if successful, NULL ///otherwise. pub fn ad_open_sps(samples_per_sec:u32) -> *const ad_rec_t; ///Open the default audio device. /// ///The device is opened in non-blocking mode and placed in idle state. ///The return value to be used as the first argument to ///other recording functions. /// # Safety /// ///Return pointer to read-only ad_rec_t structure if successful, NULL ///otherwise. pub fn ad_open() -> *const ad_rec_t; ///Start audio recording. /// /// # Safety /// ///Return 0(ReturnCode::Ok) if successful, <0 otherwise pub fn ad_start_rec(dev: *const ad_rec_t) -> i32; ///Stop audio recording. /// /// # Safety /// ///Return 0(ReturnCode::Ok) if successful, <0 otherwise pub fn ad_stop_rec(dev: *const ad_rec_t) -> i32; ///Close the recording device. /// /// # Safety /// ///Return 0(ReturnCode::Ok) if successful, <0 otherwise pub fn ad_close(dev: *const ad_rec_t) -> i32; ///Read next block of audio samples while recording; read upto max samples into buf. /// /// # Safety /// ///Return # samples actually read (could be 0 since non-blocking); AD_EOF if not ///recording and no more samples remaining to be read from most recent recording. pub fn ad_read(dev: *const ad_rec_t, buf:*mut i16, max:u32) -> i32; }