Code Monkey home page Code Monkey logo

Comments (9)

bastibe avatar bastibe commented on August 30, 2024 1

The superficial story is that PySoundCard, PyAudio, and SoundDevice internally use the C library portaudio, which introduces a bit of internal latency, while SoundCard uses the operating systems' native audio libraries directly without any additional overhead.

However, there are a few more things to consider:

  • On Windows, ultra low latency might only be possible with ASIO. portaudio supports WASAPI and ASIO (which is a separate install), while SoundCard uses only Windows' native WASAPI. Depending on your sound card, ASIO might have lower latency than WASAPI.
  • Some audio APIs in SoundCard don't guarantee a fixed block size, which might trip up your FFT processing. This is certainly something I will improve in the future, but it has not made it on all operating systems yet.
  • PySoundCard, SoundDevice, and SoundCard use CFFI to call their C libraries, while PyAudio is a compiled CPython extension. CPU overhead might be smaller for PyAudio than for the other libraries.
  • PySoundCard works, but I largely abandoned it for SoundCard. Portaudio has too many issues for my liking. If you want good bindings for portaudio, use SoundDevice.

All of this is to say: It depends. On your operating system, on your audio hardware, on your CPU load, and the particulars of your application. Personally, I'd try SoundCard first, then SoundDevice, then PyAudio.

Please do let me know your results, and report any bugs you find! SoundCard works great in my testing and in my work group, but it is still young, and probably contains some bugs.

from soundcard.

mpariente avatar mpariente commented on August 30, 2024

Thanks a lot for your quick reply, that's plenty of information!
I started using pyaudio finally, but I'll definitely try the other ones to give myself an idea of the ease and performances.
I know a little about Cython but I'm not familiat with CFFI, I'll look it up to try to give myself an idea of the pros and cons of using one or the other.

If I wanted to create a real-time audio application on Android or iOS, which of the libraries would be the easiest to re-implement?
I first try to create a prototype on a desktop (which would work on "any" OS), as a proof of concept, but if it works, I'll probably like to make it run on Android and iOS.

Thanks again for your answer and yes, if I use SoundCard and find any bug, I'll report them.

from soundcard.

bastibe avatar bastibe commented on August 30, 2024

I probably should have added that I consider PyAudio by far the hardest to use, mostly because it does not support Numpy arrays natively and you have to convert PyAudio's bytes to Numpy manually. This also comes with a performance disadvantage, since it requires an unnecessary full copy of all data.

SoundDevice and PySoundCard are largely comparable in terms of ease of use. Both have a somewhat clunky device selection interface, but playing/recording is pretty straight-forward and works natively with Numpy arrays.

I consider SoundCard significantly easier to use than all the other libraries. I created it specifically because I found PySoundCard and SoundDevice too cumbersome to use (and I created PySoundCard becauese I found PyAudio too cumbersome).

All of this is a somewhat long-winded way of saying: PyAudio is probably your worst choice, and you should only choose that if you gain measurable performance benefits from it. You probably won't.

from soundcard.

mpariente avatar mpariente commented on August 30, 2024

Thank you for your advice.
For now, what I began to write is working alright in PyAudio but given what you said, I'll switch as soon as possible to SoudCard.
The reason I chose PyAudio is because of the documentation (examples of record and wires, block or callback mode) and all the answers I found on StackOverflow.
And yes, it's obvious that the conversion between bytes and numpy array is suboptimal but it's quite easy to get from one to the other in my application.

And, do you have an idea what to use if I want to make the same kind if things on Android or iOS? You seem to have a good overview of the different libraries and their use.

from soundcard.

bastibe avatar bastibe commented on August 30, 2024

On Android and iOS? Good question.

iOS seems to use CoreAudio as its audio API, which should mean that SoundCard should work out of the box. I have not tried this, though, and it is very likely that it won't work.

I read that Android is based on ALSA, so you might be able to somehow get portaudio running on Android. Similarly, people seem to have ported pulseaudio to Android, which would enable you to use SoundCard.

But at the end of the day, it is probably easier to rely in Android's and iOS's native audio libraries using some Python bindings for Android and iOS.

from soundcard.

segalion avatar segalion commented on August 30, 2024

Hello Bastibe.
I wold like to ask for numpy requirement (as sounddevice use as optional). Do you know numpy size package? Its almost as big as all python!!!. I think is very heavy only for use good memory-managed arrays.
Have you think about a play "from disk to output" or capture "from input to disk" versions that dont need the huge numpy package?

from soundcard.

bastibe avatar bastibe commented on August 30, 2024

Numpy is required for SoundCard, both internally and for its external API. It is not possible to use SoundCard without Numpy. After all, what is the point of recording audio if you can't then interact with the data?

However, by the same token, if you don't want to interact with the data, you don't need to involve Python, either. Command line programs like sox can record audio to audio files, without requiring any programming.

from soundcard.

segalion avatar segalion commented on August 30, 2024

I understand your arguments and persective.
Problem: is not easy to find a simple player that can select witch sound device use for play (obviously multiplatform)

Things so simple as:

  • list all available sound devices (name, channels, default, properties, etc.)
  • asynchronous play a wav file (we have "wave" python support), selecting the output device.
  • asynchronous record a wav file from input device.
    its almost imposible in multiplatform (win,OSX, linux), because, usually, external players works only on default output device. (I only know the pjsip testing mini cli apps).

I am trying to find the other great question: control the volume working multiplatform (python mixer):
I am seen:

  • pycaw for windows (>=Vista) (can list cards, and control volume, even from other process,but some unmature).
  • pyalsaaudio for linux (can list, play, record and lot of mixer options, but depends on alsa-dev-libs, not always available in all platforms), or wrapper for cli aplay/arecord/amixer (that I am seen even more extendible). With pulseaudio you have even more options.
  • In OSX, "osascript" to get/set volume for default audio devices, "switchaudio-osx" cli to change global-default audio (input and output) and "system_profiler SPAudioDataType" cli to list all devices. If you know another options, I will be grateful. You have made a really great work with OSX coreaudio!!!

I am little dissapointed with python sound support, but multiplatform-sound is usually a problem everywhere.

from soundcard.

bastibe avatar bastibe commented on August 30, 2024

I see. Nevertheless, SoundCard does not work without Numpy. It uses Numpy for interpreting the raw audio buffers from pulseaudio/core audio/WASAPI, and can't run without it.

Volume control, however, is currently out of scope for SoundCard. It's a feature that would be relatively easy to implement, though. I'd be happy to accept pull requests for that.

from soundcard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.