This project implements a Bangla (Bengali) Keyword Spotting Model that can detect specific Bengali words in audio recordings. The model combines audio processing with text understanding to identify when a particular Bengali word appears in spoken audio.
This model is designed to:
Think of it as a "Bengali word detector" for audio - similar to how you might search for text in a document, but for spoken words in audio recordings.
The model uses a multimodal approach, meaning it processes both audio and text simultaneously:
The model is trained to recognize the relationship between how Bengali words sound and their textual representation.
torch
torchaudio
transformers
librosa
numpy
scikit-learn
Install with:
pip install -r requirements.txt
During execution, the model will automatically download:
facebook/wav2vec2-large-xlsr-53: For audio processingcsebuetnlp/banglabert: For Bengali text processingKWDB/
├── model.py # Defines the BanglaKeywordSpotter neural network
├── dataset.py # Handles loading audio data
├── collate.py # Batches data for training
├── train.py # Training script
├── predict.py # Prediction script
├── requirements.txt # Python dependencies
└── README.md # This file
The model expects training data in a text file named bangla_data.txt with the following format:
/path/to/audio1.wav|word_to_spot|label
/path/to/audio2.wav|another_word|label
Where:
Example:
audio/speech1.wav|হ্যালো|1
audio/speech2.wav|হ্যালো|0
audio/speech3.wav|ধন্যবাদ|1
Prepare Your Data: Create a bangla_data.txt file with your training data in the format described above.
Run Training:
python train.py
The training process will:
bangla_data.txtbangla_kws_model.pthAfter training, you can use the model to detect keywords in new audio files:
python predict.py
The script will prompt you to enter:
Enter the path to the audio file: test_audio.wav
Enter the keyword to detect: হ্যালো
The output will show:
You can also use the model programmatically in your Python code:
import torch
import librosa
from model import BanglaKeywordSpotter
# Load the trained model
model = BanglaKeywordSpotter()
model.load_state_dict(torch.load('bangla_kws_model.pth'))
model.eval()
# Load an audio file
audio_array, _ = librosa.load('audio.wav', sr=16000)
audio_batch = [audio_array]
keyword_batch = ['আপনি'] # The Bengali keyword to detect
# Make prediction
with torch.no_grad():
logit = model(audio_batch, keyword_batch)
probability = torch.sigmoid(logit).item()
prediction = 1 if probability > 0.5 else 0 # Using 0.5 threshold
print(f"Probability: {probability}")
print(f"Prediction: {'Present' if prediction == 1 else 'Not Present'}")
The BanglaKeywordSpotter model consists of:
Audio Encoder: facebook/wav2vec2-large-xlsr-53 (frozen)
Text Encoder: csebuetnlp/banglabert (frozen)
Classifier: A simple neural network with:
In predict.py, you can adjust the classification threshold:
logit, probability, prediction = predict_keyword(audio_file, keyword, model, threshold=0.3) # Lower threshold = more sensitive
In train.py, you can modify:
This model is optimized for:
train.pybangla_kws_model.pth existsThe saved model (bangla_kws_model.pth) only contains the classifier weights, not the pre-trained encoders, so it should be relatively small.
This model is suitable for applications such as:
2 commits
Python
100.0%
This project implements a Bangla (Bengali) Keyword Spotting Model that can detect specific Bengali words in audio recordings. The model combines audio processing with text understanding to identify when a particular Bengali word appears in spoken audio.
This model is designed to:
Think of it as a "Bengali word detector" for audio - similar to how you might search for text in a document, but for spoken words in audio recordings.
The model uses a multimodal approach, meaning it processes both audio and text simultaneously:
The model is trained to recognize the relationship between how Bengali words sound and their textual representation.
torch
torchaudio
transformers
librosa
numpy
scikit-learn
Install with:
pip install -r requirements.txt
During execution, the model will automatically download:
facebook/wav2vec2-large-xlsr-53: For audio processingcsebuetnlp/banglabert: For Bengali text processingKWDB/
├── model.py # Defines the BanglaKeywordSpotter neural network
├── dataset.py # Handles loading audio data
├── collate.py # Batches data for training
├── train.py # Training script
├── predict.py # Prediction script
├── requirements.txt # Python dependencies
└── README.md # This file
The model expects training data in a text file named bangla_data.txt with the following format:
/path/to/audio1.wav|word_to_spot|label
/path/to/audio2.wav|another_word|label
Where:
Example:
audio/speech1.wav|হ্যালো|1
audio/speech2.wav|হ্যালো|0
audio/speech3.wav|ধন্যবাদ|1
Prepare Your Data: Create a bangla_data.txt file with your training data in the format described above.
Run Training:
python train.py
The training process will:
bangla_data.txtbangla_kws_model.pthAfter training, you can use the model to detect keywords in new audio files:
python predict.py
The script will prompt you to enter:
Enter the path to the audio file: test_audio.wav
Enter the keyword to detect: হ্যালো
The output will show:
You can also use the model programmatically in your Python code:
import torch
import librosa
from model import BanglaKeywordSpotter
# Load the trained model
model = BanglaKeywordSpotter()
model.load_state_dict(torch.load('bangla_kws_model.pth'))
model.eval()
# Load an audio file
audio_array, _ = librosa.load('audio.wav', sr=16000)
audio_batch = [audio_array]
keyword_batch = ['আপনি'] # The Bengali keyword to detect
# Make prediction
with torch.no_grad():
logit = model(audio_batch, keyword_batch)
probability = torch.sigmoid(logit).item()
prediction = 1 if probability > 0.5 else 0 # Using 0.5 threshold
print(f"Probability: {probability}")
print(f"Prediction: {'Present' if prediction == 1 else 'Not Present'}")
The BanglaKeywordSpotter model consists of:
Audio Encoder: facebook/wav2vec2-large-xlsr-53 (frozen)
Text Encoder: csebuetnlp/banglabert (frozen)
Classifier: A simple neural network with:
In predict.py, you can adjust the classification threshold:
logit, probability, prediction = predict_keyword(audio_file, keyword, model, threshold=0.3) # Lower threshold = more sensitive
In train.py, you can modify:
This model is optimized for:
train.pybangla_kws_model.pth existsThe saved model (bangla_kws_model.pth) only contains the classifier weights, not the pre-trained encoders, so it should be relatively small.
This model is suitable for applications such as:
2 commits
Python
100.0%