Sonant is a simple C++ wrapper for recording audio with ALSA and transcribing with Whisper.cpp library.
- ALSA
- Whisper.cpp
- CMake
- Linux-based operating system (tested on Ubuntu and Arch Linux)
- C++14 or later
sudo apt-get install libasound2-dev
sudo pacman -S alsa-lib
git clone https://github.com/ggerganov/whisper.cpp.git
cd whisper.cpp
mkdir build
cd build
cmake ..
make -j
sudo make install
git clone https://github.com/lulkien/sonant.git
cd sonant
mkdir build
cd build
cmake ..
make -j
sudo make install
Include the header file, create a Sonant
object, initialize it with your Whisper model, start the recorder, and handle the transcription in your callback.
#include <iostream>
#include <sonant.h>
int main() {
Sonant sonant;
if (!sonant.initialize("/path/to/your/whisper/model")) {
std::cerr << "Failed to initialize Sonant" << std::endl;
return -1;
}
sonant.setTranscriptionCallback([](const std::string& transcription) {
std::cout << "Transcription: " << transcription << std::endl;
});
if (!sonant.startRecorder()) {
std::cerr << "Failed to start recording" << std::endl;
return -1;
}
// Your application logic here
sonant.terminate();
return 0;
}
Always call terminate()
before your application exits to ensure proper cleanup.
This project is released into the public domain under the Unlicense.