语音识别

1,下载依赖包

    pip install SpeechRecognition
    pip install pyaudio

2,代码

import speech_recognition as sr

r = sr.Recognizer()

# 方案一: 用音频文件
with sr.AudioFile(r'22.wav') as source:
    audio = r.record(source)

# # 方案一: 直接录音
# with sr.Microphone() as source:
#     audio = r.listen(source, 5)

text = r.recognize_google(audio, language='zh-CN')
print(text)
posted @ 2023-11-22 19:07  夜未央leo  阅读(96)  评论(0编辑  收藏  举报