Wednesday, July 3, 2024
HomeLanguagesPythonList all the Microphones connected to System in Python using PyAudio and...

List all the Microphones connected to System in Python using PyAudio and SpeechRecognition

In this article, we are going to get the List ID and index of the microphones attached to the system. One should have knowledge about microphone ID while dealing with microphones in the Python programs. So in order to get the list of microphones attached to the system we need the following Libraries.

  • Speechrecognition
  • PyAudio

Installation

  • SpeechRecognition: This module does not comes built-in with Python. There are two ways to install this module.
    1) Type the below command in the terminal.

    pip install SpeechRecognition

    2) Download resources from PyPI and extract it in a folder and then run following command in cmd or terminal.

    python setup.py install
  • PyAudio:
    1) Windows: Run the following command in the CMD.

    pip install pyaudio

    2) Linux: Run the following command in the terminal.

    sudo apt-get install python-pyaudio python3-pyaudio

Listing all the microphones connected

First of all import speechrecognition instance as ‘sr’

import speech_recognition as sr

Now list_microphone_names() method will return a array/list of the connected microphones to the system.

sr.Microphone.list_microphone_names()

Complete Code:




import speechrecognition as sr
  
  
print(sr.Microphone.list_microphone_names())


Output:

[‘HDA Intel PCH: ALC255 Analog (hw:0, 0)’, ‘HDA Intel PCH: HDMI 0 (hw:0, 3)’, ‘HDA Intel PCH: HDMI 1 (hw:0, 7)’, ‘HDA Intel PCH: HDMI 2 (hw:0, 8)’, ‘HDA Intel PCH: HDMI 3 (hw:0, 9)’, ‘HDA Intel PCH: HDMI 4 (hw:0, 10)’, ‘sysdefault’, ‘front’, ‘surround40’, ‘surround51’, ‘surround71’, ‘hdmi’, ‘pulse’, ‘dmix’, ‘default’]

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments