Python 智能语音识别的功能

python 复制代码
import speech_recognition as sr

def voice_recognition():
    # 创建语音识别对象
    r = sr.Recognizer()
    # 从麦克风中获取音频
    with sr.Microphone() as source:
        print("Please speak...")
        audio = r.listen(source)
    try:
        # 使用 Google Speech Recognition API 进行识别
        text = r.recognize_google(audio, language='zh-CN')
        print("You said: ", text)
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))
相关推荐
Black蜡笔小新几秒前
自动化AI算法训练服务器DLTM训推一体化平台助力农业生产管理实现安全智能化
人工智能·算法·自动化
米小虾4 分钟前
Claude Code、Codex、Cursor三分天下:2026年AI编程Agent生态全景剖析
人工智能·agent
ZHW_AI课题组19 分钟前
腾讯云调用IP定位
人工智能·python·机器学习
Wch1G0z8A31 分钟前
Google 开源了啥,让 AI Agent 碰数据库不再是定时炸弹
数据库·人工智能·开源
武子康32 分钟前
调查研究-151 Slack vs Jira:区别、使用指南与团队选择方法
人工智能·科技·深度学习·ai·职场和发展·jira·slack
米小虾34 分钟前
黄仁勋GTC 2026宣告Agent AI时代:从生成式到代理式的范式转移
人工智能·aigc·agent
IT_陈寒35 分钟前
Python闭包里藏的这个坑,差点让我加班到凌晨
前端·人工智能·后端
IT_陈寒35 分钟前
Java注解空指针?这个坑我踩得莫名其妙
前端·人工智能·后端
zhaoshuzhaoshu35 分钟前
Python文件操作详细解析带例子
python