删除用不上的配置参数

This commit is contained in:
涵曦 2024-06-24 00:45:41 +00:00
parent 40bd099153
commit 8699938b61
3 changed files with 10 additions and 82 deletions

View File

@ -27,20 +27,6 @@ def main():
dest="cookie", dest="cookie",
help="xiaomi cookie", help="xiaomi cookie",
) )
parser.add_argument(
"--use_command",
dest="use_command",
action="store_true",
default=None,
help="use command to tts",
)
parser.add_argument(
"--mute_xiaoai",
dest="mute_xiaoai",
action="store_true",
default=None,
help="try to mute xiaoai answer",
)
parser.add_argument( parser.add_argument(
"--verbose", "--verbose",
dest="verbose", dest="verbose",

View File

@ -9,28 +9,6 @@ from xiaomusic.utils import validate_proxy
LATEST_ASK_API = "https://userprofile.mina.mi.com/device_profile/v2/conversation?source=dialogu&hardware={hardware}&timestamp={timestamp}&limit=2" LATEST_ASK_API = "https://userprofile.mina.mi.com/device_profile/v2/conversation?source=dialogu&hardware={hardware}&timestamp={timestamp}&limit=2"
COOKIE_TEMPLATE = "deviceId={device_id}; serviceToken={service_token}; userId={user_id}" COOKIE_TEMPLATE = "deviceId={device_id}; serviceToken={service_token}; userId={user_id}"
HARDWARE_COMMAND_DICT = {
# hardware: (tts_command, wakeup_command, volume_command)
"LX06": ("5-1", "5-5", "2-1"),
"L05B": ("5-3", "5-4", "2-1"),
"S12": ("5-1", "5-5", "2-1"), # 第一代小爱型号MDZ-25-DA
"S12A": ("5-1", "5-5", "2-1"),
"LX01": ("5-1", "5-5", "2-1"),
"L06A": ("5-1", "5-5", "2-1"),
"LX04": ("5-1", "5-4", "2-1"),
"L05C": ("5-3", "5-4", "2-1"),
"L17A": ("7-3", "7-4", "2-1"),
"X08E": ("7-3", "7-4", "2-1"),
"LX05A": ("5-1", "5-5", "2-1"), # 小爱红外版
"LX5A": ("5-1", "5-5", "2-1"), # 小爱红外版
"L07A": ("5-1", "5-5", "2-1"), # Redmi小爱音箱Play(l7a)
"L15A": ("7-3", "7-4", "2-1"),
"X6A": ("7-3", "7-4", "2-1"), # 小米智能家庭屏6
"X10A": ("7-3", "7-4", "2-1"), # 小米智能家庭屏10
# add more here
}
DEFAULT_COMMAND = ("5-1", "5-5", "2-1")
KEY_WORD_DICT = { KEY_WORD_DICT = {
"播放歌曲": "play", "播放歌曲": "play",
@ -83,9 +61,7 @@ class Config:
account: str = os.getenv("MI_USER", "") account: str = os.getenv("MI_USER", "")
password: str = os.getenv("MI_PASS", "") password: str = os.getenv("MI_PASS", "")
mi_did: str = os.getenv("MI_DID", "") mi_did: str = os.getenv("MI_DID", "")
mute_xiaoai: bool = True
cookie: str = "" cookie: str = ""
use_command: bool = False
verbose: bool = os.getenv("XIAOMUSIC_VERBOSE", "").lower() == "true" verbose: bool = os.getenv("XIAOMUSIC_VERBOSE", "").lower() == "true"
music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music") music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music")
conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", None) conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", None)
@ -109,18 +85,6 @@ class Config:
if self.proxy: if self.proxy:
validate_proxy(self.proxy) validate_proxy(self.proxy)
@property
def tts_command(self) -> str:
return HARDWARE_COMMAND_DICT.get(self.hardware, DEFAULT_COMMAND)[0]
@property
def wakeup_command(self) -> str:
return HARDWARE_COMMAND_DICT.get(self.hardware, DEFAULT_COMMAND)[1]
@property
def volume_command(self) -> str:
return HARDWARE_COMMAND_DICT.get(self.hardware, DEFAULT_COMMAND)[2]
@classmethod @classmethod
def from_options(cls, options: argparse.Namespace) -> Config: def from_options(cls, options: argparse.Namespace) -> Config:
config = {} config = {}

View File

@ -13,7 +13,7 @@ from pathlib import Path
import mutagen import mutagen
from aiohttp import ClientSession, ClientTimeout from aiohttp import ClientSession, ClientTimeout
from miservice import MiAccount, MiIOService, MiNAService, miio_command from miservice import MiAccount, MiIOService, MiNAService
from xiaomusic import ( from xiaomusic import (
__version__, __version__,
@ -253,42 +253,20 @@ class XiaoMusic:
async def do_tts(self, value): async def do_tts(self, value):
self.log.info("do_tts: %s", value) self.log.info("do_tts: %s", value)
if self.config.mute_xiaoai:
await self.force_stop_xiaoai() await self.force_stop_xiaoai()
else:
# waiting for xiaoai speaker done
await asyncio.sleep(8)
if not self.config.use_command:
try: try:
await self.mina_service.text_to_speech(self.device_id, value) await self.mina_service.text_to_speech(self.device_id, value)
except Exception: except Exception:
pass pass
else:
await miio_command(
self.miio_service,
self.config.mi_did,
f"{self.config.tts_command} {value}",
)
async def do_set_volume(self, value): async def do_set_volume(self, value):
value = int(value) value = int(value)
self._volume = value self._volume = value
self.log.info(f"声音设置为{value}") self.log.info(f"声音设置为{value}")
if not self.config.use_command:
try: try:
self.log.debug("do_set_volume not use_command value:%d", value)
await self.mina_service.player_set_volume(self.device_id, value) await self.mina_service.player_set_volume(self.device_id, value)
except Exception: except Exception:
pass pass
else:
self.log.debug("do_set_volume use_command value:%d", value)
await miio_command(
self.miio_service,
self.config.mi_did,
f"{self.config.volume_command}=#{value}",
)
async def force_stop_xiaoai(self): async def force_stop_xiaoai(self):
await self.mina_service.player_stop(self.device_id) await self.mina_service.player_stop(self.device_id)