Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 10 May, 2020

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.

     Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

    To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

    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’]

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!