71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
![]() |
from .base import logger, synthesize_speech
|
|||
|
import requests
|
|||
|
|
|||
|
VIDEO_API_KEY = 'c4c0f516-33c0-4f5c-9d29-3b1d4e6a93c3'
|
|||
|
VIDEO_API_URL = 'https://www.typeframes.com/api/public/v2/render'
|
|||
|
WEBHOOK_URL = 'https://www.typeframes.cc/api/webhook/'
|
|||
|
|
|||
|
def create_video(audio_url,generationPreset, media_type, text, ratio, voice_name, user_id, slug,disableCaptions, caption_preset, caption_position, video_id):
|
|||
|
"""
|
|||
|
生成视频的函数(用于 create-tiktok-video)
|
|||
|
"""
|
|||
|
try:
|
|||
|
video_headers = {
|
|||
|
'Content-Type': 'application/json',
|
|||
|
'key': VIDEO_API_KEY
|
|||
|
}
|
|||
|
|
|||
|
# 判断是否需要生成视频
|
|||
|
hasToGenerateVideos = media_type == "movingImage"
|
|||
|
|
|||
|
# 配置 webhook URL,包含 video_id
|
|||
|
webhook_url = f"{WEBHOOK_URL}?userid={user_id}&videoid={video_id}"
|
|||
|
|
|||
|
# 构建请求体
|
|||
|
payload = {
|
|||
|
"frameRate": 60,
|
|||
|
"resolution": "1080p",
|
|||
|
"frameDurationMultiplier": 5,
|
|||
|
"webhook": webhook_url,
|
|||
|
"creationParams": {
|
|||
|
"mediaType": media_type,
|
|||
|
"origin": "/create",
|
|||
|
"inputText": text,
|
|||
|
"flowType": "text-to-video",
|
|||
|
"slug": slug,
|
|||
|
"disableCaptions": disableCaptions,
|
|||
|
"hasToGenerateVoice": False,
|
|||
|
"hasToTranscript": False,
|
|||
|
"hasToSearchMedia": True,
|
|||
|
"useQualityTranscript":False,
|
|||
|
"hasAvatar": False,
|
|||
|
"hasWebsiteRecorder": False,
|
|||
|
"hasTextSmallAtBottom": False,
|
|||
|
"captionPresetName": caption_preset,
|
|||
|
"captionPositionName": caption_position,
|
|||
|
"disableAudio": True,
|
|||
|
"ratio": ratio,
|
|||
|
"selectedAudio": "Bladerunner 2049",
|
|||
|
"selectedVoice": voice_name,
|
|||
|
"sourceType": "contentScraping",
|
|||
|
"selectedStoryStyle": {
|
|||
|
"value": "custom",
|
|||
|
"label": "Custom"
|
|||
|
},
|
|||
|
"hasToGenerateVideos": hasToGenerateVideos,
|
|||
|
"selectedRecording": audio_url,
|
|||
|
"selectedRecordingType": "audio",
|
|||
|
"generationPreset": generationPreset,
|
|||
|
"audioUrl": "https://cdn.tfrv.xyz/audio/_bladerunner-2049.mp3"
|
|||
|
}
|
|||
|
}
|
|||
|
logger.info(payload)
|
|||
|
response = requests.post(VIDEO_API_URL, headers=video_headers, json=payload)
|
|||
|
|
|||
|
if response.status_code == 200:
|
|||
|
return {"code": 200, "data": response.json()}
|
|||
|
else:
|
|||
|
return {"code": response.status_code, "message": response.text}
|
|||
|
except Exception as e:
|
|||
|
return {"code": 500, "message": str(e)}
|