[英]How can I get the microphone input in python?
I want to make a Python program where microphone audio input is received.我想制作一个接收麦克风音频输入的 Python 程序。
I already tried pyaudio but I can't understand how it works.我已经尝试过 pyaudio,但我不明白它是如何工作的。
There is this module called gTTS
that you can use instead.您可以改用这个名为
gTTS
模块。
The
get_audio
function will be able to detect a users voice, translate the audio to text and return it to us.get_audio
函数将能够检测用户的声音,将音频转换为文本并将其返回给我们。 It will even wait until the user is speaking to start translating/recording the audio它甚至会等到用户说话才开始翻译/录制音频
Here's a complete example on Getting user input
using the get_audio
function.这是使用
get_audio
函数Getting user input
的完整示例。
def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio)
print(said)
except Exception as e:
print("Exception: " + str(e))
return said
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.