Audio in python

GroupDIY Audio Forum

Help Support GroupDIY Audio Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

5v333

Well-known member
Joined
Jun 30, 2013
Messages
631
Location
Gothenburg
Has anybody experience in working with playback, recording and analysis in python.
I had an idea of an audio measuring script but im on square one when it comes to audio in python.

Any recomendations on modules to use? And/or other things to study?
 
Yes. I do. Python is one of the easier programming languages to get into. I'm still surprised some university basic compsci programming courses favour java over python and then going on to other things like C/C++ and Java etc. for industry. Especialy since Python is widely used in Linux Distributions, Web Backends, Database manipulation and everything else you can think of - there's a decent Python library out there.

If you're new to python consider reading one of the great free introductory books that you can find online:
This blogpost contains a list - Learning Python — The Hitchhiker's Guide to Python (varying degrees of difficulty)
The Python Project homepage has very good documentation and recommendations for free learning on and off site as well (python.org - BeginnersGuide - Python Wiki)

As for audio - there is many libraries, what exactly do you want to do? You may want to combine different high quality libraries.

For example: Audio - Python Wiki for interfacing with audio, manipulating files etc. this contains a list of some of the available libraries with their specific focus in the comment column to the right.

For analysis, graphing etc. you will want to take a look at scipy and matplotlib.

If you use Mac or Linux to program take a look at using ipython for development. It's easier to write and prototype quickly. Theres' also ipython Notebook (now kown as Project Jupyter) if you want a graphic application - which also works on Windows as far as I'm aware.

HTH. It's a very versatile language. You can even program microcontrollers in python or easy Arduino automation, just a few examples for projects. You will find a lot of finished projects in varying state of support for all kinds of use cases on www.github.com (example: filter in the search bar by language python and type in what you're looking for).

Let me know if you have any questions.

Enjoy,
Aaron
 
Last edited:
Yes. I do. Python is one of the easier programming languages to get into. I'm still surprised some university basic compsci programming courses favour java over python and then going on to other things like C/C++ and Java etc. for industry. Especialy since Python is widely used in Linux Distributions, Web Backends, Database manipulation and everything else you can think of - there's a decent Python library out there.

If you're new to python consider reading one of the great free introductory books that you can find online:
This blogpost contains a list - Learning Python — The Hitchhiker's Guide to Python (varying degrees of difficulty)
The Python Project homepage has very good documentation and recommendations for free learning on and off site as well (python.org - BeginnersGuide - Python Wiki)

As for audio - there is many libraries, what exactly do you want to do? You may want to combine different high quality libraries.

For example: Audio - Python Wiki for interfacing with audio, manipulating files etc. this contains a list of some of the available libraries with their specific focus in the comment column to the right.

For analysis, graphing etc. you will want to take a look at scipy and matplotlib.

If you use Mac or Linux to program take a look at using ipython for development. It's easier to write and prototype quickly. Theres' also ipython Notebook (now kown as Project Jupyter) if you want a graphic application - which also works on Windows as far as I'm aware.

HTH. It's a very versatile language. You can even program microcontrollers in python or easy Arduino automation, just a few examples for projects. You will find a lot of finished projects in varying state of support for all kinds of use cases on www.github.com (example: filter in the search bar by language python and type in what you're looking for).

Let me know if you have any questions.

Enjoy,
Aaron
Great post.

PS, I am not surprised at all about university programs favoring java. I work at a university, and logic is a rare commodity; hardheadedness and bureaucracy are the prevalent factors. Professors are rarely willing to get out of their comfort zone by changing what they have been teaching for decades. I work at the EE department, and, for example, some of the old timers teaching undergrads refuse to have anything to do with simulators. Such is the nature of the university beast...
 
Great post.

PS, I am not surprised at all about university programs favoring java. I work at a university, and logic is a rare commodity; hardheadedness and bureaucracy are the prevalent factors. Professors are rarely willing to get out of their comfort zone by changing what they have been teaching for decades. I work at the EE department, and, for example, some of the old timers teaching undergrads refuse to have anything to do with simulators. Such is the nature of the university beast...
Yeah I agree totally. We've had these discussions many times back when i worked at a spin off of the local technical university focusing on security research as we were still very close to uni; CTO was a long term professor, many post docs ended up teaching etc. -- python is something they should start with in compsci and then move on. you'll have to do compiler design etc anyway if you're all in not just after a bachelor degree. In any case the profs doing some of the courses were as antiqued as their material. I'm self taught and never regretted not going. It didn't matter either, I was supposed to teach an advanced course at a technical college - it was "well" paid (for uni standards - and per hour) too. but after looking at the existing material I realized I'll have to put a month into rewriting the curriculum, which isn't paid for. also it ended up too far away from where I lived without a car to go multiple times a week in the early morning. Especially if I need to work nights. If I end up going to study at some point I'd choose something entirely unrelated: linguistics, physics, anthropology maybe. but work doesn't allow for any of that the next few years. maybe I'll go for a study sabbatical like my team lead did at his former job mid in his 50ies he got a master in theoretical/particle physics. Unfortunately here (Austria/EU) that's only partly sponsored if you're employed for a certain number of years. I'm self employed so would have to pay everything myself and live of who knows what; as a student you're not even eligible for our welfare system in case you've been self employed previously - not that I want to rely on that either :)
 
Last edited:
Thanks!
Im not entierly new to python. We recently had a python course at uni but it was focused on logics and numerical analysis.
So i know about numpy, scipy, plots, loops etc but audio is the new thing here.
I need to know about converting arrrays into wavs and backwards, how to route sound to specific channels etc.
 
