aic_sdk/docs/examples.rs
1//! Example programs.
2//!
3//! You can run any of the examples with the following steps.
4//!
5//! Create a new empty directory. Change into it and run:
6//!
7//! ```bash
8//! cargo init
9//! ```
10//!
11//! Replace the contents of `src/main.rs` with the Rust code of the example you want to try.
12//! Note that some examples have additional/different instructions,
13//! but in most cases you should add the ai-coustics SDK with:
14//!
15//! ```bash
16//! cargo add aic-sdk --features download-lib,download-model
17//! ```
18//!
19//! The examples read the [license key](https://developers.ai-coustics.com/)
20//! from the environment variable `AIC_SDK_LICENSE`, so you'll have to set that up:
21//!
22//! ```bash
23//! export AIC_SDK_LICENSE="your_license_key_here"
24//! ```
25//!
26//! Finally, (compile and) run the example:
27//!
28//! ```bash
29//! cargo run
30//! ```
31
32pub mod enhancement {
33 //! Load a model, configure a processor and enhance a block of audio.
34 //!
35 //! Follow the instructions at [`examples`](super), using the following code in `src/main.rs`:
36 //!
37 //! ```no_run
38 //! # #[cfg(feature = "download-model")]
39 //! # fn example() {
40 #![doc = include_str!("../../examples/enhancement.rs")]
41 //! # }
42 //! ```
43}
44
45pub mod vad {
46 //! Detect speech with a dedicated VAD model and read the prediction from a VAD context.
47 //!
48 //! Follow the instructions at [`examples`](super), using the following code in `src/main.rs`:
49 //!
50 //! ```no_run
51 //! # #[cfg(feature = "download-model")]
52 //! # fn example() {
53 #![doc = include_str!("../../examples/vad.rs")]
54 //! # }
55 //! ```
56}
57
58pub mod analyze_file {
59 //! Analyze a WAV file given on the command line and print the resulting scores.
60 //!
61 //! In addition to the instructions at [`examples`](super), you have to add the `audio-file` crate
62 //! (if you want to use formats other than WAV, drop `--no-default-features`):
63 //!
64 //! ```bash
65 //! cargo add audio-file --no-default-features
66 //! ```
67 //!
68 //! When running the example, specify the path to an audio file to be analyzed:
69 //!
70 //! ```bash
71 //! cargo run -- path/to/audio-file.wav
72 //! ```
73 //!
74 //! `src/main.rs`:
75 //! ```no_run
76 //! # #[cfg(feature = "download-model")]
77 //! # fn example() {
78 #![doc = include_str!("../../examples/analyze_file.rs")]
79 //! # }
80 //! ```
81}
82
83pub mod benchmark {
84 //! Run processor instances concurrently until they stop keeping up with real time, to find how
85 //! many streams a machine sustains.
86 //!
87 //! In addition to the instructions at [`examples`](super), you have to add the `tokio` crate,
88 //! enabling a few features:
89 //!
90 //! ```bash
91 //! cargo add tokio --features macros,rt-multi-thread,sync,time
92 //! ```
93 //!
94 //! `src/main.rs`:
95 //! ```no_run
96 //! # #[cfg(feature = "download-model")]
97 //! # fn example() {
98 #![doc = include_str!("../../examples/benchmark.rs")]
99 //! # }
100 //! ```
101}
102
103#[cfg(feature = "async")]
104pub mod parallel_async {
105 //! Process several streams concurrently with [`ProcessorAsync`] on an async runtime.
106 //!
107 //! In addition to the instructions at [`examples`](super),
108 //! you have to enable the `async` feature:
109 //!
110 //! ```bash
111 //! cargo add aic-sdk --features download-lib,download-model,async
112 //! ```
113 //!
114 //! And you have to add two more crates:
115 //!
116 //! ```bash
117 //! cargo add futures
118 //! cargo add tokio --features macros,rt-multi-thread
119 //! ```
120 //!
121 //! `src/main.rs`:
122 //! ```no_run
123 //! # #[cfg(all(feature = "async", feature = "download-model"))]
124 //! # fn example() {
125 #![doc = include_str!("../../examples/parallel_async.rs")]
126 //! # }
127 //! ```
128 #[allow(unused_imports)]
129 // Used in the docstring:
130 use crate::ProcessorAsync;
131}
132
133pub mod build_time_download {
134 //! Download a model while the program is compiled and embed it into the binary.
135 #![doc = include_str!("../../examples/build-time-download/README.md")]
136 //!
137 //! `build.rs`:
138 //!
139 //! ```no_run
140 //! # #[cfg(feature = "download-model")]
141 //! # fn build_script() {
142 #![doc = include_str!("../../examples/build-time-download/build.rs")]
143 //! # }
144 //! ```
145 //!
146 //! `src/main.rs`:
147 //!
148 //! ```no_run
149 //! # macro_rules! include_model { ($($tt:tt)*) => { &[] } }
150 #![doc = include_str!("../../examples/build-time-download/src/main.rs")]
151 //! ```
152 #[allow(unused_imports)]
153 // These are linked in the README.md:
154 use crate::{Model, include_model};
155}