import requests
from bs4 import BeautifulSoup
UNDEFINED_STRING='undefined'
KEY = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX'
#UUID можно любой (01ae13cb744628b58fb536d496daa1e6)
UUID='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
url = 'https://asr.yandex.net/asr_xml?key=' + KEY + '&uuid=' + UUID + '&topic=queries&lang=ru-RU'
headers = {"Content-Type": 'audio/x-mpeg-3'}
#файл распознования
data = open ('test.mp3', 'rb')
response = requests.post(url, headers=headers, data=data)
soup = BeautifulSoup(response.text, 'html.parser')
#soup.variant
result=UNDEFINED_STRING
answers=soup.findAll('variant')
if(len(answers)>0):
result=answers[0].text
else:
print(UNDEFINED_STRING)