From 31df50369b1cc7e5105289ac00a2c439f905c323 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Wed, 17 Jul 2024 17:15:30 -0400 Subject: [PATCH] fix dependencies --- Dockerfile | 8 +++++--- docker-compose.yml | 4 ++++ main.py => point-virgule.py | 41 +++++++++++++++++++------------------ requirements.txt | 4 +++- 4 files changed, 33 insertions(+), 24 deletions(-) rename main.py => point-virgule.py (73%) diff --git a/Dockerfile b/Dockerfile index 4ddcded..ea8c6ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,10 @@ WORKDIR /app COPY . . -RUN pip install --no-cache-dir -r requirements.txt +RUN apt-get update && \ + apt-get install -y ffmpeg && \ + pip install --no-cache-dir -r requirements.txt -ENV RECORDING_PATH=./recordings +EXPOSE 80 -CMD ["python", "main.py"] +CMD ["python", "point-virgule.py"] diff --git a/docker-compose.yml b/docker-compose.yml index 2cb633f..08faa21 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,10 @@ services: container_name: point-virgule env_file: - .env + ports: + - "80:80" + volumes: + - ./recordings:/app/recordings networks: - point-virgule diff --git a/main.py b/point-virgule.py similarity index 73% rename from main.py rename to point-virgule.py index a34fff6..ef5eeef 100644 --- a/main.py +++ b/point-virgule.py @@ -6,14 +6,15 @@ from interactions import slash_command, GuildVoice, OptionType, SlashContext, ChannelType, slash_option, Client logging.basicConfig(level=logging.INFO) -logger = logging.getLogger(__name__) +logger = logging.getLogger("Point-Virgule") class RecorderBot(Client): - def __init__(self, recording_path: str, api_url: str, *args, **kwargs): + def __init__(self, recording_path: str, point_url: str, *args, **kwargs): super().__init__(*args, **kwargs) self.recording_path = recording_path - self.point_url = api_url + self.point_url = point_url self.active_recordings = {} + self.recording_states = {} @slash_command(name="start_meeting", description="Commencer l'enregistrement d'une réunion") @slash_option( @@ -26,40 +27,40 @@ def __init__(self, recording_path: str, api_url: str, *args, **kwargs): async def start_meeting(self, ctx: SlashContext, channel: GuildVoice): await ctx.send("Connexion au canal vocal...") voice_state = await channel.connect() - await ctx.send("Enregistrement démarré.") + await voice_state.start_recording() self.active_recordings[ctx.guild_id] = voice_state - await ctx.send("Utilisez `/stop_meeting` pour arrêter l'enregistrement et déconnecter.") + self.recording_states[ctx.guild_id] = True + await ctx.send("Enregistrement démarré. Utilisez `/stop_meeting` pour arrêter l'enregistrement et déconnecter.") logger.info(f"Enregistrement démarré dans la guilde: {ctx.guild_id}") - @slash_command(name="stop_meeting", description="Arrêter l'enregistrement d'une réunion") async def stop_meeting(self, ctx: SlashContext): - if ctx.guild_id in self.active_recordings: - channel = self.active_recordings[ctx.guild_id] + if ctx.guild_id in self.active_recordings and self.recording_states.get(ctx.guild_id, False): + voice_state = self.active_recordings[ctx.guild_id] await ctx.send("Déconnexion du canal vocal...") - await ctx.voice_state.stop_recording() - await channel.disconnect() - file_path = self.save_audio(ctx) + await voice_state.stop_recording() + await voice_state.disconnect() + file_path = self.save_audio(ctx, voice_state) del self.active_recordings[ctx.guild_id] + self.recording_states[ctx.guild_id] = False await ctx.send("Enregistrement arrêté. Envoi du fichier audio pour transcription...") logger.info(f"Enregistrement arrêté dans la guilde: {ctx.guild_id}") - + transcript = self.get_transcript(file_path) if transcript: await ctx.send(f"Transcription:\n{transcript}") logger.info(f"Transcription réussie: {transcript[:100]}") + self.delete_audio(file_path) else: await ctx.send("Erreur lors de la transcription de l'audio.") logger.error(f"Erreur lors de la transcription de l'audio pour la guilde {ctx.guild_id}") - - self.delete_audio(file_path) else: await ctx.send("Je n'enregistre pas dans ce serveur Discord.") logger.error(f"Enregistrement non trouvé pour la guilde {ctx.guild_id}") - def save_audio(self, ctx: SlashContext): - for user_id, audio_data in ctx.voice_state.recorder.output.items(): + def save_audio(self, ctx: SlashContext, voice_state): + for user_id, audio_data in voice_state.recorder.output.items(): timestamp = datetime.now().strftime("%Y%m%d%H%M%S") file_name = f"{user_id}_{timestamp}.mp3" file_path = os.path.join(self.recording_path, file_name) @@ -71,7 +72,7 @@ def save_audio(self, ctx: SlashContext): def get_transcript(self, file_path): try: with open(file_path, 'rb') as audio_file: - response = requests.post(self.api_url, files={'file': audio_file}, headers={'Content-Type': 'audio/mp3'}) + response = requests.post(self.point_url, files={'file': audio_file}, headers={'Content-Type': 'audio/mp3'}) if response.status_code == 200: logger.info(f"L'appel de l'API de transcription a réussi pour le fichier {file_path}") return response.text @@ -89,7 +90,7 @@ def delete_audio(self, file_path): load_dotenv() token = os.getenv("DISCORD_TOKEN") recording_path = os.getenv("RECORDING_PATH", "./recordings/") - api_url = os.getenv("TRANSCRIPTION_API_URL", "http://127.0.0.1:5000/transcript") - bot = RecorderBot(recording_path, api_url) - logger.info(f"{bot.user.name} démarré.") + point_url = os.getenv("TRANSCRIPTION_API_URL", "http://localhost:5000/transcript") + bot = RecorderBot(recording_path, point_url) + logger.info("démarrage du bot Discord...") bot.start(token) diff --git a/requirements.txt b/requirements.txt index 9cf2f88..e51453f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ -discord-py-interactions~=5.13.1 +discord-py-interactions +datetime python-dotenv +pynacl pydub requests \ No newline at end of file