Python Snippets

Set speaker volume

In your virtual environment, pip install pyalsaaudio.

import alsaaudio

m = alsaaudio.Mixer(control="MVC1", cardindex=0)
vol = m.getvolume()
vol = int(vol[0])

newVol = vol + 3

Stream audio to Google ASR

In your virtual environment, pip install pyaudio.

Follow examples on Github.

You can configure what microphone to use by adding an input_device_index in

To list the available devices with indices, use the following code.

import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):