Skip to content

Commit

Permalink
Feat: Only speak user custom name without id
Browse files Browse the repository at this point in the history
  • Loading branch information
whats2000 committed Oct 26, 2024
1 parent 991a79e commit feab2ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
12 changes: 11 additions & 1 deletion bot/events/message_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from utils.logger import logger
from config import TTS_TARGET_CHANNEL_ID, MESSAGE_BOT_TARGET_USER_ID


class MessageListener(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
Expand Down Expand Up @@ -92,7 +93,15 @@ async def on_message(self, message: disnake.Message):
for attempt in range(1, self.max_retries + 1):
try:
logger.info(f"Fetching TTS audio (attempt {attempt})...")
audio_data = text_to_speech(user_message, character_name)
# Remove the any (any text) the display name
player_name = member.display_name.replace(
re.search(r'\s\(.+?\)', member.display_name).group(),
''
)
audio_data = text_to_speech(
f'{player_name} 說: {user_message}',
character_name,
)
logger.info("Audio data fetched successfully")
logger.info(f"Audio data length: {len(audio_data)} bytes")

Expand All @@ -116,5 +125,6 @@ def after_playing(error):
logger.error("Failed to fetch TTS audio after multiple attempts.")
return


def setup(bot: commands.Bot):
bot.add_cog(MessageListener(bot))
5 changes: 4 additions & 1 deletion data/game_id_to_user_id.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"whats2000_": 495903741354967041,
"eason2005": 381351386975305730,
"monkey_Reachrs": 688181698822799414,
"FlandreLed": 1193230992354312203
"FlandreLed": 1193230992354312203,
"Zero_One_015645": 866858877928210445,
"BasedSinger5437": 854147624604139521
}
4 changes: 4 additions & 0 deletions data/sample_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"file": "雷電將軍.wav",
"text": "浮世景色百千年依旧,人之在世却如白露与泡影。虚无。"
},
"飛霄": {
"file": "飛霄.wav",
"text": "我曾追尋「流星」的方向,而後得到了自由。但「流星」落下的故地,卻已不見。"
},
"老簡": {
"file": "老簡.m4a",
"text": "云镇工艺为目前亚洲顶尖技术生存服务器之一,活跃于Minecraft原版环境下的技术研究。"
Expand Down
13 changes: 10 additions & 3 deletions data/user_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"user_settings": {
"495903741354967041": {
"selected_sample": "\u8349\u795e",
"tts_enabled": false
"tts_enabled": true,
"game_id": "whats2000_"
},
"667012201017638913": {
"selected_sample": "\u7b26\u7384"
Expand Down Expand Up @@ -77,11 +78,17 @@
"tts_enabled": false
},
"866858877928210445": {
"selected_sample": "\u53ef\u8389",
"tts_enabled": true
"selected_sample": "\u8349\u795e",
"tts_enabled": true,
"game_id": "Zero_One_015645"
},
"777398845486137344": {
"selected_sample": "\u96f7\u96fb\u5c07\u8ecd"
},
"854147624604139521": {
"game_id": "BasedSinger5437",
"selected_sample": "\u8349\u795e",
"tts_enabled": true
}
}
}

0 comments on commit feab2ec

Please sign in to comment.