from abc import ABC, abstractmethod from typing import Any, Dict, Optional import requests class AsrProcessor(ABC): @abstractmethod def call_recognise(self, file_path: str) -> Dict[str, Any]: """ Currently most important is field `transcript` with list of transcript words. """ pass class AsrWebClient(AsrProcessor): _url: str _auth_token: Optional[str] def __init__(self, url: str, auth_token: Optional[str]): super(AsrWebClient, self).__init__() self._url = url self._auth_token = auth_token def call_recognise(self, file_path: str) -> Dict[str, Any]: files = {"file": open(file_path, "rb")} headers = ( dict({"Authorization": f"Bearer {self._auth_token}"}) if self._auth_token is not None else dict() ) res = requests.post(self._url, files=files, headers=headers, timeout=600) json_response = res.json() print(json_response) return json_response