-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (24 loc) · 1.05 KB
/
main.py
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
29
30
31
32
from telethon import TelegramClient, events
import os
from config import Config
import generator.voice_to_text as voice_to_text
download_path = 'downloads'
client = TelegramClient(Config.PHONE_NUMBER, Config.API_ID, Config.API_HASH)
@client.on(events.NewMessage)
async def handle_message(event: events.NewMessage.Event):
if event.message.voice and event.is_private:
print("Received a voice message!")
file = event.message.voice
# Define a filename
filename = f"voice_message_{event.message.id}.ogg"
filepath = os.path.join(download_path, filename)
# Download the file
await event.message.download_media(file=filepath)
text = voice_to_text.translate(filepath, event.message.sender.first_name)
await client.send_message(event.chat_id, text)
async def main():
await client.start(phone = Config.PHONE_NUMBER)
print("listening for new voice messages...")
await client.run_until_disconnected()
with client:
task = client.loop.run_until_complete(main())