深圳深网站建设服务,西乡做网站公司,小程序怎么生成,福州建站模板搭建本人并不干这个#xff0c;但是被迫下水了解了一下这个#xff0c;稍微做了一下整理。再就是感觉现在网上以及ChatGPT在这方面给出的答案太水了#xff0c;在此开辟一篇。无意放出代码#xff0c;这里只介绍一些可能重要的点。 本来以为有了ChatGPT写这些就没有必要了… 本人并不干这个但是被迫下水了解了一下这个稍微做了一下整理。再就是感觉现在网上以及ChatGPT在这方面给出的答案太水了在此开辟一篇。无意放出代码这里只介绍一些可能重要的点。 本来以为有了ChatGPT写这些就没有必要了现在看起来还是不太可能。
一是知识稍微旧了一点新一点的没有比如github上近一年更新的优秀项目100%是不会出现在解决方案中的。追求能用是不影响的但是想找最好的有点难。二是方案缺少出处扩展溯源困难。三是多方案比较困难不易从中选取出最好的方案。四是幻觉太多验证成本太高。
1. 解码
这里将解码定义为将有损/无损的压缩格式比如 mp3/aac 等等转换到 pcm/wav 这种原始数据的格式的操作供下游使用。 原始数据可以理解为 采样率 × 位深度 × 通道数 × 音频时长 的数据不加其它处理。
2. 基本参数
来自 javax.sound.sampled.AudioFormat先要理解记住这些才能够有良好掌控 - encoding – the audio encoding technique - sampleRate – the number of samples per second - sampleSizeInBits – the number of bits in each sample - channels – the number of channels (1 for mono, 2 for stereo, and so on) - frameSize – the number of bytes in each frame - frameRate – the number of frames per second - bigEndian – indicates whether the data for a single sample is stored in big-endian byte order
3. FFmpeg A complete, cross-platform solution to record, convert and stream audio and video. 可能是最强的功能非常齐全离线格式转换命令行就用它了但是要注意ffmpeg在做转换时有不少参数直接默认了使用代码转换可能有各种对不上所以需要对参数的理解。 常见音频编码都是确定性编码不要自欺欺人觉得大小不一致还是正常的得每一个byte都一样才正常。 4. javax.sound.sampled
支持PCM/WAV之类的原始音频格式service provider: 在实现之后能够自动发现和支持更多格式
5. hendriks73/ffsampledsp
有了1-4的铺垫之后就只需要一个优秀项目来完成剩余的工作了目前看起来FFSampledSP是最佳选择之一服务器的 FFSampledSP is an implementation of the javax.sound.sampled service provider interfaces based on FFmpeg, a complete, cross-platform solution to record, convert and stream audio and video. FFSampledSP is part of the SampledSP collection of javax.sound.sampled libraries. 相当于引入了ffmepg的能力在已有的库中实现得是相当好的了。解码流的时候需要调试参数可以先校验是否能转换AudioInputStream fileStream AudioSystem.getAudioInputStream(file);
AudioFormat sourceFormat fileStream.getFormat();
log.info(in audio format: {}, aacFormat);
AudioFormat targetFormat new AudioFormat();
AudioSystem.isConversionSupported(sourceFormat, targetFormat); // 需要为true引入依赖即可并无太多需要注意的。也就是知识要得挺多使用起来反而没什么。