mirror of
https://gitee.com/mymagicpower/AIAS.git
synced 2024-12-05 21:57:59 +08:00
.. | ||
lib | ||
src | ||
ndarray_audio_sdk.iml | ||
pom.xml | ||
README.md |
NDArray 高级音频工具箱
当前功能包括:
- 获取音频文件的float数组
- 保存音频文件
- 创建给定持续时间和采样率的静音音频段
- 在这个音频样本上加一段静音
- 将任意数量的语音片段连接在一起
- 生成以分贝为单位的音频均方根能量
- 将音频归一化,使其具有所需的有效值(以分贝为单位)
- 用快速傅里叶变换计算线性谱图
- Hanning窗
- 从wav提取mel频谱特征值
运行例子 - AudioExample
...
NDManager manager = NDManager.newBaseManager(Device.cpu());
float[] floatArray = AudioArrayUtils.floatData("src/test/resources/test.wav");
//音频的float数组
logger.info("音频的float数组: {}", Arrays.toString(floatArray));
NDArray samples = manager.create(floatArray);
float rmsDb = AudioUtils.rmsDb(samples);
//返回以分贝为单位的音频均方根能量
logger.info("音频均方根能量: {}", rmsDb);
//提取特征前将音频归一化至-20 dB(以分贝为单位)
float target_dB = -20f;
samples = AudioUtils.normalize(samples, target_dB);
System.out.println("音频归一化: " + samples.toDebugString(1000000000, 1000, 1000, 1000));
//生成帧的跨步大小(以毫秒为单位)
float stride_ms = 10f;
//用于生成帧的窗口大小(毫秒)
float window_ms = 20f;
samples = AudioUtils.linearSpecgram(manager, samples, stride_ms, window_ms);
logger.info("快速傅里叶变换计算线性谱图: {}", samples.toDebugString(1000000000, 1000, 10, 1000));...
命令行查看输出:
...
[INFO ] - 音频均方根能量: -28.989937
[INFO ] - 音频归一化: ND: (134240) cpu() float32
[ 3.09278257e-03, 3.26460390e-03, 1.71821259e-04, ... 133240 more]
[INFO ] - 快速傅里叶变换计算线性谱图: ND: (161, 838) cpu() float32
[[-15.4571, -16.4412, -16.7098, -20.372 , -23.9935, -15.8598, -17.1589, -15.5935, ..., -14.3427],
[-15.948 , -16.8391, -16.8302, -17.8034, -19.115 , -15.8378, -19.4812, -15.7247, ..., -14.7543],
[-20.8405, -18.5733, -19.4289, -19.1861, -19.4255, -18.1996, -18.0149, -18.977 , ..., -17.5405],
[-19.1938, -21.0139, -21.07 , -20.2931, -20.23 , -22.3037, -20.1103, -21.3521, ..., -20.2267],
[-19.7823, -21.2425, -21.5705, -19.9856, -21.6053, -20.9323, -22.4014, -21.5406, ..., -20.1177],
[-20.0329, -23.9688, -20.718 , -20.9419, -23.5446, -21.1718, -22.1597, -20.9377, ..., -21.3833],
[-19.3693, -21.0484, -21.1794, -20.765 , -20.6318, -20.5121, -21.7306, -20.6366, ..., -21.5107],
[-18.6552, -20.0077, -20.6954, -20.5476, -19.7953, -21.1081, -22.0988, -20.7157, ..., -20.6352],
[-18.9167, -19.3219, -20.1954, -24.7476, -20.7662, -20.3794, -24.4699, -22.1381, ..., -22.1803],
[-19.3055, -19.4264, -20.4486, -22.8299, -21.0847, -23.5101, -20.4897, -19.7943, ..., -22.8922],
... 151 more]
...
帮助
引擎定制化配置,可以提升首次运行的引擎下载速度,解决外网无法访问或者带宽过低的问题。
引擎定制化配置