From fce4e1d1b48f23cd8332e60afce3df8d6209a6a7 Mon Sep 17 00:00:00 2001
From: gaochangfeng <54253717+gaochangfeng@users.noreply.github.com>
Date: 星期四, 11 四月 2024 14:59:22 +0800
Subject: [PATCH] SenseVoice对富文本解码的参数 (#1608)
---
funasr/download/file.py | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/funasr/download/file.py b/funasr/download/file.py
index d93f24c..da4958a 100644
--- a/funasr/download/file.py
+++ b/funasr/download/file.py
@@ -8,7 +8,23 @@
from typing import Generator, Union
import requests
+from urllib.parse import urlparse
+def download_from_url(url):
+ result = urlparse(url)
+ file_path = None
+ if result.scheme is not None and len(result.scheme) > 0:
+ storage = HTTPStorage()
+ # bytes
+ data = storage.read(url)
+ work_dir = tempfile.TemporaryDirectory().name
+ if not os.path.exists(work_dir):
+ os.makedirs(work_dir)
+ file_path = os.path.join(work_dir, os.path.basename(url))
+ with open(file_path, 'wb') as fb:
+ fb.write(data)
+ assert file_path is not None, f"failed to download: {url}"
+ return file_path
class Storage(metaclass=ABCMeta):
"""Abstract class of storage.
--
Gitblit v1.9.1