diff --git a/speech_service/transcriber.py b/speech_service/transcriber.py index 0e197ba..8d873a1 100644 --- a/speech_service/transcriber.py +++ b/speech_service/transcriber.py @@ -12,5 +12,5 @@ class WhisperTranscriber: print("Whisper model loaded.") def transcribe(self, audio_file: str) -> str: - result = self.pipe(audio_file) + result = self.pipe(audio_file, return_timestamps=True) return result.get("text", "").strip() diff --git a/telegram_bot/handlers/audio_handler.py b/telegram_bot/handlers/audio_handler.py index 5698584..c25e205 100644 --- a/telegram_bot/handlers/audio_handler.py +++ b/telegram_bot/handlers/audio_handler.py @@ -51,10 +51,15 @@ async def handle_voice_and_video(message: types.Message, redis_service, storage_ message_id=message.message_id ) if text: - await message.reply(f"{text}") + await send_long_message(message, text) else: await message.reply("Sorry, transcription result was not received within the timeout.") +async def send_long_message(message: types.Message, text: str): + """Отправляет длинный текст, разбивая его на части по 4096 символов""" + chunk_size = 4096 + for i in range(0, len(text), chunk_size): + await message.reply(text[i : i + chunk_size]) def convert_to_wav(input_file: str, output_file: str): """