File size: 8,693 Bytes
3e96984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ac29e2
3e96984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d56b47b
3e96984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
language:
- ja
- multilingual
tags:
- voice-activity-detection
- vad
- whisper
- onnx
- speech-detection
- audio-classification
- asmr
- japanese
- whispered-speech
license: mit
base_model: openai/whisper-base
library_name: transformers
pipeline_tag: audio-classification
---

# Whisper-base Voice Activity Detection (VAD) for Japanese ASMR - ONNX

## Model Description

This is a refined Whisper-based Voice Activity Detection (VAD) model that leverages the pre-trained Whisper encoder with a lightweight non-autoregressive decoder for high-precision speech activity detection. While fine-tuned on Japanese ASMR content for optimal performance on soft speech and whispers, the model retains Whisper's robust multilingual foundation, enabling effective speech detection across diverse languages and acoustic conditions. It has been optimized and exported to ONNX format for efficient inference across different platforms. For the full training code, configs, and ONNX export utilities, see the GitHub repository: [TransWithAI/whisper-vad](https://github.com/TransWithAI/whisper-vad).

This work builds upon recent research demonstrating the positive transfer of Whisper's speech representations to VAD tasks, as shown in [WhisperSeg](https://github.com/nianlonggu/WhisperSeg) and related work.

### Key Features

- **Architecture**: Encoder-Decoder model based on whisper-base
- **Frame Resolution**: 20ms per frame for precise temporal detection
- **Input Duration**: Processes 30-second audio chunks
- **Output**: Frame-level speech/non-speech predictions
- **Optimized**: ONNX format for cross-platform deployment
- **Real-time capable**: Fast non-autoregressive inference

### Model Architecture Details

- **Base Model**: OpenAI whisper-base encoder (frozen during training)
- **Decoder**: 2-layer transformer decoder with 8 attention heads
- **Processing**:
  - Input: 30-second audio chunks (480,000 samples @ 16kHz)
  - Features: 80-channel log-mel spectrogram
  - Output: 1500 frame predictions (20ms per frame)

## Performance

- **Frame Duration**: 20ms per frame for precise temporal detection
- **Processing Speed**: ~100x real-time on CPU (single-sample processing)
- **Batch Processing**: Currently limited to batch size of 1 due to ONNX export constraints, but single-sample inference is extremely fast
- **Specialized Training**: Japanese ASMR and whispered speech
- **Generalization**: Despite being fine-tuned on Japanese ASMR, the model inherits Whisper's strong multilingual capabilities and can effectively detect speech in various languages and acoustic environments

### Advantages over Native Whisper VAD

- **No hallucinations**: Discriminative model cannot generate spurious text
- **Much faster**: Single forward pass, non-autoregressive inference
- **Higher precision**: 20ms frame-level temporal resolution vs Whisper's 30s chunks
- **Robust**: Focal loss training handles speech/silence imbalance effectively
- **Lightweight**: Decoder adds minimal parameters to base Whisper encoder

## Usage

### Quick Start with ONNX Runtime

```python
import numpy as np
import onnxruntime as ort
from transformers import WhisperFeatureExtractor
import librosa

# Load model
session = ort.InferenceSession("model.onnx")
feature_extractor = WhisperFeatureExtractor.from_pretrained("openai/whisper-base")

# Load and preprocess audio
audio, sr = librosa.load("audio.wav", sr=16000)
audio_chunk = audio[:480000]  # 30 seconds

# Extract features
inputs = feature_extractor(
    audio_chunk,
    sampling_rate=16000,
    return_tensors="np"
)

# Run inference
outputs = session.run(None, {session.get_inputs()[0].name: inputs.input_features})
predictions = outputs[0]  # Shape: [1, 1500] - 1500 frames of 20ms each

# Apply threshold
speech_frames = predictions[0] > 0.5
```

### Using the Provided Inference Script

The model repository includes a comprehensive `inference.py` script with advanced features:

```python
from inference import WhisperVADInference

# Initialize model
vad = WhisperVADInference(
    model_path="model.onnx",
    threshold=0.5,           # Speech detection threshold
    min_speech_duration=0.25,  # Minimum speech segment duration
    min_silence_duration=0.1   # Minimum silence between segments
)

# Process audio file
segments = vad.process_audio("audio.wav")

# Segments format: List of (start_time, end_time) tuples
for start, end in segments:
    print(f"Speech detected: {start:.2f}s - {end:.2f}s")
```

