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.

22 lines
688 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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}")