[docs]@staticmethoddefto_text(file_path:str,language:str="en")->"SpeechToTextResult":"""Speech to text using google cloud. Args: file_path (str): The path to the audio file to be transcribed into text. This should be a valid path to an audio file language (str, optional): the source language code of the audio file. Defaults to "en". Supported languages are: en, ar """withopen(file_path,"rb")asf:b=f.read()response=requests.post("https://api.devrio.org/api/v1/SpeechToText/",data={"language":language,},files={"file":b},)try:result=response.json()exceptExceptionase:raiseBaseException(str(e))ifnotresult["ok"]:raiseApiException(dumps(result["error"],indent=2,ensure_ascii=False))returnSpeechToTextResult.parse(result,file_path)
[docs]@staticmethodasyncdefto_text(file_path:str,language:str="en")->"SpeechToTextResult":"""Speech to text using google cloud. Args: file_path (str): The path to the audio file to be transcribed into text. This should be a valid path to an audio file language (str, optional): the source language code of the audio file. Defaults to "en". Supported languages are: en, ar """withopen(file_path,"rb")asf:b=f.read()asyncwithClientSession()assession:form=FormData()form.add_field("file",b,filename=os.path.basename(file_path))form.add_field("language",language)asyncwithsession.request("post","https://api.devrio.org/api/v1/SpeechToText/",data=form)asresponse:try:result=awaitresponse.json()exceptExceptionase:raiseBaseException(str(e))ifnotresult["ok"]:raiseApiException(dumps(result["error"],indent=2,ensure_ascii=False))returnSpeechToTextResult.parse(result,file_path)