-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspeech.py
More file actions
46 lines (43 loc) · 1.74 KB
/
speech.py
File metadata and controls
46 lines (43 loc) · 1.74 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
import os
from pyrogram import Client, filters
from command import fox_command, fox_sudo, who_message
from requirements_installer import install_library
install_library("gTTS")
from gtts import gTTS
@Client.on_message(fox_command("voice", "TextToVoice", os.path.basename(__file__), "[text]") & fox_sudo())
async def voice(client, message):
message = await who_message(client, message)
lang_code = os.environ.get("lang_code", "en")
rnd = random.randint(10000, 99999)
await message.delete()
text = message.text.split(None, 1)[1]
tts = gTTS(text, lang=lang_code)
tts.save(f"temp/voice{rnd}.mp3")
if message.reply_to_message:
await client.send_voice(
message.chat.id,
voice=f"temp/voice{rnd}.mp3",
reply_to_message_id=message.reply_to_message.id,
)
else:
await client.send_voice(message.chat.id, voice=f"temp/voice{rnd}.mp3")
os.remove(f"temp/voice{rnd}.mp3")
@Client.on_message(fox_command("voice_ru", "TextToVoice", os.path.basename(__file__), "[text]") & fox_sudo())
async def ru_voice(client, message):
message = await who_message(client, message)
lang_code = os.environ.get("lang_code", "ru")
rnd = random.randint(10000, 99999)
await message.delete()
text = message.text.split(None, 1)[1]
tts = gTTS(text, lang=lang_code)
tts.save(f"temp/voice{rnd}.mp3")
if message.reply_to_message:
await client.send_voice(
message.chat.id,
voice=f"temp/voice{rnd}.mp3",
reply_to_message_id=message.reply_to_message.id,
)
else:
await client.send_voice(message.chat.id, voice=f"temp/voice{rnd}.mp3")
os.remove(f"temp/voice{rnd}.mp3")