У меня работает так:
1. Авторизация:
import requests
url = 'https://texttospeech.ru/api/v1/login'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0',
'Content-Type': 'text/plain;charset=UTF-8',
}
data = {"email": "sample@email.com", "pass": "password", "captcha": ""}
session = requests.Session()
response = session.post(url, json=data)
print(response.text)
2. Код для генерации mp3 из текста:
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0',
'Content-Type': 'text/plain;charset=UTF-8',
}
def get_token() -> str:
url = 'https://texttospeech.ru/api/v1/login'
data = {"email": "sample@email.com", "pass": "password", "captcha": ""}
with requests.Session() as session:
response = session.post(url, headers=headers, json=data)
token = response.json().get('data').get('token')
return token
headers['token'] = get_token()
def synthesize(text: str) -> None:
url = 'https://texttospeech.ru/api/v1/synthesize'
data = {"rate": "0", "pitch": "0", "volume": "0", "hertz": "0", "shift": "0", "echo": "0",
"text": f'{text}',
"code": "ru-RU009",
"format": "mp3"}
with requests.Session() as session:
response = session.post(url, headers=headers, json=data)
if response.status_code == 200:
print(response.json().get('message'))
filelink = response.json().get('data').get('filelink')
with open(f'{text[0:10]}.mp3', 'wb') as file:
response = session.get(f'https://texttospeech.ru/{filelink}', headers=headers)
file.write(response.content)
else:
print(response.text)
synthesize('Привет мир')