|
| 1 | +# NeMoFeatureExtractor-Android |
| 2 | + |
| 3 | +Kotlin library for extracting mel spectrograms compatible with NVIDIA NeMo models on Android. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- NeMo-compatible mel spectrogram extraction |
| 8 | +- Support for VAD (MarbleNet), ASR (Conformer, Parakeet), and Speaker (TitaNet) models |
| 9 | +- Pre-computed NeMo filterbank for maximum accuracy |
| 10 | +- Pure Kotlin implementation with no external dependencies |
| 11 | +- Configurable normalization modes |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +- Android API 24+ |
| 16 | +- Kotlin 1.9+ |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +### Gradle |
| 21 | + |
| 22 | +Add JitPack repository to your project's `settings.gradle.kts`: |
| 23 | + |
| 24 | +```kotlin |
| 25 | +dependencyResolutionManagement { |
| 26 | + repositories { |
| 27 | + maven { url = uri("https://jitpack.io") } |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +Add the dependency to your module's `build.gradle.kts`: |
| 33 | + |
| 34 | +```kotlin |
| 35 | +dependencies { |
| 36 | + implementation("com.github.Otosaku:NeMoFeatureExtractor-Android:1.0.0") |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +### Basic Usage |
| 43 | + |
| 44 | +```kotlin |
| 45 | +import com.otosaku.nemofeatureextractor.NeMoFeatureExtractor |
| 46 | +import com.otosaku.nemofeatureextractor.MelSpectrogramConfig |
| 47 | + |
| 48 | +// For VAD (MarbleNet) |
| 49 | +val vadExtractor = NeMoFeatureExtractor(context, MelSpectrogramConfig.nemoVAD) |
| 50 | +val features = vadExtractor.process(audioSamples) |
| 51 | + |
| 52 | +// For ASR (Conformer, Parakeet) |
| 53 | +val asrExtractor = NeMoFeatureExtractor(context, MelSpectrogramConfig.nemoASR) |
| 54 | +val features = asrExtractor.process(audioSamples) |
| 55 | + |
| 56 | +// For Speaker (TitaNet) |
| 57 | +val speakerExtractor = NeMoFeatureExtractor(context, MelSpectrogramConfig.nemoSpeaker) |
| 58 | +val features = speakerExtractor.process(audioSamples) |
| 59 | +``` |
| 60 | + |
| 61 | +### Without Context (generates filterbank) |
| 62 | + |
| 63 | +```kotlin |
| 64 | +val extractor = NeMoFeatureExtractor(MelSpectrogramConfig.nemoVAD) |
| 65 | +val features = extractor.process(audioSamples) |
| 66 | +``` |
| 67 | + |
| 68 | +### Custom Configuration |
| 69 | + |
| 70 | +```kotlin |
| 71 | +val config = MelSpectrogramConfig( |
| 72 | + sampleRate = 16000, |
| 73 | + nMels = 80, |
| 74 | + nFFT = 512, |
| 75 | + windowSize = 400, |
| 76 | + hopLength = 160, |
| 77 | + normalization = NormalizationMode.PER_FEATURE, |
| 78 | + preemph = 0.97f |
| 79 | +) |
| 80 | + |
| 81 | +val extractor = NeMoFeatureExtractor(context, config) |
| 82 | +``` |
| 83 | + |
| 84 | +## Audio Requirements |
| 85 | + |
| 86 | +- Sample rate: 16,000 Hz |
| 87 | +- Channels: Mono |
| 88 | +- Format: Float32 array |
| 89 | + |
| 90 | +## Configuration Presets |
| 91 | + |
| 92 | +| Preset | Normalization | Pad To | Use Case | |
| 93 | +|--------|---------------|--------|----------| |
| 94 | +| `nemoVAD` | None | 2 | Voice Activity Detection (MarbleNet) | |
| 95 | +| `nemoASR` | Per-feature | 0 | Speech Recognition (Conformer, Parakeet) | |
| 96 | +| `nemoSpeaker` | Per-feature | 16 | Speaker Verification (TitaNet) | |
| 97 | + |
| 98 | +## Output Format |
| 99 | + |
| 100 | +The `process()` method returns `Array<FloatArray>` with shape `[nMels, nFrames]`: |
| 101 | +- `nMels`: Number of mel frequency bins (default: 80) |
| 102 | +- `nFrames`: Number of time frames (depends on audio length) |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +MIT License |
| 107 | + |
| 108 | +## Related Projects |
| 109 | + |
| 110 | +- [NeMoFeatureExtractor-iOS](https://github.com/Otosaku/NeMoFeatureExtractor-iOS) - iOS/macOS version |
| 111 | +- [NVIDIA NeMo](https://github.com/NVIDIA/NeMo) - Original implementation |
0 commit comments