Skip to content

Commit

Permalink
删除用不上的配置参数
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jun 24, 2024
1 parent 40bd099 commit 8699938
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 82 deletions.
14 changes: 0 additions & 14 deletions xiaomusic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ def main():
dest="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(
"--verbose",
dest="verbose",
Expand Down
36 changes: 0 additions & 36 deletions xiaomusic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@

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}"
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 = {
"播放歌曲": "play",
Expand Down Expand Up @@ -83,9 +61,7 @@ class Config:
account: str = os.getenv("MI_USER", "")
password: str = os.getenv("MI_PASS", "")
mi_did: str = os.getenv("MI_DID", "")
mute_xiaoai: bool = True
cookie: str = ""
use_command: bool = False
verbose: bool = os.getenv("XIAOMUSIC_VERBOSE", "").lower() == "true"
music_path: str = os.getenv("XIAOMUSIC_MUSIC_PATH", "music")
conf_path: str = os.getenv("XIAOMUSIC_CONF_PATH", None)
Expand All @@ -109,18 +85,6 @@ def __post_init__(self) -> None:
if 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
def from_options(cls, options: argparse.Namespace) -> Config:
config = {}
Expand Down
42 changes: 10 additions & 32 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import mutagen
from aiohttp import ClientSession, ClientTimeout
from miservice import MiAccount, MiIOService, MiNAService, miio_command
from miservice import MiAccount, MiIOService, MiNAService

from xiaomusic import (
__version__,
Expand Down Expand Up @@ -253,42 +253,20 @@ def set_last_record(self, query):

async def do_tts(self, value):
self.log.info("do_tts: %s", value)

if self.config.mute_xiaoai:
await self.force_stop_xiaoai()
else:
# waiting for xiaoai speaker done
await asyncio.sleep(8)

if not self.config.use_command:
try:
await self.mina_service.text_to_speech(self.device_id, value)
except Exception:
pass
else:
await miio_command(
self.miio_service,
self.config.mi_did,
f"{self.config.tts_command} {value}",
)
await self.force_stop_xiaoai()
try:
await self.mina_service.text_to_speech(self.device_id, value)
except Exception:
pass

async def do_set_volume(self, value):
value = int(value)
self._volume = value
self.log.info(f"声音设置为{value}")
if not self.config.use_command:
try:
self.log.debug("do_set_volume not use_command value:%d", value)
await self.mina_service.player_set_volume(self.device_id, value)
except Exception:
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}",
)
try:
await self.mina_service.player_set_volume(self.device_id, value)
except Exception:
pass

async def force_stop_xiaoai(self):
await self.mina_service.player_stop(self.device_id)
Expand Down

0 comments on commit 8699938

Please sign in to comment.