Вот мой главный файл
import socket import yandex_pb2 model = yandex_pb2.ConnectionRequest() model.apiKey = "wefeww-wefwefwefwe-wefw-wef-we-fw-e" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('asr.yandex.net', 80)) header = ("GET /asr_partial HTTP/1.1\r\n" "User-Agent: KeepAliveClient\r\n" "Host: asr.yandex.net:80\r\n" "Upgrade: dictation\r\n\r\n") byte_head = header.encode() s.send(byte_head) message = model message_size = hex(len(message))[2:].encode() message_contoller = '\r\n'.encode() message_request = message.encode() s.send(message_size) s.send(message_contoller) s.send(message_request) data = s.recv(1000000) s.close()
Вот модель сообщения которую я потом превратил в класс yandex_pb2
use 'syntax = "proto2" message ConnectionRequest { optional int32 protocolVersion = 1 [default = 1]; required string speechkitVersion = 2; required string serviceName = 3; required string uuid = 4; required string apiKey = 5; required string applicationName = 6; required string device = 7; required string coords = 8; required string topic = 9; required string lang = 10; required string format =11; optional bool disableAntimatNormalizer = 18 [default = false]; optional AdvancedASROptions advancedASROptions = 19; } message AdvancedASROptions { optional bool partial_results = 1 [default = true]; optional string biometry = 24; }