我使用SpeechRecognition Python包来获取用户的音频。
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
执行此代码时,会开始侦听用户输入的音频。如果用户暂时不说话,它会自动停止。
答案 0 :(得分:0)
我认为你需要阅读library specifications;那么,您可以检查使用记录方法而不是 listen 方法比您的应用程序更可取。
答案 1 :(得分:0)
with
时,录制会停止。您可以在with
之后打印一些内容,以了解记录已停止。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)