how to detect that microphone is on or off in python 3 <p><strong>Its not duplicate</strong></p> <p>I have a python code that uses speech recognition and it has a problem when microphone is off so i want to add a code that closes python if microphone is off and if its not then runs the whole script.</p> <p><strong>for example:</strong></p> <pre><code>import speech_recognition as sr #if microphone is on : r = sr.Recognizer() with sr.Microphone() as source: audio = r.listen(source) try: said = r.recognize_google(audio) print(audio) except sr.UnknownValueError: print('google did not understand what you said') except sr.RequestError as e: print('errpr' + "; {0}".format(e)) #else print('please turn your microphone on and open again') quit() </code></pre> <p>any ideas how to do that?</p> <p><strong>Its not a duplicate question and it's completely a different question</strong></p> <p><a href="http://stackoverflow.com/questions/2797572/how-to-see-if-there-is-one-microphone-active-using-python">In this link</a> : we can detect that microphone is connected to pc or not , i wanna detect that microphone button is on or off.</p> <p>Actually my codes has this error that when my microphone is off and i run the code then i turn that on while code is still running , it will not recognize my voice , so i want to warn user to turn his microphone on then restart program.</p>