Crates.io | norma |
lib.rs | norma |
version | 0.0.3 |
source | src |
created_at | 2024-07-23 22:53:24.286112 |
updated_at | 2024-10-06 21:58:52.362293 |
description | A pure Rust speech to text library |
homepage | https://github.com/MikeIvanichev/norma |
repository | https://github.com/MikeIvanichev/norma |
max_upload_size | |
id | 1313348 |
size | 394,846 |
An easy to use and extensible pure Rust real-time transcription (speech-to-text) library.
use std::{
thread::{self, sleep},
time::Duration,
};
use norma::{
input::Settings,
models::whisper::monolingual,
Transcriber,
};
// Define the model that will be used for transcription
let model = monolingual::Definition::new(
monolingual::ModelType::DistilLargeEnV3,
norma::models::SelectedDevice::Cpu, // Replace with Cuda(0) or Metal as needed
);
// Spawn the transcriber in a new std thread
let (jh, th) = Transcriber::blocking_spawn(model).unwrap();
// Start recording using the default microphone
let mut stream = th.blocking_start(Settings::default()).unwrap();
thread::spawn(move || while let Some(msg) = stream.blocking_recv() {
println!("{}", msg);
});
sleep(Duration::from_secs(10));
// Stop the transcription and drop the TranscriberHandle,
// causing the transcriber to terminate
th.stop().unwrap();
drop(th);
// Join the thread that was spawned for the transcriber
jh.join().unwrap().unwrap();
Norma uses cpal to be agnostic over multiple audio backends.
This allows us to support:
Some audio backends are optional and will only be compiled with a feature flag.
jack
Oboe can either use a shared or static runtime.
The static runtime is used by default,
but activating the oboe-shared-stdcxx
feature makes it use the shared runtime,
which requires libc++_shared.so from the Android NDK to be present during execution.
All Accelerators are defined in models::SelectedDevice
.
Using the CPU does not require any extra features.
However when building on MacOS the accelerate
feature can be enabled to allow
the resulting program to utilize Apple's Accelerate framwork.
let device = SelectedDevice::Cpu;
For the below code to compile either the cuda
or the cudnn
feature must be enabled.
The cuda
feature flag requires that CUDA
be installed and correctly configured on your machine.
Once enabled the program will be built with CUDA support,
and require CUDA on the machine running the code.
The cudnn
feature flag requires that cuDNN
be installed and correctly configured on your machine.
Once enabled the program will be built with cuDNN support,
and require CUDA and cuDNN on the machine running the code.
let device = SelectedDevice::Cuda(ord);
Where ord
is the ID of the CUDA device you want to use.
If you only have one device or want to use the default set it to 0.
Using Metal requires compiling the program on MacOS
with the metal
feature flag.
let device = SelectedDevice::Metal;