File size: 721 Bytes
0945533
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import telebot
import whisper
import os

TOKEN = "8514932008:AAGX3GyNd-9t8GBEYHm7JYfEZlztxAJvr4A"

bot = telebot.TeleBot(TOKEN)

model = whisper.load_model("medium")

@bot.message_handler(content_types=['audio','voice','video','document'])
def handle_file(message):

    file_info = bot.get_file(message.document.file_id if message.document else message.video.file_id)
    downloaded = bot.download_file(file_info.file_path)

    file_name = "input_file"
    with open(file_name, "wb") as f:
        f.write(downloaded)

    result = model.transcribe(file_name)

    with open("output.srt","w") as f:
        f.write(result["text"])

    bot.send_document(message.chat.id, open("output.srt","rb"))

bot.infinity_polling()