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

2023-12-20 02:05:55

?系统环境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=<Username>
export MI_PASS=<Password>

Windows下:

set MI_USER=<Username>
set MI_PASS=<Password>

然后自己写了个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,增加控制命令关键词:打开微信、关闭微信、电脑声音大一点...

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

文章来源:https://blog.csdn.net/yyws2039725/article/details/135087609
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。