Audacity Spectrum Generation and Python

Help for Audacity on GNU/Linux.
Forum rules
ImageThis forum is for Audacity on GNU/Linux.
Please state:
  • which version of Linux you are using,
  • the exact three-section version number of Audacity from Help menu > About Audacity,
  • whether you installed your distribution's release, PPA version, or compiled Audacity from source code.

Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade (see https://www.audacityteam.org/download/).
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Post Reply
RubenvWyk
Posts: 10
Joined: Tue Oct 25, 2016 5:55 pm
Operating System: Linux *buntu

Audacity Spectrum Generation and Python

Post by RubenvWyk » Tue Oct 25, 2016 6:32 pm

Hi Everybody \m/

First of, I want to say thank you for all the effort you have put into creating Audacity. I learned a great deal, in a very short amount of time with the help of all your efforts.

This year, I was working on a DSP project that required me to write a program in Python to plot the spectrum of recordings obtained using Audacity.

I basically used Audacity to record sound with a normal microphone -> laptop setup. Then my Python program would read it, and use existing libraries (such as http://greenteapress.com/wp/think-dsp/) to generate a spectrum and look at different frequency bands.

In the end, everything worked out, but I could never get the same spectrum plot as Audacity... I am unsure of whether my analysis was faulty, or my windowing, or if Audacity does some smoothing that I could not get behind. I was wondering if it is possible to pipe the spectrum data from Audacity to Python?

If not, can someone point me in a direction where I can figure out what I did wrong?

I am unsure of what I should provide here to be helped... but I will be more than willing to supply any needed info.

Thanks.

steve
Site Admin
Posts: 80752
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by steve » Tue Oct 25, 2016 7:27 pm

Are you referring to "Plot Sectrum" (http://manual.audacityteam.org/man/plot_spectrum.html)
If so, you can export the data as a text file (see link above for details)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

RubenvWyk
Posts: 10
Joined: Tue Oct 25, 2016 5:55 pm
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by RubenvWyk » Thu Oct 27, 2016 8:09 am

Yes, I am referring to "Plot Spectrum"...

But instead of having to export the data, since that has to be done manually as far as I know, I want to automate the process :)

record -> analyze recording -> plot spectrum (generate spectrum data) -> python for analysis

steve
Site Admin
Posts: 80752
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by steve » Thu Oct 27, 2016 10:53 am

RubenvWyk wrote:But instead of having to export the data, since that has to be done manually as far as I know, I want to automate the process :)
Audacity does not have that feature built in, but some options are:

* Use AutoKey, Sikuli or similar to automate Audacity via its GUI.

* Build Audacity from the sourcecode and enable "mod-script-pipe" (Some of the documentation may be out of date as I don't think anyone has worked on this "experimental" feature for quite a while: http://manual.audacityteam.org/man/scripting.html)

* Perform the FFT analysis directly in Python.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

RubenvWyk
Posts: 10
Joined: Tue Oct 25, 2016 5:55 pm
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by RubenvWyk » Thu Oct 27, 2016 11:36 am

Thanks for the advice.

I will explore the "mod-script-pipe" and AutoKey avenues and report back.

Regarding the FFT in Python... this is what I did do, but my FFT analyses does not output the same graphs (guessing its either my smoothing or windowing methods that are faulty) as Audacity and subsequently I do not get the correct peak values. That is why I thought that maybe I can somehow access (or pipe) the data that Audacity generates :)

steve
Site Admin
Posts: 80752
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by steve » Thu Oct 27, 2016 12:52 pm

RubenvWyk wrote: but my FFT analyses does not output the same graphs
Are you comparing the (text) data, or just the (graphic) graph?
The text data from Audacity is "scientifically" accurate, but how the graph is drawn is in part a matter of interpretation. There are many ways to interpolate / extrapolate, and the methods used by Audacity are just one choice. Different methods can look significantly different.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

RubenvWyk
Posts: 10
Joined: Tue Oct 25, 2016 5:55 pm
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by RubenvWyk » Thu Oct 27, 2016 8:05 pm

well, I saw that if I take the text from the exported file, and plot it in Excel (for instance) then I get the same graph as Audacity...

So I figured I needed this data, plot the graph in Python, and then analyze the graph itself for max, min, turning points, etc...

The whole point of all of this is automation in the end.

steve
Site Admin
Posts: 80752
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by steve » Thu Oct 27, 2016 11:33 pm

I've been trying to remember the name of the automation tool I used a while back (to automate a job in Audacity) - just remembered :)
Actionaz (https://www.jmgr.net/)
Ubuntu and Debian both have it in their repositories.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

RubenvWyk
Posts: 10
Joined: Tue Oct 25, 2016 5:55 pm
Operating System: Linux *buntu

Re: Audacity Spectrum Generation and Python

Post by RubenvWyk » Fri Oct 28, 2016 6:34 am

W0000000T!!!

Will give it a try as soon as I can, and let you know :)

Thank you for all the advice.

Post Reply