PyAudio provides Python bindings for PortAudio, the cross-platformaudio I/O library. With PyAudio, you can easily use Python to play andrecord audio on a variety of platforms. PyAudio is inspired by:
- Volume Control On Multi Output Device For Mac Pro
- Volume Control On Multi Output Device For Mac Download
When using the Built-in Output as part of a Mult-Output Device, you can set the volume of the Built-in Output with AppleScript: osascript -e 'set volume 2' This doesn't seem to affect the volume of the other devices that are part of the Multi-Output Device. Now, if only there was a way to get the volume button keys to run a script! Mar 10, 2018 In the right pane place a check next to SoundFlower (2ch) and the external device you have currently attached or your Internal Speakers if no such device is attached. Then,Right click or CTRL + CLICK on Create Multi Output Device and click Use this device for sound output from the pop up menu. USB and Bluetooth powered audio devices connect just as easily with a Mac. If you need them to work with the built-in speakers, or any other device connected to the audio jack, it’s fairly easy. There’s a built-in tool on macOS that lets you combine and output audio to multiple devices. Output audio to multiple devices. Aug 20, 2020 If you set your master volume to 10 and Chrome to 50, Chrome will play at a volume level of 5. If an app doesn’t appear in the list, you’ll need to launch it first—and perhaps start playing or recording audio in it. To the right of the volume slider for each app, click the “Output” or “Input” dropdowns to assign a different output. Soundflower, a multi-output device (that part was 10.7 specific), and line-in to copy - I didn't know at that time that soundflowerbed could copy for me. Sadly, while 10.6.8 works better than 10.7 in several respects, the video recording frameworks in 10.7 are significantly superior to 10.6 - 10.6's Quicktime can only record a full screen.
- pyPortAudio/fastaudio: Python bindings for PortAudio v18 API.
- tkSnack: cross-platform sound toolkit for Tcl/Tk and Python.
To use PyAudio, first instantiate PyAudio using
pyaudio.PyAudio()
(1), which sets up the portaudio system.To record or play audio, open a stream on the desired device with thedesired audio parameters using
pyaudio.PyAudio.open()
(2). This sets up a pyaudio.Stream
to play or recordaudio.Play audio by writing audio data to the stream using
pyaudio.Stream.write()
, or read audio data from the streamusing pyaudio.Stream.read()
. (3)Note that in “blocking mode”, each
pyaudio.Stream.write()
orpyaudio.Stream.read()
blocks until all the given/requestedframes have been played/recorded. Alternatively, to generate audiodata on the fly or immediately process recorded audio data, use the“callback mode” outlined below.Use
pyaudio.Stream.stop_stream()
to pause playing/recording,and pyaudio.Stream.close()
to terminate the stream. (4)Finally, terminate the portaudio session using
pyaudio.PyAudio.terminate()
(5)In callback mode, PyAudio will call a specified callback function (2)whenever it needs new audio data (to play) and/or when there is new(recorded) audio data available. Note that PyAudio calls the callbackfunction in a separate thread. The function has the followingsignature
callback(<input_data>,<frame_count>,<time_info>,<status_flag>)
and must return a tuple containing frame_count
frames of audio data and a flag signifying whether there are moreframes to play/record.Start processing the audio stream using
pyaudio.Stream.start_stream()
(4), which will call thecallback function repeatedly until that function returnspyaudio.paComplete
.To keep the stream active, the main thread must not terminate, e.g.,by sleeping (5).
- Classes
PyAudio
,Stream
- Host Specific Classes
PaMacCoreStreamInfo
- Stream Conversion Convenience Functions
get_sample_size()
,get_format_from_width()
- PortAudio version
get_portaudio_version()
,get_portaudio_version_text()
- Portaudio Sample Formats
paFloat32
,paInt32
,paInt24
,paInt16
,paInt8
,paUInt8
,paCustomFormat
- PortAudio Host APIs
paInDevelopment
,paDirectSound
,paMME
,paASIO
,paSoundManager
,paCoreAudio
,paOSS
,paALSA
,paAL
,paBeOS
,paWDMKS
,paJACK
,paWASAPI
,paNoDevice
- PortAudio Error Codes
paNoError
,paNotInitialized
,paUnanticipatedHostError
,paInvalidChannelCount
,paInvalidSampleRate
,paInvalidDevice
,paInvalidFlag
,paSampleFormatNotSupported
,paBadIODeviceCombination
,paInsufficientMemory
,paBufferTooBig
,paBufferTooSmall
,paNullCallback
,paBadStreamPtr
,paTimedOut
,paInternalError
,paDeviceUnavailable
,paIncompatibleHostApiSpecificStreamInfo
,paStreamIsStopped
,paStreamIsNotStopped
,paInputOverflowed
,paOutputUnderflowed
,paHostApiNotFound
,paInvalidHostApi
,paCanNotReadFromACallbackStream
,paCanNotWriteToACallbackStream
,paCanNotReadFromAnOutputOnlyStream
,paCanNotWriteToAnInputOnlyStream
,paIncompatibleStreamHostApi
- PortAudio Callback Return Codes
paContinue
,paComplete
,paAbort
- PortAudio Callback Flags
paInputUnderflow
,paInputOverflow
,paOutputUnderflow
,paOutputOverflow
,paPrimingOutput
pyaudio.
get_format_from_width
(width, unsigned=True)¶Returns a PortAudio format constant for the specified width.
Parameters: |
|
---|---|
Raises: | ValueError – when invalid width Animal crossing wild world action replay codes north america. |
Return type: | A PortAudio Sample Format constant |
pyaudio.
get_portaudio_version
()¶Returns portaudio version.
Return type: | string |
---|
pyaudio.
get_portaudio_version_text
()¶Ragtime 6.5.2 serial. Returns PortAudio version as a text string.
Return type: | string |
---|
pyaudio.
get_sample_size
(format)¶Returns the size (in bytes) for the specifiedsample format.
Parameters: | format – A PortAudio Sample Format constant. |
---|---|
Raises: | ValueError – on invalid specified format. |
Return type: | integer |
pyaudio.
paAL
= 9¶Open Audio Library
pyaudio.
paALSA
= 8¶Advanced Linux Sound Architecture (Linux only)
pyaudio.
paASIO
= 3¶Steinberg Audio Stream Input/Output
pyaudio.
paAbort
= 2¶An error ocurred, stop playback/recording
pyaudio.
paBeOS
= 10¶BeOS Sound System
pyaudio.
paComplete
= 1¶This was the last block of audio data
pyaudio.
paContinue
= 0¶There is more audio data to come
pyaudio.
paCoreAudio
= 5¶CoreAudio (OSX only)
pyaudio.
paCustomFormat
= 65536¶a custom data format
pyaudio.
paDirectSound
= 1¶DirectSound (Windows only)
pyaudio.
paFloat32
= 1¶32 bit float
pyaudio.
paInDevelopment
= 0¶Still in development
pyaudio.
paInputOverflow
= 2¶Buffer overflow in input
pyaudio.
paInputUnderflow
= 1¶Buffer underflow in input
pyaudio.
paInt16
= 8¶16 bit int
pyaudio.
paInt24
= 4¶24 bit int
pyaudio.
paInt32
= 2¶32 bit int
pyaudio.
paInt8
= 16¶8 bit int
pyaudio.
paJACK
= 12¶JACK Audio Connection Kit
pyaudio.
paMME
= 2¶Multimedia Extension (Windows only)
pyaudio.
paNoDevice
= -1¶Not actually an audio device
pyaudio.
paOSS
= 7¶Open Sound System (Linux only)
pyaudio.
paOutputOverflow
= 8¶Buffer overflow in output
pyaudio.
paOutputUnderflow
= 4¶Buffer underflow in output
Volume Control On Multi Output Device For Mac Pro
pyaudio.
paPrimingOutput
= 16¶Just priming, not playing yet
pyaudio.
paSoundManager
= 4¶SoundManager (OSX only)
pyaudio.
paUInt8
= 32¶8 bit unsigned int
pyaudio.
paWASAPI
= 13¶Windows Vista Audio stack architecture
pyaudio.
paWDMKS
= 11¶Windows Driver Model (Windows only)
[This article covers using a Mac's HDMI output for surround sound audio using an HDMI equipped A/V receiver. Info here should still be applicable to later OS X versions and newer Macs if using HDMI output. Also here's a later article with Notes/Tips for Repeated Mac Mini Video Blackouts with some A/V Receivers that includes Receiver HDMI Info, Tests and Tips on HDMI and HDCP problems in OS X.](from a reader mail, reply bounced so posting here)
'OS X DVD Player HDMI Audio Question
I finally hooked up my new mac mini to our receiver so we'd have surround sound possible with DVDs played in OS X. The OS X Sound pref pane set to HDMI Output (see example below) and Audio/Midi utility configured correctly for multi-channel audio. (I think.) The receiver the mini's HDMI is connected to shows 'PCM' during playback and DVD movie (Dolby Digital 5.1) audio seems muffled compared to playing the same DVD in our home dvd player. We noticed the standalone player shows 'Dolby Digital' on the receiver's display - not 'PCM'. DVDs just sound much better from the home player than from the OS X DVD player connected to the same receiver.
How do I get the OS X DVD player to send 'dolby digital' to the receiver to see if that helps?
-Beth'
First, I'm assuming your Sound Output (System prefs) is set to HDMI like this example:
FYI: When set to HDMI audio output, the Mac's audio volume control is disabled.
Volume is controlled from the connected device (i.e. Receiver or HDTV).
As for changing the OS X DVD Player audio output to Dolby Digital (and not PCM) - it's a simple change in the OS X DVD Player settings. Set the OS X DVD player Prefs (in 'Disc Setup' options) Audio Output to 'Digital Out'. As you have it set (from the comments), the Mac/OS X DVD Player is decoding the Dolby Digital audio on the DVD and sending PCM audio to your receiver. (When set to Digital Out, it will bitstream Dolby Digital (or DTS) to the receiver for decoding.) Apple's support article on 'Setting up iTunes & DVD Player for digital surround sound' (support.apple.com/kb/HT4072, later changed to HT202029), went from 'archived, no longer updated' to removed as of 2019. Here's a screenshot from my OS X DVD Player Audio Output prefs setting.
The 'Digital Output' option may also have info on the connected device appended to it. (My example above has 'Samsung' - the TV brand connected to the AVR. Winning eleven 8 for pc. If not going through a receiver, you'd usually get only Stereo with direct TV connections.) As you can see in the screenshot, I also check the option to 'Disable Dolby dynamic range compression'. (I prefer maximum dynamic range although some may not, especially for nighttime viewing. A/V Receivers often have DRC options also.)
iTunes Surround Sound Settings:
The Apple article also had info on surround sound setting in iTunes. Click the 'Speech Bubble' icon (see below) to see/select available audio options for the specific file being played. Apple says in iTunes 11 and later, digital surround sound is selected automatically for content that includes it. (Surround output still relies on proper hardware/configuration and options can vary depending on the media used.)
The Apple article also had info on surround sound setting in iTunes. Click the 'Speech Bubble' icon (see below) to see/select available audio options for the specific file being played. Apple says in iTunes 11 and later, digital surround sound is selected automatically for content that includes it. (Surround output still relies on proper hardware/configuration and options can vary depending on the media used.)
I rarely use it and don't buy/rent iTunes content so can't comment on quality or specific recommended titles.
OS X DVD Player (Subjective) Sound Quality (PCM vs Bitstreaming/Digital output)
After Beth's comments on (PCM) DVD movie SQ, I checked this on my AVR (with TDKR DVD's Dolby Digital 5.1) and PCM output from the OS X DVD player seemed (by ear) about 5-6dB down vs Bitstreaming at the same AVR Master Volume setting. Lower volume (level) with LPCM vs Bitstream isn't uncommon, but even adjusting for volume level, I still preferred bitstreaming Dolby Digital/DTS to the AVR as it also shows the codec used on the AVR display (vs 'PCM'). Often in blind speaker tests most think 'louder' is better, within limits of course. Normally from a standalone player, SQ should be equivalent (PCM vs Bitstream) unless there's another issue present. (I used a 2012 Mac Mini 2.3GHz quad-core i7, 16GB RAM with OS X 10.9.5. Not tested other versions/player software.) Bottom line, I prefer letting the A/V Receiver decode DVD surround sound rather than OS X. (And one less thing the Mac/OS X has to do.)
After Beth's comments on (PCM) DVD movie SQ, I checked this on my AVR (with TDKR DVD's Dolby Digital 5.1) and PCM output from the OS X DVD player seemed (by ear) about 5-6dB down vs Bitstreaming at the same AVR Master Volume setting. Lower volume (level) with LPCM vs Bitstream isn't uncommon, but even adjusting for volume level, I still preferred bitstreaming Dolby Digital/DTS to the AVR as it also shows the codec used on the AVR display (vs 'PCM'). Often in blind speaker tests most think 'louder' is better, within limits of course. Normally from a standalone player, SQ should be equivalent (PCM vs Bitstream) unless there's another issue present. (I used a 2012 Mac Mini 2.3GHz quad-core i7, 16GB RAM with OS X 10.9.5. Not tested other versions/player software.) Bottom line, I prefer letting the A/V Receiver decode DVD surround sound rather than OS X. (And one less thing the Mac/OS X has to do.)
Volume Control On Multi Output Device For Mac Download
And in case anyone is wondering, I was getting multi-channel PCM out. (Audio/Midi utility set for 8-channel (7.1) output. Notice this is NOT set to 'Encoded Digital Audio' option. I prefer PCM out for general (non-DVD, non-iTunes movie) playback through the AVR. Digital/Surround is set separately in the DVD Player and iTunes.) The OS X 5.1/7.1 speaker tests in Audio/Midi Setup Utility worked/played correctly (front, center, rears, subwoofer, etc. output tests) and the (Yamaha RX-A2000) AVR (set to straight surround decode/no DSP) speaker icons display showed 5.1 or 7.1 depending on my configuration set in Audio/Midi utility.
(I originally linked to Apple's PH5164 article on 'Using Audio Midi to Setup external speakers for stereo or surround sound', but they have now removed it. And their basic guide to 'Connecting a Mac to a home stereo, iPod, iPad, musical instruments, or speakers' is now Set up an audio device on your Mac or stream music from your Mac.)
BTW: I tried 5.1 vs 7.1 PCM tests with DVD Dolby Digital 5.1 in case using Dolby Digital 5.1 with 7.1 setting was a factor - it wasn't. Maybe other models/OS versions or players differ, but I see no reason not to set the DVD player to Digital Out unless your connected hardware/setup has an issue with that.
I also like that Bitstreaming shows the DVD/Movie's Codec used on the AVR's display instead of just 'PCM'. (Although I've not had the problem with my setup, as mentioned on the audio/HT page previously, some have had to set their player to PCM to avoid audio dropouts with some Dolby TrueHD audio Blu-Rays when the player was set to bitstreaming. The only time I've set my BD player to PCM is to hear director's commentary/secondary audio tracks/PIP - something I rarely do.)
About Subwoofer (Low Frequency Bass and .1) Output:
I've seen some posts in Apple's forums from mac owners saying they're not getting any subwoofer output from their Mac/OS X systems. I didn't see any detailed info on their configuration/setup but here's a list/recap of some tips, reasons why and things to check:
I've seen some posts in Apple's forums from mac owners saying they're not getting any subwoofer output from their Mac/OS X systems. I didn't see any detailed info on their configuration/setup but here's a list/recap of some tips, reasons why and things to check:
- Does the content being played have any actual low-frequency content?
- How is your A/V Receiver setup for Bass/Subwoofer management?
(Are speakers set to 'Small' with subwoofer crossover frequency set (i.e. 80Hz), etc.) - Does the Subwoofer work correctly with other content? (non-OS X player, DVD/BR discs, etc)
- Does the Subwoofer have an auto/on switch? (if so set to ON vs auto - more info below)
- Does the A/V Receiver have an option for 'expanded' surround options (but you may not like it)
Some AVRs also have a 'double bass' (or similar named) option for sending main speaker channel (not .1) low frequency audio to the Subwoofer(s) even when speakers are set to 'Large'. That usually isn't recommended however and setting speakers to 'Small' (regardless of their size/driver capability) is preferred as it reduces the amplifier load significantly by not having to handle LF (low frequency bass) output, and lets the Subwoofer do what it's designed to do better than the main speakers. This load reduction is a plus for most Receivers and can help extend the life of the amp and improve audio dynamics. (Low Frequency audio takes a LOT more power.)
Regarding Subwoofers with an Auto/On Switch:
Some subwoofer amplifiers with an 'Auto On' (or Auto Standby) feature may not be getting a high enough level signal to turn on the amp. This can vary by subwoofer/amp mfr and also by AVR. (Some AVRs output higher voltage levels than others. Regardless I don't recommend setting the AVR's SW trim level over the '0' setting as it could clip the output in some cases and reduces headroom.) Another old tip (for higher levels/better Auto on triggering) is using a 'Y' adapter at the Subwoofer if its amp has dual (R/L) inputs, but this could also clip the input stage of the SW Amp, depending on the AVR/Output level. Some higher end SW amps handle this better (input protection) but many may not.
Also some subwoofer amps with an 'Auto' on setting may go into standby if no (sufficient) signal is received for a period of time. (The SW plate amps I've had with this feature typically went into standby after appx 15 minutes. Despite them being fairly quick to switch out of standby, for some movies with extended periods of dialog, I've switched them to On vs Auto for that reason.) Despite the auto/standby feature, I still power off my amps when done using them.
Some subwoofer amplifiers with an 'Auto On' (or Auto Standby) feature may not be getting a high enough level signal to turn on the amp. This can vary by subwoofer/amp mfr and also by AVR. (Some AVRs output higher voltage levels than others. Regardless I don't recommend setting the AVR's SW trim level over the '0' setting as it could clip the output in some cases and reduces headroom.) Another old tip (for higher levels/better Auto on triggering) is using a 'Y' adapter at the Subwoofer if its amp has dual (R/L) inputs, but this could also clip the input stage of the SW Amp, depending on the AVR/Output level. Some higher end SW amps handle this better (input protection) but many may not.
Also some subwoofer amps with an 'Auto' on setting may go into standby if no (sufficient) signal is received for a period of time. (The SW plate amps I've had with this feature typically went into standby after appx 15 minutes. Despite them being fairly quick to switch out of standby, for some movies with extended periods of dialog, I've switched them to On vs Auto for that reason.) Despite the auto/standby feature, I still power off my amps when done using them.
(There's a lot more to this subject of course (room calibration/EQ, gain vs level matching subs, etc), but it's beyond the scope of this article.)
Equipment Used:
- Late 2012 Mac Mini 2.3GHz Quad-Core i7, 16GB RAM, 480GB Intel 520 SSD swap, OEM 1TB HDD.
- OS X 10.9.5 (also tested w/10.8.5). No 3rd party add-ons or plugins installed.
- Logitech Wireless K400 Keyboard with trackpad. (Using the included USB Stub receiver.)
- USB Apple 'Superdrive' (DVD/CD). (Have also used a MiniStack MAX with Blu-ray/DVD drive.)
- 2010 Yamaha RX-A2000 A/V Receiver (firmware 3.43)
- 7.2 speaker setup - Klipsch RF83s/RC64/RS62s/RS42s & SVS PC13/PB13/PB12-Ultra/2 subs, bought used/damaged over the years.
(HT/Audio page has my (750W) SVS Ultra Bash Amp Failure/Tests and Repair Info.)
This Yamaha AVR has dual subwoofer outputs and unlike some '.2' AVRs, the outputs are separate/independent. (You can setup Subs for Mono x2, Stereo, or Front/Rear configuration, although in most cases Mono is best.)