How to get the current selected audio device in python? - python

I'm using python to get the current selected audio device in windows. I'm using pyaudio now and open to use other libs.
What I have achieved:
with pyaudio's get_device_info_by_index I can list all audio devices.
with pyaudio's get_default_output_device_info I can get the default audio device(seems to me it's the internal audio device embedded in PC)
What I have tried:
If I plug in my headphone or connect the PC to some bluetooth speaker, I can use get_device_info_by_index to get new plugged devices. But get_default_output_device_info still gives me the default PC speaker.
So I need a way to find out the current selected speaker. For example, I connect headphone and bluetooth speaker to the PC, so I have 3 output speakers. Then I can use windows's control panel to select a speak to use.
I need a way to find out which one is selected in Python, either pyaudio or any other libs.

Related

Change microphone voice with Python (in Windows)

I would like to replicate the Clownfish app in Python.
I need to use Python to transmit an audio file to the microphone, on Windows, Linux, and Mac, such that if any service is listening to the microphone (for example, skype), it would catch that audio I'm transmitting.
Is there any way to transmit audio through the user's microphone?
There's pyvoicechanger which works only for Linux.
Take a look at this library PyAudio.
Looks like you could use wire or wire (callback).
PyAudio Example: Make a wire between input and output (i.e., record a
few samples and play them back immediately).
Another library you should take a look at is python-sounddevice.

How to manage audio in and out from and to file of Huawei GSM modems?

I've got a Huawei E173 USB dongle connected to a Raspberry PI.
I'm trying to use the device to make and receive calls.
For my purpose, it is needed (i) to save audio of the call to file and (ii) to send audio to the telephony call from an input file.
As far as I understood (I can't find any official guide), the E173 dongle sets up three new devices (please correct me if I'm wrong):
/dev/ttyUSB0 for commands
/dev/ttyUSB1 for voice data
/dev/ttyUSB2 for notifications
In order to enable phone calls, I run the following commands: AT+CLIP=1, AT+CRC=1, AT+CNMI=1,2 on /dev/ttyUSB0.
Also, if I run AT^CVOICE? I get ^CVOICE:0,8000,16,20.
Finally, when I make/receive calls, I run AT^DDSETEX=2 on /dev/ttyUSB0 to enable audio forward to the /dev/ttyUSB1 port.
At this point, I'm stuck.
I know there are other similar posts trying to redirect microphone input and speakers output to the dongle, but my aim is to save the conversation to file (during a call, I tried to run cat /dev/ttyUSB1 > filename.raw, but the file can't be opened with standard software, hence, how can I convert it?) and, simultaneously, to send voice from file (which format? I tried to send back the filename.raw to /dev/ttyUSB1 with cat filename.raw > /dev/ttyUSB1, but the entire system gets freezed).
How can I save audio to file and send back audio from file?
I found some resources on the Internet trying to explain, for similar devices, that audio has to be sent in mono, in digital frequency of 8000 Hz, and digitalized to 16 bit. By looking at the result of the AT^CVOICE? command, such parameters should be applied also in my case.
Also, the same resource tells that "audio data should be fed to the modem audio port in batches of 320 bytes every 0.02 seconds".
I've tried to apply even such approach, with no luck.
I'm also stuck trying to get audio from a huawei E153.. if I use the 'Huawei Mobile Partner' software. I can use the pc sound to hear and talk during a voice call, so I know it is possible for sure. I read that someone could manage to get the sound form a Huawei Mobile modem in ubuntu, take a look here:
https://askubuntu.com/questions/464661/way-to-call-through-huawei-modem-in-14-04-e303

How to Detect event generated by USB device into raspberry pi

Hello geniuses i want to only detect the event generated by a usb device attached to it like barcode scanner.Now want that a barcode scanner is plugged in to a usb port of a raspberry pi.now when it scan then how can my rpi detect that a usb device has generated a event.
Hopefully PyUSB works, and in that case you can follow this guide
If for whatever reason that doesn't work, you could open the /dev/tty device direclty with a standard:
with open('/dev/tty4', 'rb') as fh:
for event in fh.read(8)
Note that /dev/tty is just a out-of-the-hat example, your device might end up somewhere else. Check dmsg and lsusb to determine where your device got mounted, if at all mounted or discovered. You might need specific drivers for your scanner.

How to identify a keyboard from HID when is attached via USB on Linux

I have a problem to identify what kind of device has been attached via USB, I am developing with Python and I am using a watcher to check any changes on the folder /dev/input.
As soon as I attach a device, I get an alert that something has changed, but I need to hook up the new device with the library evdev.
In this point I am not sure how can I check if the device is genuine keyboard or barcode scanner instead of a mouse or other devices.
Does every keyboard has a "keyboard" word into the description? Does the HID using a special driver only for keyboard and another one for mouse?
The keyboard that I am going to attach is not going to be a unique one, I can go to the shop a buy a new one and then it should work when it's plugged.
I am not 100% sure how the HID and Plug&Play works on Linux, so I need to get some more information about them.
Summary:
- Code: Python
- Library: evdev
Goal: hook up the keyboard/barcode scanner just plugged with a python script using the evdev library

RS232 Serial - USB Converter device path (/dev/ttyUSB*) not getting listed

I am using an RS232 Serial - USB Converter to connect to a controller. I am trying to connect to this port programmatically.
The device is getting listed as below when I give lsusb
Bus 003 Device 003: ID 05ad:0fba Y.C. Cable U.S.A., Inc.
But I am not able to see it's device path (something like /dev/ttyUSB*).
I would like to know the way to get the path from device id (or) a way to create / find the path which can be used to open the port from a program (Ruby, Python, C)
Centos has a fairly old kernel. It may be lacking in support for your device.
Are you able to try with a newer distribution (Fedora, Ubuntu, etc) to test whether it works or not? Failing that, do you have a different dongle you can use?
You can Google for "Centos 05ad:0fba" or similar combinations to find out whether it's supported.

Categories