如何制作一个仅Python依靠Python第三方库的听写程序

编程入门 行业动态 更新时间:2024-10-28 11:31:05

如何制作一个仅Python依靠Python<a href=https://www.elefans.com/category/jswz/34/1770258.html style=第三方库的听写程序"/>

如何制作一个仅Python依靠Python第三方库的听写程序

导入所需的库

import speech_recognition as sr

创建一个Recognizer对象

r = sr.Recognizer()

使用麦克风录音

with sr.Microphone() as source:print("Please speak your sentence:")audio = r.listen(source)

使用Google Speech Recognition进行语音识别

try:sentence = r.recognize_google(audio)print("You said: " + sentence)
except sr.UnknownValueError:print("Sorry, I could not understand what you said.")
except sr.RequestError as e:print("Could not request results from Google Speech Recognition service; {0}".format(e))

完整代码:

import speech_recognition as srr = sr.Recognizer()with sr.Microphone() as source:print("Please speak your sentence:")audio =

更多推荐

如何制作一个仅Python依靠Python第三方库的听写程序

本文发布于:2023-12-06 14:26:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1667860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第三方   程序   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!