### Streaming/Real-time Processing

```python
# Process audio stream in chunks
vad = WhisperVADInference("model.onnx", streaming=True)

for audio_chunk in audio_stream:
    speech_active = vad.process_chunk(audio_chunk)
    if speech_active:
        # Handle speech detection
        pass
```

## Input/Output Specifications

### Input
- **Audio Format**: 16kHz mono audio
- **Chunk Size**: 30 seconds (480,000 samples)
- **Feature Type**: 80-channel log-mel spectrogram
- **Shape**: `[1, 80, 3000]` (batch size fixed to 1 - see note below)

### Output
- **Type**: Frame-level probabilities
- **Shape**: `[1, 1500]` (batch size fixed to 1)
- **Frame Duration**: 20ms per frame
- **Range**: [0, 1] probability of speech presence

**Note on Batch Processing**: Currently, the ONNX model only supports batch size of 1 due to export limitations between PyTorch transformers and ONNX. However, single-sample inference is highly optimized and runs extremely fast (~100x real-time on CPU), making sequential processing still very efficient for most use cases.

## Training Details

### Training Configuration
- **Dataset**: ~500 hours Japanese ASMR audio recordings with accurate speech timestamps
- **Loss Function**: Focal Loss (α=0.25, γ=2.0) for class imbalance
- **Optimizer**: AdamW with learning rate 1.5e-3
- **Batch Size**: 128
- **Training Duration**: 5 epochs
- **Hardware**: Single GPU training with mixed precision (bf16)

### Data Processing
- Audio segmented into 30-second chunks
- Frame-level labels generated from word-level timestamps
- Augmentation: None (relying on Whisper's pre-training robustness)

## Limitations and Considerations

1. **Fixed Duration**: Model expects 30-second chunks; shorter audio needs padding
2. **Training Specialization**: While the model performs well across languages and environments due to Whisper's strong multilingual foundation, it excels particularly at:
   - Japanese ASMR content (primary training data)
   - Whispered and soft speech detection
   - Quiet, intimate audio environments
3. **Generalization**: The model can effectively handle various languages and normal speech volumes, though performance may be slightly better on content similar to the training data
4. **Background Noise**: Performance may degrade in very noisy conditions
5. **Music/Singing**: Primarily trained on speech; may have variable performance on singing

## Model Files

- `model.onnx`: ONNX model file
- `model_metadata.json`: Model configuration and parameters
- `inference.py`: Ready-to-use inference script with post-processing
- `requirements.txt`: Python dependencies

## Installation

```bash
pip install onnxruntime  # or onnxruntime-gpu for GPU support
pip install librosa transformers numpy
```

## Applications

- **ASMR Content Processing**: Detect whispered speech and subtle vocalizations in ASMR recordings
- **Japanese Audio Processing**: Optimized for Japanese language content, especially soft speech
- **Transcription Pre-processing**: Filter out silence before ASR, particularly effective for whispered content
- **Audio Indexing**: Identify speech segments in long recordings
- **Real-time Communication**: Detect active speech in calls/meetings
- **Audio Analytics**: Speech/silence ratio analysis for ASMR and meditation content
- **Subtitle Alignment**: Accurate timing for subtitles, including whispered dialogue

## Citation

If you use this model, please cite:

```bibtex
@misc{whisper-vad,
  title={Whisper-VAD: Whisper-based Voice Activity Detection},
  author={Grider},
  year={2025},
  publisher={Hugging Face},
  howpublished={\url{https://huggingface.co/TransWithAI/Whisper-Vad-EncDec-ASMR-onnx}}
}
```

## References

- Original Whisper Paper: [Robust Speech Recognition via Large-Scale Weak Supervision](https://arxiv.org/abs/2212.04356)
- WhisperSeg: [Positive Transfer of the Whisper Speech Transformer to Human and Animal Voice Activity Detection](https://doi.org/10.1101/2023.09.30.560270)
  - GitHub: [https://github.com/nianlonggu/WhisperSeg](https://github.com/nianlonggu/WhisperSeg)

## License

MIT License

## Acknowledgments

This model builds upon OpenAI's Whisper model and implements architectural refinements for efficient voice activity detection.