Python
16
Вклад в тег
await bot.answer_callback_query(callback_query_id=cmd.id, text="Уведомление", show_alert=True)
await callback_query.answer("Уведомление", show_alert=True)
For this to work, your audio must be in an .OGG file encoded with OPUS
import subprocess
import io
def mp3_to_ogg(filename, path=''):
with open(f'{path}{filename}.mp3', 'rb') as input_file, open(f'{path}{filename}.ogg', 'wb') as output_file:
mp3_io = io.BytesIO(input_file.read())
ffmpeg_command = ['ffmpeg', '-i', 'pipe:0', '-c:a', 'libopus', '-f', 'ogg', 'pipe:1']
result = subprocess.run(ffmpeg_command, input=mp3_io.read(), capture_output=True)
ogg_bytes = result.stdout
output_file.write(ogg_bytes)
import string
def is_russian(text):
alpha = "абвгдеёжзиклмнопрстуфхцчшщъыьэюя"
new_text = text.translate(str.maketrans('', '', string.punctuation)).lower().replace(' ', '')
rulet = 0
for letter in new_text:
if letter in alpha:
rulet += 1
# Если больше или равно 70%
if rulet/len(new_text) >= 0.7:
return(True)
else:
return(False)
good_text = "Какой-то текст, со знаками препинания, конечно же, sorry!"
bad_text = "Some english text, isn't russian."
secret = "Люблю Gucci"
print(is_russian(good_text)) #вернёт True
print(is_russian(bad_text)) #вернёт False
print(is_russian(secret)) #вернёт False