mirror of
https://github.com/harry0703/MoneyPrinterTurbo.git
synced 2026-02-21 08:27:22 +08:00
Fix support for Windows systems
This commit is contained in:
parent
f55ea42a07
commit
9650def321
@ -1,5 +1,5 @@
|
||||
import os
|
||||
|
||||
import socket
|
||||
import tomli
|
||||
from loguru import logger
|
||||
|
||||
@ -12,8 +12,7 @@ with open(config_file, mode="rb") as fp:
|
||||
|
||||
app = _cfg.get("app", {})
|
||||
whisper = _cfg.get("whisper", {})
|
||||
|
||||
hostname = os.uname().nodename
|
||||
hostname = socket.gethostname()
|
||||
|
||||
log_level = _cfg.get("log_level", "DEBUG")
|
||||
listen_host = _cfg.get("listen_host", "0.0.0.0")
|
||||
@ -23,6 +22,10 @@ project_description = _cfg.get("project_description", "MoneyPrinterTurbo\n by
|
||||
project_version = _cfg.get("project_version", "1.0.0")
|
||||
reload_debug = False
|
||||
|
||||
imagemagick_path = app.get("imagemagick_path", "")
|
||||
if imagemagick_path and os.path.isfile(imagemagick_path):
|
||||
os.environ["IMAGEMAGICK_BINARY"] = imagemagick_path
|
||||
|
||||
__cfg = {
|
||||
"hostname": hostname,
|
||||
"listen_host": listen_host,
|
||||
|
||||
@ -6,14 +6,14 @@ from timeit import default_timer as timer
|
||||
from loguru import logger
|
||||
|
||||
from app.config import config
|
||||
from app.models import const
|
||||
from app.utils import utils
|
||||
|
||||
model_size = config.whisper.get("model_size", "large-v3")
|
||||
device = config.whisper.get("device", "cpu")
|
||||
compute_type = config.whisper.get("compute_type", "int8")
|
||||
|
||||
model = WhisperModel(model_size_or_path=model_size, device=device, compute_type=compute_type)
|
||||
if config.app.get("subtitle_provider") == "whisper":
|
||||
model = WhisperModel(model_size_or_path=model_size, device=device, compute_type=compute_type)
|
||||
|
||||
|
||||
def create(audio_file, subtitle_file: str = ""):
|
||||
|
||||
@ -17,9 +17,7 @@ def get_bgm_file(bgm_name: str = "random"):
|
||||
if bgm_name == "random":
|
||||
suffix = "*.mp3"
|
||||
song_dir = utils.song_dir()
|
||||
# 使用glob.glob获取指定扩展名的文件列表
|
||||
files = glob.glob(os.path.join(song_dir, suffix))
|
||||
# 使用random.choice从列表中随机选择一个文件
|
||||
return random.choice(files)
|
||||
|
||||
file = os.path.join(utils.song_dir(), bgm_name)
|
||||
@ -154,11 +152,12 @@ def generate_video(video_path: str,
|
||||
if not font_name:
|
||||
font_name = "STHeitiMedium.ttc"
|
||||
font_path = os.path.join(utils.font_dir(), font_name)
|
||||
if os.name == 'nt':
|
||||
font_path = font_path.replace("\\", "/")
|
||||
|
||||
logger.info(f"using font: {font_path}")
|
||||
|
||||
# 自定义的生成器函数,包含换行逻辑
|
||||
def generator(txt):
|
||||
# 应用自动换行
|
||||
wrapped_txt = wrap_text(txt, max_width=video_width - 100,
|
||||
font=font_path,
|
||||
fontsize=fontsize) # 调整max_width以适应你的视频
|
||||
@ -179,16 +178,14 @@ def generate_video(video_path: str,
|
||||
|
||||
clips = [
|
||||
VideoFileClip(video_path),
|
||||
# subtitles.set_position(lambda _t: ('center', position_height))
|
||||
]
|
||||
# Burn the subtitles into the video
|
||||
|
||||
if subtitle_path and os.path.exists(subtitle_path):
|
||||
subtitles = SubtitlesClip(subtitle_path, generator)
|
||||
subtitles = SubtitlesClip(subtitles=subtitle_path, make_textclip=generator, encoding='utf-8')
|
||||
clips.append(subtitles.set_position(lambda _t: ('center', position_height)))
|
||||
|
||||
result = CompositeVideoClip(clips)
|
||||
|
||||
# Add the audio
|
||||
audio = AudioFileClip(audio_path)
|
||||
result = result.set_audio(audio)
|
||||
|
||||
@ -210,10 +207,10 @@ def generate_video(video_path: str,
|
||||
video_clip = video_clip.set_audio(comp_audio)
|
||||
video_clip = video_clip.set_fps(30)
|
||||
video_clip = video_clip.set_duration(original_duration)
|
||||
# 编码为aac,否则iPhone里面无法播放
|
||||
|
||||
logger.info(f"encoding audio codec to aac")
|
||||
video_clip.write_videofile(output_file, audio_codec="aac", threads=threads)
|
||||
# delete the temp file
|
||||
|
||||
os.remove(temp_output_file)
|
||||
logger.success(f"completed")
|
||||
|
||||
|
||||
@ -15,6 +15,11 @@
|
||||
# If empty, the subtitle will not be generated
|
||||
subtitle_provider = "edge"
|
||||
|
||||
# Once you have installed it, ImageMagick will be automatically detected, except on Windows!
|
||||
# On Windows, for example "C:\Program Files (x86)\ImageMagick-7.1.1-Q16-HDRI\magick.exe"
|
||||
# Download from https://imagemagick.org/archive/binaries/ImageMagick-7.1.1-29-Q16-x64-static.exe
|
||||
# imagemagick_path = "C:\\Program Files (x86)\\ImageMagick-7.1.1-Q16\\magick.exe"
|
||||
|
||||
[whisper]
|
||||
# Only effective when subtitle_provider is "whisper"
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
requests~=2.31.0
|
||||
moviepy~=1.0.3
|
||||
moviepy~=2.0.0.dev2
|
||||
openai~=1.13.3
|
||||
faster-whisper~=1.0.1
|
||||
edge_tts~=6.1.10
|
||||
|
||||
Loading…
Reference in New Issue
Block a user