mirror of
https://github.com/Hommy-master/capcut-mate.git
synced 2026-08-28 23:27:50 +08:00
Merge branch 'dev' of github.com:Hommy-master/capcut-mate into dev
This commit is contained in:
@@ -136,20 +136,57 @@ def add_audio_to_draft(
|
||||
audio['duration'] = temp_material.duration
|
||||
logger.info(f"Auto-detected audio duration: {audio['duration']} microseconds")
|
||||
|
||||
# 3. 创建音频素材并添加到草稿
|
||||
# 3. 计算截取时长
|
||||
segment_duration = audio['end'] - audio['start']
|
||||
logger.info(f"Audio trimming params - start: {audio['start']} microseconds, end: {audio['end']} microseconds, duration: {segment_duration} microseconds")
|
||||
|
||||
# 5. 创建音频素材并添加到草稿
|
||||
# 使用逻辑截取,通过source_timerange设置音频片段的开始和结束时间
|
||||
audio_segment = draft.AudioSegment(
|
||||
material=audio_path,
|
||||
target_timerange=trange(start=audio['start'], duration=segment_duration),
|
||||
material=audio_path, # 使用原始音频文件
|
||||
source_timerange=trange(start=audio['start'], duration=segment_duration), # 设置从原始音频的哪个位置开始截取
|
||||
target_timerange=trange(start=0, duration=segment_duration), # 轨道开始时间从0开始
|
||||
volume=audio['volume']
|
||||
)
|
||||
|
||||
# 3. 添加音频效果(如果指定了)
|
||||
if audio.get('audio_effect'):
|
||||
try:
|
||||
# 这里可以根据需要添加具体的音频效果
|
||||
# 由于音频效果类型较多,这里先预留接口
|
||||
logger.info(f"Audio effect '{audio['audio_effect']}' specified but not implemented yet")
|
||||
# 添加音频效果
|
||||
audio_effect = audio['audio_effect']
|
||||
effect_type = None
|
||||
|
||||
# 查找对应的音频效果类型
|
||||
for effect_name, effect_meta in draft.AudioSceneEffectType.__members__.items():
|
||||
if effect_meta.value.name == audio_effect:
|
||||
effect_type = effect_meta
|
||||
break
|
||||
|
||||
# 如果找到了对应的效果类型,则添加效果
|
||||
if effect_type:
|
||||
# 获取效果的默认参数,转换为0-100范围内的值列表
|
||||
# 注意:add_effect方法需要的是0-100范围内的参数值列表
|
||||
# 而不是直接传递实际值
|
||||
params_list = []
|
||||
for param in effect_type.value.params:
|
||||
# 将实际默认值转换为0-100范围内的值
|
||||
# 例如:如果参数范围是0-1,默认值是1,则转换为100
|
||||
if param.min_value != param.max_value:
|
||||
# 计算参数值在0-100范围内的对应值
|
||||
param_value = ((param.default_value - param.min_value) / (param.max_value - param.min_value)) * 100
|
||||
else:
|
||||
# 如果参数范围是固定值,则使用50作为默认值
|
||||
param_value = 50
|
||||
params_list.append(param_value)
|
||||
|
||||
# 添加效果
|
||||
audio_segment.add_effect(
|
||||
effect_type=effect_type,
|
||||
params=params_list
|
||||
)
|
||||
logger.info(f"Added audio effect: {audio_effect} with params: {params_list}")
|
||||
else:
|
||||
logger.warning(f"Unknown audio effect: {audio_effect}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to add audio effect '{audio['audio_effect']}': {str(e)}")
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ def test_add_audios():
|
||||
"""测试音频添加接口"""
|
||||
|
||||
# 1. 先创建一个草稿
|
||||
create_draft_url = "http://localhost:8000/v1/create_draft"
|
||||
create_draft_url = "http://localhost:30000/openapi/capcut-mate/v1/create_draft"
|
||||
create_draft_data = {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
@@ -25,29 +25,15 @@ def test_add_audios():
|
||||
print(f"Draft created successfully: {draft_url}")
|
||||
|
||||
# 2. 添加音频
|
||||
add_audios_url = "http://localhost:8000/v1/add_audios"
|
||||
add_audios_url = "http://localhost:30000/openapi/capcut-mate/v1/add_audios"
|
||||
audio_infos = [
|
||||
{
|
||||
"audio_url": "https://example.com/audio1.mp3",
|
||||
"audio_url": "https://assets.jcaigc.cn/test1.mp3",
|
||||
"duration": 10000000, # 10秒 (微秒)
|
||||
"start": 0,
|
||||
"end": 5000000, # 前5秒
|
||||
"volume": 0.8,
|
||||
"audio_effect": "reverb"
|
||||
},
|
||||
{
|
||||
"audio_url": "https://example.com/audio2.mp3",
|
||||
"duration": 15000000, # 15秒 (微秒)
|
||||
"start": 5000000, # 从第5秒开始
|
||||
"end": 10000000, # 到第10秒结束
|
||||
"volume": 1.0
|
||||
},
|
||||
# 测试不提供duration字段的情况
|
||||
{
|
||||
"audio_url": "https://example.com/audio3.mp3",
|
||||
"start": 10000000, # 从第10秒开始
|
||||
"end": 15000000, # 到第15秒结束
|
||||
"volume": 0.5
|
||||
"audio_effect": "教堂"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -71,7 +57,7 @@ def test_add_audios():
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error occurred: {e}")
|
||||
print("Make sure the server is running on http://localhost:8000")
|
||||
print("确保服务器正在运行 http://localhost:30000")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user