Example of gRPC server implementation in Rust, designed to convert voice into vector representations (embeddings). This service can be part of a search engine, vector analysis systems, etc. It uses an offline model (preloaded), and performs computations on CPU (without using GPU).
P.S. If you want to enable support for GPU calculations, you can easily do it by making small changes to the project.
This service is implemented specifically for the input/output of this model TitaNet-L.
First you need to download the model, and convert it to ONNX format.
Then it should be placed in the /model directory of the project.
In config.yaml you can set the value for the fields:
Serverhost- host to start gRPC server.port- port to start gRPC server.
Logginglog_level- logging level of detail.
ModelSettingspath- model path.sample_rate- sampling frequency (Hz).window_length- size of the analysis window.frame_length- frame size.frame_step- step between frames.fft_size- FFT size (number of points).n_mels- number of mel filters.ref_value- reference value.amin- minimum amplitude value.
When using your own audio file, make sure that it has the correct format - WAV PCM_S16LE mono (sample_rate 16000Hz).
Otherwise, you will get an error as the service checks the audio file for consistency.
If you have ffmpeg installed, you can use it, for conversion.
To send a request to the server, take voice_embeddings.proto (from the ./proto directory), and use it in your client.
You can check if it works, for example, via Postman.
Query structure for rpc EmbedText:
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"content": "audio in base64 format"
}As a result of the recognition, the server will return JSON of the form:
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"embeddings": [
-0.028818072751164436,
0.04423859715461731,
-0.004005502909421921,
"...",
-0.044924844056367874,
-0.02066687121987343
]
}- To install
Ruston Unix-like systems (MacOS, Linux, ...) - run the command in the terminal. After the download is complete, you will get the latest stable version of Rust for your platform, as well as the latest version of Cargo.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh- Run the following command in the terminal to verify.
cargo --version- Open the project and run the commands.
Check the code to see if it can be compiled (without running it).
cargo checkBuild + run the project (in release mode with optimizations).
cargo run --releaseUDP: If you have Windows, see Instructions here.
This project is licensed under the MIT License or Apache License 2.0, your choice.