如何在JAVA中将WAV音频转换为频率文件? [英] How to convert WAV audio to frequency file in JAVA?

查看:93
本文介绍了如何在JAVA中将WAV音频转换为频率文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将立体声wav 转换为频率并将它们保存为txt。

我的想法是我必须加载wav,读取它然后保存我的电脑中的频率为txt。

例如

0:00 min 50HZ

0:01 min 57HZ

....

1:10分450HZ




我尝试运行和编辑很多项目,但我无法实现它。(样本,字节,fft等等尝试失败太多)

任何源代码执行此操作?谢谢



我尝试过:



I want to convert stereo wav into frequency and save them into a txt.
The idea is that i have to load the wav, reading it and finally save the frequencies in my computer as a txt.
For example
0:00 min 50HZ
0:01 min 57HZ
....
1:10 min 450HZ


I try to run and edit a lot of projects but i couldnt achive it.(Too many failed attempts with samples, bytes, fft, ...etc)
Any source code that do this?Thanks

What I have tried:

ByteArrayOutputStream out = new ByteArrayOutputStream();
                running = true;
                int n = 0;
                byte[] buffer = new byte[(int) 1024];
                try { while (running) {
                               n++;
                    if (n > 200000){break;}                  
                    int count = 0;
                    count = outDinSound.read(buffer, 0, 1024);
                        if (count > 0) {out.write(buffer, 0, count);}
                                      }
                    byte b[] = out.toByteArray();
<pre>final int totalSize = b.length;
                    int amountPossible = totalSize / 1024;
                    System.out.println("Frequencies captured: "+totalSize+"         "+amountPossible+" * 1024");
                    System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");                  
                    Complex[][] results = new Complex[amountPossible][];
                    System.out.println("                    * * *   STARTING ANALYSIS   * * *");
                    for (int times = 0; times < amountPossible; times++) {
                        Complex[] complex = new Complex[1024]; 
                        for (int i = 0; i < 1024; i++)                                   {
                        complex[i] = new Complex(b[(times * 1024) + i], 0);              }
                        results[times] = FFT.fft(complex);
                                                                         }

推荐答案

这是一项非常复杂的任务,你要做的事情,你仍然没有完全解释详细说明你想要的。所以我的建议是实现一个你知道可行的FFT算法,然后尝试实现你想要的代码。如果你遇到困难,你可以改善你的问题。



但是你应该知道,如果你想要一个显示一些倍频程相关噪声电平的均衡器,你根本就不需要FFT。您可以使用时间信号简单地获得适当的滤波器和卷积。对于A加权分贝,也可以使用相同的程序,使用不同的滤波器,这也常用于将噪声水平作为一个数字。



但是这些方法需要在Q& A论坛上不能轻易实现的知识。
This is quite a complex task you are setting out to do, and you have still not explained in exact detail what you want. So my advice to you is to implement an FFT algorithm that you know works, then try and implement the code you want. If you get stuck you can improve your question.

But you should know that if you want an equalizer that shows some octave band related noise level you don't need the FFT at all. You can simply get the appropriate filter and convolute that with the time signal. The same procedure can also be used, with a different filter, for A-weighted decibels which are also commonly used to give the noise level as a single digit.

But these approaches require knowledge that is not trivially implemented on a Q&A forum.


这篇关于如何在JAVA中将WAV音频转换为频率文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