# import xml.etree.ElementTree as XmlElementTree
# import httplib2
# import uuid
# # импорт нативных библиотек
# from config import ** *
# # импорт конфига
#
# ** *_HOST = '***'
# ** *_PATH = '/***_xml'
# CHUNK_SIZE = 1024 ** 2
#
#
# # ?
#
# def speech_to_text(filename=None, bytes=None, request_id=uuid.uuid4().hex, topic='notes', lang='ru-RU',
# key=** * _API_KEY):
# if filename:
# with open(filename, 'br') as file:
# bytes = file.read()
# if not bytes:
# raise Exception('Neither file name nor bytes provided.')
#
# bytes = convert_to_pcm16b16000r(in_bytes=bytes)
#
# url = ** *_PATH + '?uuid=%s&key=%s&topic=%s&lang=%s' % (
# request_id,
# key,
# topic,
# lang
# )
# # метод обработки файла
#
# chunks = read_chunks(CHUNK_SIZE, bytes)
#
# connection = httplib2.HTTPConnectionWithTimeout(***_HOST)
# # подключение к страницы для передачи заголовка
# connection.connect()
# connection.putrequest('POST', url)
# connection.putheader('Transfer-Encoding', 'chunked')
# connection.putheader('Content-Type', 'audio/x-pcm;bit=16;rate=16000')
# connection.endheaders()
#
# for chunk in chunks:
# connection.send(('%s\r\n' % hex(len(chunk))[2:]).encode())
# connection.send(chunk)
# connection.send('\r\n'.encode())
#
# connection.send('0\r\n\r\n'.encode())
# response = connection.getresponse()
# # отправка и получение ответа
#
# if response.code == 200:
# response_text = response.read()
# xml = XmlElementTree.fromstring(response_text)
# # ?
# if int(xml.attrib['success']) == 1:
# max_confidence = - float("inf")
# text = ''
#
# for child in xml:
# if float(child.attrib['confidence']) > max_confidence:
# text = child.text
# max_confidence = float(child.attrib['confidence'])
#
# if max_confidence != - float("inf"):
# return text
# else:
#
# raise SpeechException('No text found.\n\nResponse:\n%s' % (response_text))
# else:
# raise SpeechException('No text found.\n\nResponse:\n%s' % (response_text))
# else:
# raise SpeechException('Unknown error.\nCode: %s\n\n%s' % (response.code, response.read()))
#
#
# сlass
# SpeechException(Exception):
# pass
def recv():
while True:
data = sock.recv(1024)
if data:
print('\n' + data.decode('utf-8'))
async def sender():
session = PromptSession()
while True:
try:
with patch_stdout():
message = await session.prompt_async('{}'.format(nickname) + ': ')
string = nickname + ': ' + message
sock.send(string.encode('utf-8'))
except socket.error:
pass
thread_reciev = threading.Thread(target=recv, name="reciev_message")
thread_reciev.start()
asyncio.get_event_loop().run_until_complete(sender())
command = '!скажи текст'
print(command[7:])
#текст
command2 = '!скажи много текста'
print(command2[7:])
#много текста
command = '!скажи текст'
print(command.split(' ')[1])
#текст
command = '!скажи текст'
print(command.replace('!скажи ',''))
#текст
command = '!скажи текст'
print((command[::-1][0:len(command[::-1])-7])[::-1])
#текст
import base64
command = '!скажи текст'
t = 'KGNvbW1hbmRbOjotMV1bMDpsZW4oY29tbWFuZFs6Oi0xXSktN10pWzo6LTFd'
print(eval(compile(base64.b64decode(t),'<string>', 'eval')))
#текст
from threading import Thread
def start_new_thread(function):
def decorator(*args, **kwargs):
t = Thread(target = function, args=args, kwargs=kwargs)
t.daemon = True
t.start()
return decorator
@start_new_thread
def we_are_sleep(args)
if body.lower() == "!кто":То
!кто сломалне сработает, ибо ты проверяешь строку на точное совпадение, коего не будет.Проверять надо так:
if "!кто" in body.lower():
...
body = "!кто сломал"
local = body.split(' ')
print(local)
########
["!кто", "сломал"]