import speech_recognition as sr
# 创建一个识别器对象
recognizer = sr.Recognizer()
# 用语音文件创建一个音频文件对象
audio_file = "C:\\Users\\19406\Desktop\\75968.wav"
with sr.AudioFile(audio_file) as source:
audio = recognizer.record(source) # 读取音频文件
try:
# 使用Google Web Speech API进行语音识别
text = recognizer.recognize_google(audio, language='en-US')
print("识别结果:" + text)
except sr.UnknownValueError:
print("抱歉,无法识别")
except sr.RequestError:
print("抱歉,无法连接到API")
wav转文字 python
最新推荐文章于 2024-05-23 17:12:10 发布
文章介绍了如何在Python中使用`speech_recognition`库创建识别器对象,读取音频文件,并尝试通过GoogleWebSpeechAPI进行语音识别,处理可能的识别错误。
摘要由CSDN通过智能技术生成