[Python] Determine which microphone source to use for Azure Cognitive Services with Python

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    I've set up an instance of Azure Cognitive Services to listen on a microphone for a key phrase. This works fine, however I'm unable to tell it to listen to a specific microphone on my Apple Mac.

    The code I have is:

    mic_name = self.preferences.get('mic_name', None)
    self.audio_config = speechsdk.audio.AudioConfig(device_name=mic_name) if mic_name else None
    ...
    self.keyword_recognizer = speechsdk.KeywordRecognizer(audio_config=self.audio_config)


    Where I'm providing the microphone name as the device name to the speechsdk.audio.AudioConfig library. However from what I can read via https://aka.ms/csspeech/microphone-selection it seems I need to provide the device ID, not the name or index which is what pyaudio gives me.

    I've been searching online in an attempt to find a solution to getting the device ID, and the only thing I've been able to determine is that the pyobjc package might be needed in order to interact with the hardware via objective-c. Yet my attempts at that have also failed.

    Does anyone know of an existing library, or example I could reference, where a Python script is able to return the ID of a microphone device so I can provide it to the Speech Services SDK? (I also want this to work for windows, but that is a seperate matter)

    ===

    Update - to be clear, I need the user to be able to select the microphone they want to use from a dropdown, and then pass said Microphone ID through to the speechsdk.audio.AudioConfig library.

    Continue reading...

Compartilhe esta Página