|
| 1 | +# Picovoice Rust Demos |
| 2 | + |
| 3 | +This Rust module contains demos for processing real-time audio (i.e. microphone) and audio files using the Picovoice Platform. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +The microphone demo uses [miniaudio-rs](https://github.com/ExPixel/miniaudio-rs) for cross-platform audio capture. It uses `bindgen` and therefore requires `clang` to be installed and on the path. Use the [`Bindgen` docs](https://rust-lang.github.io/rust-bindgen/requirements.html) for instructions on how to install `clang` for various Operating Systems and distros. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +NOTE: The working directory for the following `Cargo` commands is: |
| 12 | + |
| 13 | +```console |
| 14 | +picovoice/demo/rust/filedemo # File Demo |
| 15 | +picovoice/demo/rust/micdemo # Microphone Demo |
| 16 | +``` |
| 17 | + |
| 18 | +### File Demo |
| 19 | + |
| 20 | +The file demo allows testing Picovoice on a corpus of audio files. The demo is mainly useful for quantitative performance benchmarking. It accepts mono 16kHz WAV audio files. The following processes a file looking for instances of the wake phrase defined in the file passed to the `--keyword_path` argument and then infers the follow-on spoken command |
| 21 | +using the context defined by the file passed to the `--context_path` argument: |
| 22 | + |
| 23 | +```console |
| 24 | +cargo run --release -- \ |
| 25 | +--input_audio_path "path/to/input.wav" \ |
| 26 | +--keyword_path "/path/to/keyword.ppn" \ |
| 27 | +--context_path "/path/to/context.rhn" |
| 28 | +``` |
| 29 | + |
| 30 | +To see all available arguments, use the `--help` flag: |
| 31 | +```console |
| 32 | +cargo run --release -- --help |
| 33 | +``` |
| 34 | + |
| 35 | +### Microphone Demo |
| 36 | + |
| 37 | +The microphone demo opens an audio stream from a microphone and detects utterances of a give wake word(s). The following processes |
| 38 | +incoming audio from the microphone for instances of the wake phrase defined in the file passed to the `--keyword_path` argument and then infers the follow-on spoken command using the context defined by the file |
| 39 | +passed to the `--context_path` argument. Upon completion of the spoken command inference it resumes wake word |
| 40 | +detection. |
| 41 | + |
| 42 | +```console |
| 43 | +cargo run --release -- \ |
| 44 | +--keyword_path "/path/to/keyword.ppn" \ |
| 45 | +--context_path "/path/to/context.rhn" |
| 46 | +``` |
| 47 | + |
| 48 | +To see all available arguments, use the `-h` flag: |
| 49 | +```console |
| 50 | +cargo run --release -- --help |
| 51 | +``` |
| 52 | + |
| 53 | +It is possible that the default audio input device is not the one you wish to use. There are a couple |
| 54 | +of debugging facilities baked into the demo application to solve this. First, type the following into the console: |
| 55 | +```console |
| 56 | +cargo run --release -- --show_audio_devices |
| 57 | +``` |
| 58 | + |
| 59 | +It provides information about various audio input devices on the box. On a is an example output from a Windows machine: |
| 60 | + |
| 61 | +```console |
| 62 | +Capture Devices |
| 63 | + 0: Microphone Array (Realtek(R) Audio) |
| 64 | + 1: Microphone (USB Audio Device) |
| 65 | +``` |
| 66 | + |
| 67 | +You can use the device index to specify which microphone to use for the demo. For instance, if you want to use the USB microphone in the above example, you can invoke the demo application as below: |
| 68 | + |
| 69 | +```console |
| 70 | +cargo run --release -- \ |
| 71 | +--keyword_path "/path/to/keyword.ppn" \ |
| 72 | +--context_path "/path/to/context.rhn" \ |
| 73 | +--audio_device_index 1 |
| 74 | +``` |
| 75 | + |
| 76 | +Exact system setups don't always play well with certain audio backends. If this is the case you can override the default with a specific backend: |
| 77 | + |
| 78 | +```console |
| 79 | +cargo run --release -- \ |
| 80 | +--keyword_path "/path/to/keyword.ppn" \ |
| 81 | +--context_path "/path/to/context/one.rhn" \ |
| 82 | +--audio_device_index 1 \ |
| 83 | +--audio_backend Alsa |
| 84 | +``` |
| 85 | + |
| 86 | +If the problem persists we suggest storing the recorded audio into a file for inspection. This can be achieved with: |
| 87 | + |
| 88 | +```console |
| 89 | +cargo run --release \ |
| 90 | +--context_path "/path/to/context.rhn" \ |
| 91 | +--keyword_path "/path/to/keyword.ppn" \ |
| 92 | +--audio_device_index 1 \ |
| 93 | +--output_path ./test.wav |
| 94 | +``` |
| 95 | + |
| 96 | +If after listening to stored file there is no apparent problem detected please open an issue. |
0 commit comments