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โ
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)
}
Create processorโ
import NCKit
let modelURL = try NCKitModelLocator.modelTarGzURL()
let processor = try NCKitProcessor(
modelURL: modelURL,
attenLimDb: 100, // 100 = unlimited attenuation
postFilterBeta: 0 // 0 = post-filter off
)
Process one hop (real-time)โ
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
}
}
Tune at runtimeโ
processor.setAttenLim(60) // lighter noise reduction
processor.setPostFilterBeta(0.02) // stronger residual-noise suppression
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.