You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import oss2
|
|
|
|
|
from TtsConfig import *
|
|
|
|
|
|
|
|
|
|
# 初始化 OSS Bucket
|
|
|
|
|
auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
|
|
|
|
|
bucket = oss2.Bucket(auth, ENDPOINT, BUCKET_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 上传 MP3 文件到 OSS
|
|
|
|
|
def upload_mp3_to_oss(file_path, oss_object_name):
|
|
|
|
|
"""
|
|
|
|
|
上传 MP3 文件到 OSS
|
|
|
|
|
:param file_path: 本地 MP3 文件路径
|
|
|
|
|
:param oss_object_name: OSS 中存储的文件名
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
# 上传文件
|
|
|
|
|
with open(file_path, 'rb') as file:
|
|
|
|
|
bucket.put_object(oss_object_name, file)
|
|
|
|
|
print(f"文件 {file_path} 已成功上传到 OSS,存储为 {oss_object_name}")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"上传失败: {e}")
|