fix: 解决 L05C 无提示音问题 support MiIOService tts (#198)

* support MiIOService tts

* Auto-format code 🧹🌟🤖

---------

Co-authored-by: Formatter [BOT] <runner@fv-az1773-635.5c5iphqueiuuvdxclnr0txjlua.dx.internal.cloudapp.net>
This commit is contained in:
Gao, Ruiyuan 2024-09-24 14:18:09 +08:00 committed by GitHub
parent 6e8830c4e6
commit 55b8b4e966
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 2 deletions

View File

@ -247,6 +247,7 @@ docker build -t xiaomusic .
- XIAOMUSIC_PUBLIC_PORT 用于设置外网端口,对应后台的 【外网访问端口】当使用反向代理时可以设置为外网端口XIAOMUSIC_HOSTNAME 设为外网IP或者域名即可。
- XIAOMUSIC_DOWNLOAD_PATH 变量可以配置下载目录,默认为空,表示使用 music 目录为下载目录,对应后台的 【音乐下载目录】。设置这个目录必须是 music 的子目录,否则刷新列表后会找不到歌曲。具体见 <https://github.com/hanxi/xiaomusic/issues/98>
- XIAOMUSIC_PROXY 用于配置国内使用 youtube 源下载歌曲时使用的代理,参数格式参考 yt-dlp 文档说明。 见 <https://github.com/hanxi/xiaomusic/issues/2><https://github.com/hanxi/xiaomusic/issues/11>
- MIIO_TTS_CMD 用于部分机型(如:`L05C`)使用 MiIO 支持 tts 能力,默认为空,命令选择见 [MiService-fork 文档](https://github.com/yihong0618/MiService)
### :warning: 安全提醒

View File

@ -2,6 +2,7 @@
"account": "",
"password": "",
"mi_did": "",
"miio_tts_command": null,
"cookie": "",
"verbose": false,
"music_path": "music",

View File

@ -77,6 +77,7 @@ class Config:
account: str = os.getenv("MI_USER", "")
password: str = os.getenv("MI_PASS", "")
mi_did: str = os.getenv("MI_DID", "") # 逗号分割支持多设备
miio_tts_command: str = os.getenv("MIIO_TTS_CMD", "")
cookie: str = ""
verbose: bool = os.getenv("XIAOMUSIC_VERBOSE", "").lower() == "true"
music_path: str = os.getenv(

View File

@ -110,6 +110,9 @@ var vConsole = new window.VConsole();
<option value="false" selected>false</option>
</select>
<label for="miio_tts_command">MiIO sst 指令:</label>
<input id="miio_tts_command" type="text" placeholder="如5 或者 5-3"></input>
<label for="disable_httpauth">关闭控制台密码验证:</label>
<select id="disable_httpauth">
<option value="true" selected>true</option>

View File

@ -15,7 +15,7 @@ from logging.handlers import RotatingFileHandler
from pathlib import Path
from aiohttp import ClientSession, ClientTimeout
from miservice import MiAccount, MiNAService
from miservice import MiAccount, MiIOService, MiNAService, miio_command
from xiaomusic import __version__
from xiaomusic.analytics import Analytics
@ -64,6 +64,7 @@ class XiaoMusic:
self.last_record = None
self.cookie_jar = None
self.mina_service = None
self.miio_service = None
self.polling_event = asyncio.Event()
self.new_record_event = asyncio.Event()
@ -215,6 +216,7 @@ class XiaoMusic:
# Forced login to refresh to refresh token
await account.login("micoapi")
self.mina_service = MiNAService(account)
self.miio_service = MiIOService(account)
async def try_update_device_id(self):
try:
@ -1129,6 +1131,10 @@ class XiaoMusicDevice:
self._last_cmd = None
self.update_playlist()
@property
def did(self):
return self.xiaomusic.device_id_did[self.device_id]
def get_cur_music(self):
return self.device.cur_music
@ -1504,7 +1510,17 @@ class XiaoMusicDevice:
async def text_to_speech(self, value):
try:
if not self.config.miio_tts_command:
self.log.debug("Call MiNAService tts.")
await self.xiaomusic.mina_service.text_to_speech(self.device_id, value)
else:
self.log.debug("Call MiIOService tts.")
value = value.replace(" ", ",") # 不能有空格
await miio_command(
self.xiaomusic.miio_service,
self.did,
f"{self.config.miio_tts_command} {value}",
)
except Exception as e:
self.log.exception(f"Execption {e}")
@ -1640,6 +1656,7 @@ class XiaoMusicDevice:
self._playing = False
if arg1 != "notts":
await self.do_tts(self.config.stop_tts_msg)
await asyncio.sleep(3) # 等它说完
# 取消组内所有的下一首歌曲的定时器
self.cancel_group_next_timer()
await self.group_force_stop_xiaoai()