Enhance VoiceBot to support AIBot integration for dynamic TTS script generation

This commit is contained in:
Edgar P. Burkhart 2025-03-22 23:21:07 +01:00
parent e6fc040d78
commit 31f10b8438
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 15 additions and 8 deletions

View file

@ -59,7 +59,7 @@ def main() -> None:
text_bot = TextBot(bot, wl, aibot=aibot, shuffler=shf)
text_bot.init_events()
voice_bot = VoiceBot(bot, cambai, shuffler=shf)
voice_bot = VoiceBot(bot, cambai, aibot=aibot, shuffler=shf)
voice_bot.init_events()
@bot.listen("on_ready")

View file

@ -3,6 +3,7 @@ import random
import discord
from botbotbot.ai import AIBot
from botbotbot.shuffle import Shuffler
from botbotbot.tts import CambAI
@ -14,11 +15,13 @@ class VoiceBot:
self,
bot: discord.Bot,
cambai: CambAI | None = None,
aibot: AIBot | None = None,
shuffler: Shuffler | None = None,
) -> None:
self.bot = bot
self.cambai = cambai
self.shf = shuffler
self.aibot = aibot
def init_events(self) -> None:
self.bot.add_listener(self.on_voice_state_update, "on_voice_state_update")
@ -45,13 +48,17 @@ class VoiceBot:
and random.random() < 5 / 100
):
logger.info("Generating tts")
script = random.choice(
[
"Salut la jeunesse !",
f"Salut {member.display_name}, ça va bien ?",
"Allo ? À l'huile !",
]
)
script = None
if self.aibot is not None and random.random() < 20 / 100:
script = self.aibot.answer("Dis un truc aléatoire et original.")
if script is None:
script = random.choice(
[
"Salut la jeunesse !",
f"Salut {member.display_name}, ça va bien ?",
"Allo ? À l'huile !",
]
)
source = await discord.FFmpegOpusAudio.from_probe(self.cambai.tts(script))
vo: discord.VoiceClient = await after.channel.connect()