- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
,这是我想要达到的目标:
我希望能够将电话麦克风录制的音频并以给定频率处理电平到一个数组中,以创建一种“条形图”可视化器。我还需要计算播放歌曲的BPM,以了解更新可视化程序的节奏。
我真正要寻找的只是获取频率阵列和BPM计算。如果我能弄清楚如何处理音频,则可以处理实际的可视化部分。
这就是我要制作的:
从我所做的研究来看,似乎可能的解决方案是使用FFT(快速傅立叶变换)。为此,我找到了这个:stackoverflow。但是该stackoverflow线程是用于Java的,而我的应用程序当前是用Kotlin编写的。我读过有可能将Java导入Kotlin,但是经过几次尝试,我仍然无法使其工作。因此,对此的一些建议可能会有所帮助。
无论如何,我最终还是找到了一个为Kotlin Nier Vizualizer编写的库。它确实具有类似于我想要复制的形式,但是对于我的一生,我无法弄清楚从何处提取频率阵列。我尝试在将缓冲区传递到可视化器之前先读取它们,但这只是我收到的一个疯狂的长字符串。我的意思是,我不确定我期望的是什么,但是我绝对可以使用一些帮助来理解如何将其转换为可以实际使用的数据格式。
这是我所在位置的示例:KeyFrameMaker.kt
fun makeKeyFrame() {
val waveFrac = mWaveAnimator.computeCurrentValue()
val fftFrac = mFftAnimator.computeCurrentValue()
if (mWaveAnimator.hasValueUpdated) {
computedWaveData.originMap { idx, _ ->
(((mDestWaveData[idx].toInt() and 0xFF) - (mPrevWaveData[idx].toInt() and 0xFF)) * waveFrac + (mPrevWaveData[idx].toInt() and 0xFF)).toByte()
}
// Create String for computedWaveData ByteArray
var hexBuffer = ""
for (b in computedWaveData) {
hexBuffer += String.format("%02X", b)
}
println("WAVE COMPUTED: $hexBuffer")
}
if (mFftAnimator.hasValueUpdated) {
computedFftData.originMap { idx, _ ->
((mDestFftData[idx] - mPrevFftData[idx]) * fftFrac + mPrevFftData[idx]).toByte()
}
// Create String for computedFftData ByteArray
var hexBuffer = ""
for (b in computedFftData) {
hexBuffer += String.format("%02X", b)
}
println("FFT COMPUTED: $hexBuffer")
}
}
Magnitudes: 57.0, 32.649654, 123.967735, 31.622776, 121.49486, 48.104053, 47.0, 14.142136, 5.0, 7.2111025, 6.708204, 5.0, 5.8309517, 2.236068, 6.708204, 9.899495, 11.401754, 9.219544, 4.472136, 3.6055512, 4.472136, 1.4142135, 4.1231055, 8.944272, 8.5440035, 18.973665, 17.888544, 20.09975, 15.264338, 9.055386, 6.708204, 4.472136, 3.1622777, 3.1622777, 2.236068, 2.236068, 2.0, 2.236068, 2.0, 0.0, 2.828427, 4.1231055, 3.6055512, 3.6055512, 2.828427, 4.472136, 2.828427, 2.236068, 2.0, 2.0, 2.0, 1.4142135, 2.0, 2.236068, 2.0, 1.4142135, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 0.0, 1.0, 1.4142135, 1.0, 1.0, 1.0, 1.4142135, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.4142135, 1.4142135, 1.0, 1.0, 1.4142135, 1.0, 1.4142135, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.4142135, 1.0, 1.0, 1.0, 0.0, 1.0, 1.4142135, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0
Magnitudes: 25.0, 69.289246, 132.63861, 129.71121, 21.095022, 23.537205, 23.537205, 9.219544, 22.847319, 14.422205, 10.816654, 8.944272, 2.236068, 0.0, 3.1622777, 8.062258, 20.615528, 2.828427, 4.1231055, 7.81025, 4.0, 2.236068, 3.1622777, 5.656854, 13.038404, 34.713108, 53.712196, 9.848858, 21.023796, 8.062258, 5.0990195, 5.3851647, 3.6055512, 3.1622777, 3.1622777, 3.1622777, 3.1622777, 3.1622777, 2.236068, 2.236068, 2.236068, 2.828427, 2.236068, 1.0, 4.0, 4.0, 3.1622777, 2.0, 2.0, 1.0, 2.0, 1.4142135, 1.4142135, 2.0, 3.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 2.236068, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.4142135, 1.0, 1.0, 1.0, 1.0, 1.0, 1.4142135, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0
Magnitudes: 2.0, 19.104973, 30.232433, 73.3553, 6.4031243, 27.513634, 76.537575, 43.462627, 17.262676, 12.369317, 13.601471, 13.341664, 9.486833, 11.18034, 15.811388, 13.601471, 45.01111, 37.01351, 44.64303, 21.023796, 1.4142135, 7.28011, 8.5440035, 4.2426405, 13.416408, 21.023796, 16.492422, 11.401754, 3.0, 5.0, 5.0990195, 2.0, 3.6055512, 3.0, 2.0, 2.828427, 4.472136, 2.0, 3.1622777, 3.0, 2.0, 2.828427, 3.6055512, 0.0, 3.1622777, 2.236068, 2.0, 3.0, 2.236068, 3.1622777, 2.236068, 2.0, 2.236068, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 2.0, 2.0, 1.0, 1.0, 2.0, 1.4142135, 1.4142135, 2.0, 1.0, 1.0, 2.0, 1.4142135, 1.4142135, 1.0, 2.236068, 1.0, 1.4142135, 3.0, 2.828427, 1.4142135, 3.0, 1.4142135, 2.236068, 4.0, 1.0, 1.4142135, 2.0, 1.0, 1.4142135, 1.0, 0.0, 1.4142135, 1.0, 1.4142135, 2.0, 1.4142135, 1.0, 1.4142135, 1.4142135, 0.0, 1.4142135, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.4142135, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0
Phases: 0.0, 2.0638473, 0.52183425, 0.15991312, 1.94013, -1.1383885, -1.2847449, 0.8519663, 2.4980915, 2.3561945, 2.7367008, 2.9441972, 2.7610862, 3.1415927, 2.0899425, 2.0344439, -0.32175055, -2.2794225, 2.3561945, 1.2490457, -1.5707964, -0.98279375, 2.4668517, 1.5707964, 2.3561945, 1.5707964, 3.1415927, 3.1415927, 1.5707964, 2.3561945, 3.1415927, 1.5707964, 1.5707964, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 2.3561945, 1.5707964, -1.5707964, 3.1415927, 0.0, 3.1415927, -2.6779451, 0.0, 3.1415927, -2.3561945, 2.3561945, 0.0, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 0.0, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 0.0, 3.1415927, 3.1415927, 3.1415927, 0.0, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, -2.3561945, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 0.0, 3.1415927, 1.5707964, 0.0, 0.0, 0.0, 3.1415927, 2.6779451, 3.1415927, 2.3561945, -0.7853982, 0.0, -2.819842, 0.0, -1.5707964, -2.0344439, 2.6779451, 3.1415927, 1.5707964, 2.6779451, 1.5707964, -2.3561945, 0.0, 3.1415927, 2.3561945, 2.3561945, 0.0, -2.3561945, 2.3561945, -1.5707964, 3.1415927, 0.0, -2.6779451, 1.5707964, 0.0, 0.0, 3.1415927, 0.0, 0.0, 3.1415927, 3.1415927, 3.1415927, 0.0, -1.5707964, 3.1415927, -2.3561945, -2.3561945, 3.1415927, 0.0, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 2.3561945, 0.0, 3.1415927, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 0.0, 3.1415927, 0.0, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 0.0, -2.3561945, 3.1415927, -2.3561945, -2.3561945, 3.1415927, 3.1415927, 3.1415927, -2.3561945, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, -2.3561945, 3.1415927, -2.3561945, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, 3.1415927, -2.3561945, 3.1415927, 3.1415927, -2.3561945, 3.1415927, -2.3561945, -2.3561945, 3.1415927, 3.1415927, -2.3561945, -2.3561945, -2.3561945, -2.3561945, -2.3561945, 0.0
Phases: 0.0, 2.2694561, -1.7492068, -1.8925469, -0.15702978, 1.2095926, 0.0, 1.4288993, -0.9272952, -0.5880026, -1.1071488, -0.6435011, -0.5404195, 0.4636476, -2.6779451, -2.3561945, -2.2318394, -0.86217004, 1.1071488, 2.158799, -2.6779451, -0.7853982, 1.815775, 2.6779451, -1.929567, 0.32175055, 1.1071488, 1.4711276, 2.1224513, -1.6814536, -1.1071488, -1.1071488, -1.2490457, -1.2490457, -1.1071488, -1.1071488, -1.5707964, -1.1071488, 0.0, 0.0, -2.3561945, -1.3258177, 0.5880026, 2.55359, -2.3561945, -1.1071488, -0.7853982, -1.1071488, -1.5707964, -1.5707964, -1.5707964, -0.7853982, 3.1415927, -2.6779451, -1.5707964, -0.7853982, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, 3.1415927, -2.3561945, -1.5707964, -1.5707964, -1.5707964, -2.3561945, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -2.3561945, -2.3561945, -1.5707964, -1.5707964, -2.3561945, -1.5707964, -2.3561945, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -2.3561945, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -2.3561945, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, 0.0, 0.0, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, 0.0, 0.0, 0.0, 0.0, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, 0.0, 0.0, -1.5707964, 0.0
Phases: 0.0, 1.2170932, -2.5222197, 1.1243883, 0.094951704, 0.21406068, 1.784857, -2.4329665, -0.4048918, -0.5880026, -0.98279375, -1.1071488, 1.1071488, 0.0, 1.2490457, 2.0899425, 2.7430701, 0.7853982, -1.815775, -0.87605804, 1.5707964, -1.1071488, -2.819842, -0.7853982, 1.0040671, 2.2950463, 2.6363025, 2.7233684, -1.1284221, -1.0516502, -1.3734008, -1.19029, -0.98279375, -1.2490457, -1.2490457, -1.2490457, -1.2490457, -1.2490457, -1.1071488, -1.1071488, -1.1071488, -0.7853982, 0.4636476, -1.5707964, -1.5707964, -1.5707964, -1.2490457, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -0.7853982, -0.7853982, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -2.0344439, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -2.3561945, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -2.3561945, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, -1.5707964, -1.5707964, 0.0, 0.0, -1.5707964, 0.0, -1.5707964, -1.5707964, -1.5707964, 0.0, 0.0, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, -1.5707964, 0.0, 0.0, -1.5707964, -1.5707964, 0.0, 0.0, 0.0
class MainActivity : AppCompatActivity() {
val SAMPLING_RATE = 44100
val REQUEST_CODE_AUDIO_PERMISSION = 1
private var visualizer: Visualizer? = null
lateinit var magnitudesArray: FloatArray
private var mWaveBuffer: ByteArray? = null
private var mFftBuffer: ByteArray? = null
private var mDataCaptureSize: Int = 0
private var mAudioBufferSize: Int = 0
private var mAudioRecord: AudioRecord? = null
private var mAudioRecordState: Boolean = false
@TargetApi(Build.VERSION_CODES.KITKAT)
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ensurePermissionAllowed()
println("OUTSIDE PERMISSIONS CHECK")
mAudioBufferSize = AudioRecord.getMinBufferSize(SAMPLING_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_8BIT)
mAudioRecord = AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLING_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_8BIT, mAudioBufferSize)
println("mAudioBufferSize: $mAudioBufferSize")
if (mAudioRecord!!.state != AudioRecord.STATE_INITIALIZED) println("AudioRecord init failed")
else println("AudioRecord init success")
try {
println("BEGIN INITIALIZING VIZUALIZER.")
println("Audio Session ID: ${mAudioRecord!!.audioSessionId}")
//visualizer = Visualizer(mAudioRecord.audioSessionId).apply {
visualizer = Visualizer(0).apply {
enabled = false
captureSize = 512
//captureSize = captureSizeRange[1]
try {
scalingMode = Visualizer.SCALING_MODE_NORMALIZED
} catch (e: NoSuchMethodError) {
println("CANT SET SCALING MODE.")
}
measurementMode = Visualizer.MEASUREMENT_MODE_NONE
setDataCaptureListener(object : Visualizer.OnDataCaptureListener {
override fun onFftDataCapture(visualizer: Visualizer?, fft: ByteArray?, samplingRate: Int) {
val n = fft?.size
val magnitudes = FloatArray(n!! / 2 + 1)
val phases = FloatArray(n / 2 + 1)
magnitudes[0] = Math.abs(fft[0].toFloat())
magnitudes[n / 2] = Math.abs(fft[1].toFloat())
phases[n / 2] = 0f
phases[0] = phases[n / 2]
for (k in 1 until n / 2) {
val i = k * 2
magnitudes[k] = Math.hypot(fft[i].toDouble(), fft[i + 1].toDouble()).toFloat()
phases[k] = Math.atan2(fft[i + 1].toDouble(), fft[i].toDouble()).toFloat()
}
println(magnitudes.joinToString(", "))
println(phases.joinToString(", "))
}
override fun onWaveFormDataCapture(visualizer: Visualizer?, waveform: ByteArray?, samplingRate: Int) {
val waveBuffer = mWaveBuffer ?: return
if (waveform == null || waveform.size != waveBuffer.size) {
return
}
System.arraycopy(waveform, 0, waveBuffer, 0, waveform.size)
}
}, Visualizer.getMaxCaptureRate(), true, true)
}.apply {
mDataCaptureSize = captureSize.apply {
mWaveBuffer = ByteArray(this)
mFftBuffer = ByteArray(this)
}
}
} catch (e: RuntimeException) {
println("ERROR DURING VISUALIZER INITIALIZATION: $e")
}
record_button.setOnClickListener {
if (!mAudioRecordState) {
mAudioRecord!!.startRecording()
visualizer?.enabled = true
mAudioRecordState = true
}
else {
mAudioRecord!!.stop()
visualizer?.enabled = false
mAudioRecordState = false
}
}
}
private fun ensurePermissionAllowed() {
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
println("PERMISSION TO RECORD AUDIO DENIED. REQUESTING.")
ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.RECORD_AUDIO), REQUEST_CODE_AUDIO_PERMISSION)
}
else {
println("PERMISSION TO RECORD AUDIO GRANTED.")
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
when (requestCode) {
REQUEST_CODE_AUDIO_PERMISSION -> {
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Demo need record permission, please allow it to show this visualize effect!", Toast.LENGTH_LONG).show()
finish()
}
}
}
}
最佳答案
如果您使用的是Android Visualizer类,则不需要其他FFT库,因为Visualizer类提供了getFFT()
方法,该方法可向您返回已应用FFT的音频。您只需要将其转换为dB级别的幅度,即可使其在图形中看起来不错。
在尝试实例化Visualizer之前,您需要请求麦克风权限,否则它将无法初始化。 Visualizer主要用C语言实现,并且主要是JNI包装器,因此如果出现问题,则会引发大量RuntimeExceptions,因此您需要将初始化和设置调用包装在try / catch块中。
lateinit var magnitudesArray: FloatArray
//...
val captureSizeRange = Visualizer.getCaptureSizeRange()
try {
visualizer = Visualizer(0)
visualizer?.let {
scalingMode = Visualizer.SCALING_MODE_NORMALIZED
captureSize = captureSizeRange[1]
setDataCaptureListener(this, Visualizer.getMaxCaptureRate(), false, true)
enabled = true
}
} catch (e: RuntimeException) {
//..log it
}
magnitudesArray = FloatArray(captureSizeRange[1] / 2 + 1)
onFftDataCapture
函数,以使用
documentation中给出的公式将传入的FFT传输到
magnitudesArray
。将log10函数应用于这些值以获得适合于可视化的幅度(人耳以大约log10的比例解释相对声能,这就是为什么声音通常以dB单位描述的原因)。
关于java - 请求有关可视化器的Android Kotlin音频分析的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57931246/
我是一个相对较新的程序员; CS 学士学位,大学毕业大约 2 年,主要使用 C# 中的 .NET。我对 SQL 交互/脚本编写相当流利,并且对 ASP.NET 做了一些工作(主要是维护现有站点)。 我
我计划开发一个简单的解决方案,使我能够即时执行非常基本的视频流分析。我以前从未做过类似的事情,因此这是一个非常笼统和开放的问题。主要重点是检查流是否正常运行,例如 - 卡住帧、黑屏以及音频是否存在。同
我正在考虑重组一个大型 Maven 项目...... 我们当前结构的基本概述: build [MVN plugins, third party dependency management]:5.1
我需要有关附加查询的建议。该查询执行了一个多小时,并根据解释计划进行了全表扫描。我对查询调优还很陌生,希望得到一些建议。 首先,为什么我要进行全表扫描,即使我使用的所有列都在其上创建了索引。 其次,有
我正在做一个项目,我需要在 4 个模型之间创建三个多对多关系。这是它的过程: 常见问题类别可以有许多常见问题子类别,反之亦然。 常见问题组可以有许多常见问题的子类别,反之亦然。 常见问题可以有许多常见
对于代码大小比语音质量更重要的 PIC 和/或 ARM 嵌入式系统,是否有任何易于使用的免费或廉价的语音合成库?现在似乎 1 meg 的封装被认为是“紧凑的”,但很多微 Controller 都比它小
我们正在使用 Solr 建议器功能进行 businessName 查找。当用户输入查询以及匹配的名称时,我们希望 solr 发送来自个人资料的其他属性,如 id、地址、城市、州、国家等字段。 我尝试使
我正在构建一个用户界面。我的计划将包括 4 个主要部分: 1) 顶部菜单 - TMainMenu。一个窗口的顶部 2) 主菜单 - TTreeView。一个窗口的左边。 TreeView的每一项=对应
我的公司需要一个任务管理系统来处理从“为X购买一台计算机”到“将一个人转移到另一个国家”这样简单的场景。简单的场景是由一个人处理的单个任务,而更大的任务可以分解为在工作流程中委派给多个人的多个子任务。
MarkLogic 服务器的林大小与实际内存的建议比率是多少?例如,我目前有一个 190GB 的数据库,并且该数据库随着时间的推移而不断增长。由于数据库会不断增长,我最终需要对该数据库进行集群。因此,
去年我收到了一个礼物,它是一个索尼 CMT700Ni 音频站,支持 wifi。它还具有类似于广播的功能,称为“PartyStreaming”。我目前正在挖掘内部,探索它,所以也许我可以结束拥有自己的“
有没有我可以阅读的研究论文/书籍可以告诉我针对手头的问题哪种特征选择算法最有效。 我试图简单地将 Twitter 消息识别为 pos/neg(首先)。我从基于频率的特征选择开始(从 NLTK 书开始)
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我正在浏览 stackoverflow 以查找有关使用 jUnit 进行测试的常见建议,但仍然有几个问题。我知道,如果要测试的方法很复杂,最好的方法是将其分成小的单独部分并测试每个部分。但问题是 -
我有一个方法如下 public List> categorize(List customClass){ List> returnValue = new ArrayList<>();
我的问题是,当按照下面的程序合并时,在最佳实践场景中,“将分支折叠回主干”程序的最后一步是正确的方法吗? 我已经使用 svn 很多年了。在我的个人项目中,我总是毫不犹豫地在主干上愉快地进行修改,并且在
我读过 UINavigationController当您想从 n 个屏幕跳转到第一个屏幕时,这是最佳选择。这样做需要以下代码: NSMutableArray *array=[[NSMutableArr
我有一个文件输入类。它在构造函数中有一个字符串参数来加载提供的文件名。但是,如果文件不存在,它就会退出。如果文件不存在,我希望它输出一条消息 - 但不确定如何...... 这是类(class): pu
我希望创建一个“您访问过的国家/地区” map - 就像您可能在 Facebook、TravelAdvisor 和诸如此类的网站上看到的那样。 我尝试过不同的闪光灯套件,但它们并不像我希望的那样先进。
我需要一些关于如何处理我想用 Perl 编写的脚本的建议。基本上我有一个看起来像这样的文件: id: 1 Relationship: "" name: shelby pet: 1
我是一名优秀的程序员,十分优秀!