[docs]defdetect_file_src_type(file_path:str)->str:"""Detect if the file is local or remote."""ifos.path.isfile(file_path):return"local"parsed_url=urlparse(file_path)ifparsed_url.schemeandparsed_url.netloc:return"remote"return"invalid"
[docs]defdownload_audio_from_url(audio_url:str)->str:"""Download audio from url to local."""ext=audio_url.split(".")[-1]response=requests.get(audio_url,stream=True)response.raise_for_status()withtempfile.NamedTemporaryFile(mode="wb",suffix=f".{ext}",delete=False)asf:forchunkinresponse.iter_content(chunk_size=8192):f.write(chunk)returnf.name