Created
March 3, 2014 19:13
-
-
Save mansam/9332445 to your computer and use it in GitHub Desktop.
Audio device detection w/ pyaudio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lsusb | |
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub | |
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. | |
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. | |
Bus 001 Device 006: ID 05e3:0606 Genesys Logic, Inc. USB 2.0 Hub / D-Link DUB-H4 USB 2.0 Hub | |
Bus 001 Device 009: ID 1130:f211 Tenx Technology, Inc. TP6911 Audio Headset | |
# cat d.py | |
import pyaudio | |
p = pyaudio.PyAudio() | |
info = p.get_host_api_info_by_index(0) | |
numdevices = info.get('deviceCount') | |
#for each audio device, determine if is an input or an output and add it to the appropriate list and dictionary | |
for i in range (0,numdevices): | |
if p.get_device_info_by_host_api_device_index(0,i).get('maxInputChannels')>0: | |
print "Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0,i).get('name') | |
if p.get_device_info_by_host_api_device_index(0,i).get('maxOutputChannels')>0: | |
print "Output Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0,i).get('name') | |
devinfo = p.get_device_info_by_index(1) | |
print "Selected device is ",devinfo.get('name') | |
if p.is_format_supported(44100.0, # Sample rate | |
input_device=devinfo["index"], | |
input_channels=devinfo['maxInputChannels'], | |
input_format=pyaudio.paInt16): | |
print 'Yay!' | |
p.terminate() |
Which version of Python are you using? This is old Python 2 code, it will throw a syntax error on that print statement under Python 3.
I fixed it, thanks. Didnt see that there is no ( ) after "print"
Using Python 3.9
пн, 30 авг. 2021 г. в 17:46, Samuel Lucidi ***@***.***>:
… ***@***.**** commented on this gist.
------------------------------
Which version of Python are you using? This is old Python 2 code, it will
throw a syntax error on that print statement under Python 3.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/9332445#gistcomment-3876760>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOGE5AA23IWD4KJMGP23YCDT7N4SDANCNFSM5DBLFJKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
invalid syntax here:
print "Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0,i).get('name')