'python speech recognition library / pyaudio: refresh list of mics
hi this is my first post so i will try my best to explain what i need.
My problem is that i'm using a specific mic that might disconnect at any time if so i need it to connect to my pc's mic. here is the code
mic = None
for i in sr.Microphone.list_microphone_names():
print(i)
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
if str(name) == "Microphone (Blue Snowball)":
print("\n\n\n\n\n")
mic = sr.Microphone(sample_rate = 18000, device_index= index)
print("using Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
print(mic)
if mic == None:
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
if str(name) == "Microphone (Realtek High Defini":
print("\n\n\n\n\n")
mic = sr.Microphone(sample_rate = 18000, device_index= index)
print("using Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
print(mic)
print(mic)
the code above is ran 1 every 5 seconds or so
now the problem is when i disconnect the mic it still says it there
it seems like the sr.Microphone.list_microphone_names()get the all the audio devices when the program starts then during operation when it is called again it does not update that list it just retrieves this list that was made at the start.
now i need a way to either update this list or see which mics are operational. i know pyaudio does see this mic is missing cause the device indexes changes but it does not update the list
thanks from sir snibbles
p.s i have research this for 4 hours and i don't have any experience with pyaudio
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
