import requests class Converter: """ Этот класс выполняет главную функцию, конвертирует голос в текст """ def __init__(self, path_to_file: str, message, model, language: str = "ru-RU"): self.language = language self.path_to_file = path_to_file self.service = None self.message = message self.model = model def audio_to_text(self) -> str: """ Основная функция :return: str - текст + служебная информация """ try: r = requests.get("http://192.168.0.108:5000/ping") if r.status_code == 200: response = requests.post( "http://192.168.0.108:5000/decrypt_audio", files={"file": open(self.path_to_file, "rb").read()}, timeout=6000 ) if response.status_code == 200: return response.json() else: return 'Не удалось получить текст.' else: result = self.model.transcribe(self.path_to_file) return result["text"] except requests.ConnectionError: result = self.model.transcribe(self.path_to_file) return result["text"]