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
m.setvolume(newVol)

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 self._audio_interface.open().

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

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