小爱音箱pro接入gpt和语音控制电脑

 系统环境win7,python3.11

先安装MiService,使用:GitHub - Yonsm/MiService: XiaoMi Cloud Service for mi.com这个安装没成功,

改用:GitHub - yihong0618/MiService: XiaoMi Cloud Service for mi.com

在终端使用变量,

Mac OS 或 Linux 下:

export MI_USER=
export MI_PASS=

Windows下:

set MI_USER=
set MI_PASS=

然后自己写了个bat控制小爱:

播放文字语音:

@echo off

set MI_USER=***
set MI_PASS=***
set MI_DID=***
set OPENAI_API_KEY=***
set API_BASE=https://***/v1

:start
set /P _new="请输入要问的,默认是你好:"
if "%_new%" == "" (set _new=你好)
micli 5 %_new%
goto start
pause
exit

执行动作

@echo off

set MI_USER=***
set MI_PASS=***
set MI_DID=***
set OPENAI_API_KEY=***
set API_BASE=https://***/v1

:start
set /P _new="请输入要问的,默认是明天的天气:"
if "%_new%" == "" (set _new=明天的天气)
micli 5-5 %_new% #0
goto start
pause
exit

 播放控制

@echo off

set MI_USER=***
set MI_PASS=***
set MI_DID=***
set OPENAI_API_KEY=***
set API_BASE=https://***/v1

:start
set /P _new="请输入 1.播放(默认) 2.暂停 3.下一首 4.上一首:"
if "%_new%" == "" (set _new=1)
if "%_new%" == "1" micli 5-5 播放 #0
if "%_new%" == "2" micli 5-5 暂停 #0
if "%_new%" == "3" micli 5-5 下一首 #0
if "%_new%" == "4" micli 5-5 上一首 #0
goto start
pause
exit

然后再安装:GitHub - yihong0618/xiaogpt: Play ChatGPT and other LLM with Xiaomi AI Speaker

增加讯飞星火接口:xiaogpt\bot\xinghuo_bot.py

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
from sparkdesk_web.core import SparkWeb
from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin

class XinghuoBot(ChatHistoryMixin, BaseBot):
    name = "讯飞星火"
    def __init__(self, xhconf=None) -> None:
        self.history = []
        self._sparkWeb = SparkWeb(
            cookie="***",
            fd="***",
            GtToken="***",
        )
        self._bot = self._sparkWeb.create_continuous_chat()
       

    @classmethod
    def from_config(cls, config):
        return cls(xhconf=config)

    async def ask(self, query, **options):
        try:
            answer = self._bot.chat(query)
        except Exception as e:
            print(str(e))
        return str(answer).replace(" ", "~").replace("\n", "~")

    def ask_stream(self, query: str, **options):
        raise Exception("GLM do not support stream")

run给小爱接入GPT.bat

@echo off

set MI_USER=***
set MI_PASS=***
set MI_DID=***

set OPENAI_API_KEY=***
set API_BASE=https://***/v1

python xiaogpt.py --hardware LX06  --mute_xiaoai

rem 接入讯飞星火
rem python xiaogpt.py --hardware LX06  --mute_xiaoai --use_xinghuo --tts edge

语音控制电脑:

修改xiaogpt\xiaogpt.py,增加控制命令关键词:打开微信、关闭微信、电脑声音大一点...

剩下的大家自由发挥,也可以对接微信机器人,用语音给好友发送信息等等...

你可能感兴趣的:(硬件,Python,家电,gpt)