RosaKit - LibRosa port to Swift for iOS and macOS platforms.
Library can generate Mel-spectrogram using Short-time Fourier transform (STFT) algorithm.
It's provide methods for calcualte Short-time Fourier transform window and Spectrogram.
Via CocoaPods:
pod 'RosaKit'
-
Generate Spectrogram for visualisations
-
Preprocessing steps for most Machine Learning models in Sound Recognition Sphere
https://librosa.github.io/librosa/generated/librosa.feature.melspectrogram.html
You can use such code:
let rawAudioData = Data(...)
let chunkSize = 66000
let chunkOfSamples = Array(rawAudioData[0..<chunkSize])
let powerSpectrogram = samples.melspectrogram(nFFT: 1024, hopLength: 512, sampleRate: Int(sampleRate), melsCount: 128)
Please look in Examples