苹果、微软的ai电脑已经可以语音操控电脑了。开源的也有,下面是一个开源的python+openai api实现windows语音交互沟通,让ai人工智能识别你的命令进行电脑关机和其他操作,示例代码如下:
# -*- coding: utf-8 -*-
import speech_recognition as sr
import pyttsx3
import openai
import os
import sys
openai.api_key = "<your-api-key>"
# 创建 TTS 对象
engine = pyttsx3.init()
# 创建 Recognizer 对象
r = sr.Recognizer()
def getopenairesponse(keyword):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=keyword,
max_tokens=1024,
temperature=0.5
)
return response["choices"][0]["text"]
def listen_for_wake_word():
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("等待唤醒词...")
audio = r.listen(source)
try:
text = r.recognize_sphinx(audio, language='zh-CN')
return text.lower()
except:
return ""
def shutdown_computer():
print("电脑即将关机")
engine.say("电脑即将关机")
engine.runAndWait()
if sys.platform == "win32":
os.system('shutdown /s /t 1')
else:
os.system('sudo shutdown -h now')
def restart_computer():
print("电脑即将重启")
engine.say("电脑即将重启")
engine.runAndWait()
if sys.platform == "win32":
os.system('shutdown /r /t 1')
else:
os.system('sudo reboot')
is_active = False
while True:
if not is_active:
wake_word = listen_for_wake_word()
if "开机" in wake_word:
is_active = True
print("系统已开启")
engine.say("系统已开启")
engine.runAndWait()
continue
# 使用麦克风录音
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source) # 噪音抑制
print("我在听,您请说:")
audio = r.listen(source)
# 将语音转成文本
try:
text = r.recognize_sphinx(audio, language='zh-CN')
print("你说的:" + text)
if "关闭系统" in text.lower():
is_active = False
print("系统已关闭")
engine.say("系统已关闭")
engine.runAndWait()
continue
elif "关机" in text.lower():
shutdown_computer()
break
elif "重启" in text.lower():
restart_computer()
break
# 将文字转成语音并播放
response = getopenairesponse(text)
engine.say(response)
engine.runAndWait()
except sr.UnknownValueError:
print("识别失败")
except 网友回复
视频大模型和最强文本大模型通过代码生成视频哪个性价比更高?
seedream5.5为啥无法将图白色背景修改成透明?
seedance2如何通过2张不同角度平视图来识别场景进行人物定位?
有没有免费的浏览器中离线运行的语音识别ai模型?
微信小程序个人版不交钱认证就不让你用二维码,报错"errcode":85411?
美丽国为啥要限制ai发展?
seedance2如何参考白模视频使用真实场景和人物生成新视频?
如何设定小孩看电视的时候每隔10分钟弹出一个题目,答对才能继续,答错继续下一题?
直播数字人根据公屏互动评论实时做出不用动作技术是什么?
未来ai文本大模型根据剧本直接生成像素风或三维白模或灰模粗糙场景动画html给视频大模型参考站位与运镜?