Yes. I do. Python is one of the easier programming languages to get into. I'm still surprised some university basic compsci programming courses favour java over python and then going on to other things like C/C++ and Java etc. for industry. Especialy since Python is widely used in Linux Distributions, Web Backends, Database manipulation and everything else you can think of - there's a decent Python library out there.

..........

I program in C and have recently started learning C++. I have also bought a (great) book on Java but I think it will stay on the shelf for a while as I have definitely made a decision to go with Python. Thank you for the links.

However, the advantage of knowing C is that learning other programs becomes a lot easier. Knowing assembly is even one step further into working at registry level. This is particularly important for embedded programming.
 
Different languages are better or worse for different situations. If you know c or c++ you will see a lot of drawbacks to python. And once you know python you'll wish c++ had the same extent of easy to grab modules (I don't know why there isn't a C++ namespace for every python module?)
Really comparing a compiled to interpreter language seems a little odd.

However, the advantage of knowing C is that learning other programs becomes a lot easier. Knowing assembly is even one step further into working at registry level. This is particularly important for embedded programming.
My 1st language is C and I agree it makes other languages easier and you apply a better mindset to higher level languages like python.
 
I concur with the advice here. My ECE BS program back in the 80s used FORTAN77 (on mainframes) and Pascal on various PCs for teaching software and programming. I learned C at a summer job in '87 and never looked back. Except for one SW prof in grad school who taught in Ada (he was on one of the first Ada compiler dev teams to pass the early DoD milestones).

Got into C++, again on the job, in '98. Spent my whole career in C and C++ with some extensive use of SSE intrinsics on several projects. Was always curious about Python, but never had time or a good reason to use it until my last job. There were a few guys doing some of their work in Python and I started chatting with them about it. Then a little sub-task came along that seemed like a perfect fit. I decided to jump in and use it to teach myself Python. Got a lot of help from a couple of younger guys who had several years of Python experience and made the thing work.

All of the libraries make things easy. Almost too easy for doing basic tasks. I suspect this may be part of the reason it isn't used to teach fundamental algorithms, data structures, etc. My take is that it's great for doing quick one-offs or "glue programs" as part of a larger project. Converting data files or extracting/distilling/rearranging information between systems is easy. Doing status dashboards for daily or weekly progress/status of operations is easy. It's really powerful. But the mindset for writing Python, for me at least, was very different than writing C.

Good luck on your journey. I'd try to find some sample code that does something with audio and start modifying it or adding to it. Then try something small from scratch. If you can, find a local Python guru to help get you started.
 
Last edited:
Freshman year back in the 60s involved learning to program using Fortran IV. We would have to type out our programs onto hollerith cards using key punch machines. Our programs would be batch run over night on the school's IBM 360 mainframe.

JR
 
I concur with the advice here. My ECE BS program back in the 80s used FORTAN77 (on mainframes) and Pascal on various PCs for teaching software and programming.
I've been wanting to learn FORTRAN for a long time now. Some colleagues who work on applied electromagnetics (Finite Element Analysis and such) say it is still the best programming language for fast numerical codes, and they swear by it. I use MATLAB and I love it, but I must reckon that it is not the most efficient environment, first, it requires, well, MATLAB; you can't use it stand-alone. Also, the code is very high level, with many custom functions. It is very similar to Python; you require Anaconda or whatever you want to use, and it is not the most efficient type of code, but it is very easy to do powerful stuff in it with a relatively small effort.

Some time ago I purchased some cheap FORTRAN courses online, but they were very amateur-ish. I haven't found any FORTRAN courses on Coursera or EDX, everyone wants to learn Phyton, and no one seems to care for the good ol' FORTRAN, aside from a niche market.

I have a book on FORTRAN 95, I guess I could start there, but I have too much stuff on my plate right now...
 
Last edited:
the version of fortran (IV) I learned on in the 60s, was pretty rudimentary...

I recall with some amusement how crude their math operations were. I recall rounding errors like 2x3=5.99 and silly stuff like that.

JR
 
I never touched FORTRAN after about 1986. Even in the 80s and 90s the science guys complained about fundamental numerical problems with C. Not sure of that still holds or whether Python is better. Most of what I've done is integer and non-demanding floating point numerical stuff.

I have had to use MATLAB before. While it works well for some things, it is horribly inefficient. One job I started out inheriting a mess of a computer vision algorithm that had also been implemented in MATLAB (for a multi-million dollar piece of production capital equipment). What a disaster. After a year I was finally able to convince management that both the algorithm and its implementation language were terrible choices. Redesigned it and implemented in C/C++ for a 10-30x speedup.

For one-off heavy lifting scientific computation/modelling stuff it might be a valid choice, but you will pay in time and/or compute resources if it is a big computation. In production, throughput (and cost) are king.
 
Matlab originates from Fortran Ive been told.
I was glad when we had our course in python because now i dont need to rely on a temporary students license for matlab.
If you know matlab you will learn a lot in python in a short time.
There are lots of similarities.
 
I was glad when we had our course in python because now i dont need to rely on a temporary students license for matlab.

If you have existing Matlab scripts you would like you use, there is a mostly compatible open source language called Octave which is language compatible, and includes most of the basic functions, but is missing the more advanced add-on toolboxes you can get for Matlab.
Octave language site
 
Matlab originates from Fortran Ive been told.
I was glad when we had our course in python because now i dont need to rely on a temporary students license for matlab.
If you know matlab you will learn a lot in python in a short time.
There are lots of similarities.
Yes, I've heard similar stuff, that for the very critical applications, MATLAB uses FORTRAN code.
 

Latest posts

Back
Top