Source code for langchain_community.tools.azure_ai_services.utils

import os
import tempfile
from urllib.parse import urlparse

import requests


[docs]def detect_file_src_type(file_path: str) -> str: """检测文件是本地的还是远程的。""" if os.path.isfile(file_path): return "local" parsed_url = urlparse(file_path) if parsed_url.scheme and parsed_url.netloc: return "remote" return "invalid"
[docs]def download_audio_from_url(audio_url: str) -> str: """从URL下载音频到本地。""" ext = audio_url.split(".")[-1] response = requests.get(audio_url, stream=True) response.raise_for_status() with tempfile.NamedTemporaryFile(mode="wb", suffix=f".{ext}", delete=False) as f: for chunk in response.iter_content(chunk_size=8192): f.write(chunk) return f.name