简介:Python超简单语音识别
Python超简单语音识别
随着人工智能技术的不断发展,语音识别技术也日益成熟。Python作为一种流行的编程语言,有着丰富的语音识别库和工具,可以实现超简单的语音识别。本文将介绍如何使用Python进行超简单的语音识别,重点突出其中的重点词汇或短语。
pip install SpeechRecognition来安装这个库。
import speech_recognition as srr = sr.Recognizer()with sr.Microphone() as source:print("请说话...")audio = r.listen(source)
try:print("你说了: " + r.recognize_google(audio, language='zh-CN'))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))
if "打开" in result and "天气" in result:weater = "".join(filter(str.isalnum, result)) #过滤空格和标点符号,获取城市名称print("打开天气应用,查询" + weater + "的天气情况")os.system("xdg-openweathermap -c " + weater) #打开天气应用elif "退出" in result:print("退出")exit() #退出程序else:print("指令不正确")