[Python] SpeechRecognition, AssertionError "Source must be an audio source"

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

  1. Stack

    Stack Membro Participativo

    Here is my code:

    import speech_recognition as sr

    r = sr.Recognizer()

    with sr.Microphone() as source:
    print('Say Something')
    audio = r.listen(source)
    voice_data = r.record(audio)
    print(voice_data)


    When I type "python main.py" on the terminal and start the program it starts to listen but doesn't get what I say. I've tried to use adjust_for_ambient_noise() instead of listen() but it also didn't change anything.

    I'm using macOS Catalina and Python 3.8.1.

    This is the error I get:

    Traceback (most recent call last):
    File "main.py", line 8, in <module>
    voice_data = r.record(audio)
    File "/Users/sefailyasoz/PycharmProjects/SpeechAssistant/venv/lib/python3.8/site-packages/speech_recognition/__init__.py", line 483, in record
    assert isinstance(source, AudioSource), "Source must be an audio source"
    AssertionError: Source must be an audio source


    This is what I get when I use adjust_for_ambient_noise(), if I use listen, it doesn't end, it just listens, I end it with Ctrl+C.

    Continue reading...

Compartilhe esta Página