语音识别
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)