How do i control when to stop the audio input?

后端 未结 2 2001
南方客
南方客 2021-01-28 15:22

I am using the SpeechRecognition Python package to get the audio from the user.

import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recogn         


        
相关标签:
2条回答
  • 2021-01-28 15:52

    I think you need to read the library specifications; then, you can check that using record method instead of listen method is preferable to your application.

    0 讨论(0)
  • 2021-01-28 15:52
    1. as the documentation specifies, recording stops when you exit out of with. you may print something after with to know that the recording has been stopped.
    2. here's how you can stop recording after 50 seconds.
    import speech_recognition as sr 
    recognizer = sr.Recognizer() 
    mic = sr.Microphone(device_index=1) 
    with mic as source:
        recognizer.adjust_for_ambient_noise(source)
        captured_audio = recognizer.record(source=mic, duration=50)
    
    0 讨论(0)
提交回复
热议问题