我试图从音频信号中提取MFCC矢量作为输入到递归神经网络.但是,我无法弄清楚如何使用Core Audio在Swift中获取原始音频帧.据推测,我必须进入低级才能获得该数据,但我找不到这方面的有用资源.
如何使用Swift获取所需的音频信号信息?
编辑:这个问题被标记为如何使用Swift在iOS中捕获音频样本的可能重复?.但是,那个特定的问题没有我想要的答案.也就是说,该问题的解决方案是创建一个AVAudioRecorder,它是我的问题解决方案的一个组件,而不是最终结果.
这个问题如何将WAV/CAF文件的样本数据转换为字节数组?更像是我前进的方向.解决方案是用Objective-C编写的,我想知道是否有办法在Swift中完成它.
我想在我的iOS上使用Swift 3处理从麦克风读取的字节.我目前使用的是AVAudioEngine.
print(inputNode.inputFormat(forBus: bus).settings)
print(inputNode.inputFormat(forBus: bus).formatDescription)
Run Code Online (Sandbox Code Playgroud)
这给了我以下输出:
["AVNumberOfChannelsKey": 1, "AVLinearPCMBitDepthKey": 32, "AVSampleRateKey": 16000, "AVLinearPCMIsNonInterleaved": 1, "AVLinearPCMIsBigEndianKey": 0, "AVFormatIDKey": 1819304813, "AVLinearPCMIsFloatKey": 1]
<CMAudioFormatDescription 0x14d5bbb0 [0x3a5fb7d8]> {
mediaType:'soun'
mediaSubType:'lpcm'
mediaSpecific: {
ASBD: {
mSampleRate: 16000.000000
mFormatID: 'lpcm'
mFormatFlags: 0x29
mBytesPerPacket: 4
mFramesPerPacket: 1
mBytesPerFrame: 4
mChannelsPerFrame: 1
mBitsPerChannel: 32 }
cookie: {(null)}
ACL: {(null)}
FormatList Array: {(null)}
}
extensions: {(null)}
}
Run Code Online (Sandbox Code Playgroud)
问题是我想要发送数据的服务器不期望32位浮点数而是16位无符号整数.我想我必须改变mFormatFlags.有谁知道我怎么能这样做,什么价值是正确的?
生成的字节流应该等同于我在android上使用的字节流
AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLES_PER_SECOND,
AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT,
recordSegmentSizeBytes);
Run Code Online (Sandbox Code Playgroud)
我试过这个:
let cfmt = AVAudioCommonFormat.pcmFormatInt16
inputNode.inputFormat(forBus: bus) = AVAudioFormat(commonFormat: cfmt, …Run Code Online (Sandbox Code Playgroud)