NCKitProcessor
NCKit inference engine. Create one instance per session and reuse it.
Requirementsโ
| Parameter | Value |
|---|---|
| Sample rate | 48,000 Hz |
| Channels | 1 (mono) |
| Format | Float32 in [-1.0, 1.0] |
| Hop size | frameLength (480 samples = 10 ms) |
APIโ
Swift
public final class NCKitProcessor {
public let frameLength: Int
public init(
modelURL: URL,
attenLimDb: Float = 100,
postFilterBeta: Float = 0
) throws
@discardableResult
public func processFrame(
input: UnsafeMutablePointer<Float>,
output: UnsafeMutablePointer<Float>
) -> Float
public func setAttenLim(_ db: Float)
public func setPostFilterBeta(_ b: Float)
}
Kotlin
class NCKitProcessor @JvmOverloads constructor(
modelFile: File,
public val attenLimDb: Float = 100f,
public val postFilterBeta: Float = 0f,
) : AutoCloseable {
val frameLength: Int
fun processFrame(input: FloatArray, output: FloatArray): Float
fun setAttenLim(db: Float)
fun setPostFilterBeta(beta: Float)
override fun close()
}
Create processorโ
Swift
import NCKit
let modelURL = try NCKitModelLocator.modelTarGzURL()
let processor = try NCKitProcessor(
modelURL: modelURL,
attenLimDb: 100, // 100 = unlimited attenuation
postFilterBeta: 0 // 0 = post-filter off
)
Kotlin
import com.fiveexceptions.nckit.NCKitModelLocator
import com.fiveexceptions.nckit.NCKitProcessor
val modelFile = NCKitModelLocator.modelFile(context)
val processor = NCKitProcessor(
modelFile = modelFile,
attenLimDb = 100f,
postFilterBeta = 0f,
)
// Or use AutoCloseable:
NCKitProcessor(modelFile).use { processor -> /* ... */ }
Process one hop (real-time)โ
Swift
let hop = processor.frameLength
var input = [Float](repeating: 0, count: hop)
var output = [Float](repeating: 0, count: hop)
// Fill input[0..<hop] with 48 kHz mono samples from your audio source
input.withUnsafeMutableBufferPointer { inBuf in
output.withUnsafeMutableBufferPointer { outBuf in
let lsnr = processor.processFrame(
input: inBuf.baseAddress!,
output: outBuf.baseAddress!
)
// lsnr: local SNR estimate (dB), optional voice-activity hint
}
}
Kotlin
val hop = processor.frameLength
val input = FloatArray(hop) // fill with 48 kHz mono samples
val output = FloatArray(hop)
val snrDb = processor.processFrame(input, output)
// snrDb: local SNR estimate (dB) for this frame
Tune at runtimeโ
Swift
processor.setAttenLim(60) // lighter noise reduction
processor.setPostFilterBeta(0.02) // stronger residual-noise suppression
Kotlin
processor.setAttenLim(60f)
processor.setPostFilterBeta(0.02f)
Throwsโ
| Error | When |
|---|---|
NCKitError.libraryInit / NCKitException.LibraryInit | Model failed to load |
NCKitError.missingModel / NCKitException.MissingModel | Model file missing |
Notesโ
- Not thread-safe โ call
processFramefrom one serial queue / coroutine context only. setAttenLim/setPostFilterBetaare safe from any thread.- Android: call
close()(oruse {}) when done to release native memory (~30 MB). - Live audio: prefer NCKitStreamProcessor over manual
processFramehop accumulation.