How do you get input from a USB microphone in Python 3? - python-3.x

How do you get input from a USB microphone in Python 3? I want to use a raspberry pi 3 model b and a USB microphone. The USB microphone has the automatic gain off. I want to get the decibel level of the sound the USB microphone is picking up, and I want to use that information as a variable to be used in the Python 3 program. I DO NOT WANT to record sound from the USB microphone, save it as a wave file, and use the wave file in the program. I want the program to be working with real time sound.

Related

Raspberry Pi to SIM8200EA-M2_5G_HAT with audio jack

I am trying to make python based phone calls, using a raspberry pi (4) and a waveshare SIM8200EA-M2_5G_HAT.
The first part was easy: find the AT commands to send over serial interface to start/stop the call.
Next step was supposed to be playing an audio file. Python to play an audio file was easy peasy. Sound came out to the audio jack of the pie. Before I think about the final solution to wire pi to HAT, I used the same earphone (phones and mic) to directly connect to the HAT. A started call (using minicom) did not provide any sound. Neither could I use the microphone nor did I hear anything from the call.
Is anyone familiar with this setup - or at least the HAT - and know about the pain to make the audio jack working?

Get MIDI note from USB interface on Arduino Yun

I am using an Arduino Yun and a MIDI to USB interface and my goal is to read the incoming MIDI note on the installed Linux operating system.
The goal is to have the computer on the Yun read the note and send it to the Arduino which then transmits a square wave over the pins at the note played on the piano.
But I can't figure out how to read from the USB interface; the Linux system is command line only and I can't figure out a good way to read the incoming note.
There is nothing special about USB; the USB MIDI driver makes the interface show up as a normal MIDI port, which can be accessed like any other MIDI port.
If you want to write a shell script, the easiest way is probably to parse the output of aseqdump.
See Translating MIDI input into computer keystrokes on Linux? for an example.
If you want to write a C program, you have to use the ALSA sequencer API; consider using the aseqdump source code as a template.
If you just want to send the raw MIDI bytes over the serial line, you can simply read them from /dev/snd/midiC?D?.

Recording wav file Using Arduino

I am bit stuck, how can I make my arduino record into .wav files?
The arduino is connected with a microphone, and am using the Arduino ADC.
Any ideas? Will I be able to play them back using my pc?
many question cross my head
1- Is this possible using an arduino Uno
2- Is this possile using just a microphone connected to the Arduino ADC
3- if yes how can i get the wav format.
The idea gonna be like this
Ardiuno microphone-->Uno ADC -->arduino (library making wav sound)--> Storing data to a an SD card connected via SPI or maybe (connecting a Raspberry as a storage device)
also another question:
4- Do I need an amplifier due to the act that analog output from the microphone is very weak so the ADC couldn't detect the variation
In another log i had seen that i should connect the microphone to a level shifter.And that cause of the analog output is AC so i have to make the negative wave as 0 (for 10 it ADC)
the zero point as 512 and the positive as 1024 (10 bit ADC).(really i'm not sure about this part)
doing some research i got this library "https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features#recording-audio" which is supposed to do the job, I mean making some wav file from the analog input.
So any help would be appreciated
Thx in advance,
Salah Laaroussi
Yes, although a bit complex it is very possible to do this via an uno.
The biggest hurdles to overcome is the limited amount of RAM and the clock speed. You will have to setup twin buffers to handle writing to the SD card. Make sure the card has a high enough write speed or the entire program will come to a screeching halt as you will run out of memory.
apc mag has a great article detailing out the circuit and code.
http://apcmag.com/arduino-projects-digital-audio-recorder.htm/
There are many things you haven't prepared yet:
output of microphone (assuming you know about electronics: still requires a biasing circuit e.g. a resistor + capacitor).
the output of the microphone is still very weak (in the magnitude of mV), which Arduino is incapable of capturing so you need a pre-amplifier
the design of the pre-amplifier will also include DC offset which makes the output of the microphone all above 0VDC which is in the range of the Arduino ADC otherwise the arduino will capture only those above 0VDC.

How do I detect if the computer is playing any sound?

I want to programmatically detect if a (local) computer (not mobile device) is playing any sound or music. Preferably via some high level api from Java or Python or a similar language.
I have never done it, but as a first approach I would open (open as input, not output) a fake recording stream on the master windows playback lineout device (instead the normal use of opening the mic or linein device for recording).
I would then monitor the captured frames. If for a certain time there are values over some small threshold, I would infer there is sound.

With Python/PySide/PyQt/Phonon how to control a USB Soundcards output sample clock rate?

I am trying to O/P audio to a USB soundcard (Lindy PnP SoundCard device) via Python/PySide/PyQT by the use of Phonon and/or QTMultimedia.
I can O/P the aduio (mp3/wav) which is no problem - the issue is that I want to control the USB's output sample clock rate, I need to be able to change this from 44.1 to 48 kHz. The soundcard comes with its own s/w that allows this so it is possible.
I can play Audio through Phonon like so..
self.mediaObj=phonon.Phonon.MediaObject(self)
self.audioSink=Phonon.AudioOutput(Phonon.MusicCategory, self)
self.audioPath=Phonon.createPath(self.mediaObj, self.audioSink)
self.audioSink.setVolume(0.3)
However I do not see any way to change the sample clock rate of the USB device from looking at the Class Reference doc's it seems its not possible.
http://www.pyside.org/docs/pyside/PySide/phonon/index.html
So then I have tried to use Qt Multimedia to change the USB soundcards O/P clock rate..
format = QtMultimedia.QAudioFormat()
format.setChannels(2)
format.setFrequency(44100)
format.setSampleSize(16)
format.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
format.setSampleType(QtMultimedia.QAudioFormat.SignedInt)
This has no effect. Does anyone know how I would do this and if it is even possible with Phonon/PyQT? I am guessing I need to go lower and try find the USB Soundcard directly which will be messy..
Much appeciate any help!!
Alan

Resources