Change microphone voice with Python (in Windows) - python

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.

Related

Use OS tools to scan in an image with Python 3

I am building an application with python that needs to be able to connect to a scanner and process the data from the resulting pdf/jpeg/whatever. I have been trying to find a way to connect to the scanner to request a scan, but with no real progress.
I have looked around at all the options I could find, including this answer : I want to connect my program to image scanner
Most of the solutions I have found say that you need to use pyTwain, pySane, Libinsane, python-imagescanner, or the likes, which all seem to revolve around using TWAIN for Windows or SANE for Linux. I have a printer/scanner combo, but I can't find a TWAIN driver for it since it is not an 'enterprise' printer, but even then I don't know that this specific printer is what users would have, so I am looking for a more general solution.
The confusing part for me, is that I can still get the scanner to scan just fine by using Windows Fax and Scan, so I feel like there must be a way to get the scanner to receive a scan command from programs.
I don't really need much control over the scanner, just "scan the image and save the file here ___". So, is there any way to just tell Windows to send the "scan" command and save the output to a specific file that I can access? Maybe just using like a command through os.system()? (Basically, if windows can do it, can't I just use windows tools?)
A way to do this through linux would be helpful, too, but Windows 10 is the primary concern.
I cannot answer for Linux only for Windows.
The generic method to talk to a scanner is via Windows Image Acquisition.
In most cases the scanner needs some driver support and that's usually easily confirmed via MsPaint scanning (or if it is installed Fax scanning).
So first check the scanner in included in Windows Devices and either right click scan OR attempt a scan in Paint.
If you see messages like these the client is not enabled to use the scanner via WIA and you will need to install a suitable WIA driver.
Once that hurdle is surmounted then you can use a WIA-CMD-Scanner app to try to acquire the image to a file using https://github.com/nagimov/wia-cmd-scanner , it is a small 35 KB compiled VB exe.
So in my testing that scanner only returns a full platen scan 21.59 cm x 29.70 cm (it would not respect reducing the scan area with this tool.) NOTE also it only works with the first scanner, as found by Windows (You would need to modify the code for targeting a specific model).
The command that works for me (YMMV)
wia-cmd-scanner.exe /w 0 /h 0 /dpi 300 /color RGB /format PNG /output .\scan.png
Scanning to file .\scan.png (dpi = 300, color mode 'RGB', output format 'PNG')
Scan finished in 27 seconds
There is an example of setting date / using for loop in the readme https://github.com/nagimov/wia-cmd-scanner#scripting-and-automation

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 get the current selected audio device in 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.

How do I capture a live IP Camera feed (eg: http://61.60.112.230/view/viewer_index.shtml?id=938427) to python application?

I need to perform image recognition thing on real time camera feed. The video is embedded in shtml hosted on a IP. How do I access the video and process things using openCV.
First,you need to find the actual path to camera stream. It is mjpeg or rtsp stream. Use developer option in this page to find the stream, like http://ip/video.mjpg or rtsp://ip/live.sdp. When you find the stream url,create python script which will use stream like capture = cv2.VideoCapture(stream_url). But,as noticed,this is too broad which mean you are asking for full tutorial. This is some directions,and when you have some code,ask a question about issues with your code and you'll get an answer.

Configure Mac OS X MIDI programmatically

I'm writing a program that converts OSC into MIDI, allowing OSC enabled applications (like touchOSC on my iPhone) to control MIDI enabled applications (Sibelius, Ableton Live and so on).
I'm using Python to create an OSC server and convert from OSC to MIDI. To get MIDI to the application in question, I'm outputting MIDI to the Apple IAC driver, which is then enabled as an input within the program in question.
Does anyone know of a means to programmatically configure Mac MIDI devices programmatically? In particular, I need to enable the IAC driver, which is disabled by default.
Using FileMon, I have observed that Audio Midi Setup.app modifies this file when enabling/disabling the IAC driver:
~/Preferences/ByHost/com.apple.MIDI.0017f2cxxxxx.plist
The number 0017f2cxxxxx is my system IOPlatformUUID. It's a simple XML property list, but I'm wary of writing to it directly. Even if I did, presumably I would need to cajole the midi server process into re-reading it somehow?
Finally, I'm becoming more and more aware that using the IAC driver at all is a pretty naff solution - for a start it only works on Mac! Ideally, I would write a loopback MIDI driver and all my problems would be solved...
Your hunch about writing directly to the plist is correct -- you probably shouldn't do it. I'm not 100% sure about this, but I have a feeling that the plist reflects the state of the MIDI device, but altering it will not open or close that MIDI device as you need.
To actually open the MIDI device, you could use something like pygame. I have used it for some audio-related projects, and the SDK is very straightforward and easy to work with. As python doesn't have great support for MIDI directly, this is probably your best bet (short of writing the python C module yourself, which would be rather painful).
As for IAC, it's a shame that other OS's don't come with virtual MIDI devices like this. IAC is very useful and good at what it does. So while relying on IAC for something like this would not be cross-platform, you could write an abstraction layer for manipulating the loopback device. For Windows users, you could recommend a free MIDI loopback device to be used with your software.
If you want to send OSC to MIDI then you're best off creating a Virtual Midi port in software rather trying to remotely configure an IAC. This virtual port will show up in Ableton etc so you can then have it control things programmatically.
You can do this using the rtmidi-python library (or older and slightly different pyrtmidi) - both based on the cross-platform rtmidi lib which provides for straightforward sending of MIDI Control and Notes:
import rtmidi_python as rtmidi
vmidi_out = rtmidi.MidiOut()
vmidi_out.open_virtual_port('My Virtual MIDI Output Port')
vmidi_out.send_message([0x90, 48, 100]) # Note on
vmidi_out.send_message([176, 7, 100]) # Control Change - Volume
PyGame itself uses PortMidi under the hood. If you don't need all PyGame library, maybe this can be useful for you.

Categories