update and make test for transcribe and chat_vod and shorts
This commit is contained in:
+5
-12
@@ -5,6 +5,7 @@ import whisper
|
||||
import linux
|
||||
from moviepy import VideoFileClip
|
||||
from whisper.utils import get_writer
|
||||
from pathlib import Path
|
||||
|
||||
model = whisper.load_model("base")
|
||||
|
||||
@@ -29,6 +30,8 @@ def extract_audio(video_path: str):
|
||||
codec="pcm_s16le",
|
||||
ffmpeg_params=["-ac", "1"]
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
finally:
|
||||
# Always clean up the temporary sanitized video on Windows 11
|
||||
if os.path.exists(sanitized_video_path):
|
||||
@@ -45,7 +48,7 @@ def transcribe_to_srt(video_path: str):
|
||||
result = model.transcribe(audio_path)
|
||||
|
||||
print("Creating SRT file...")
|
||||
srt_writer = get_writer("srt", transcribe_path)
|
||||
srt_writer = get_writer("srt", Path(transcribe_path).parent)
|
||||
srt_writer(result, transcribe_path, {})
|
||||
|
||||
print(f"SRT subtitle file saved in: {transcribe_path}")
|
||||
@@ -54,14 +57,4 @@ def transcribe_to_srt(video_path: str):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
video_path = "my_video.mp4"
|
||||
audio_temp_path = "temp_audio.wav" # Changed extension to .wav
|
||||
|
||||
output_dir = os.getcwd()
|
||||
output_prefix = "my_video_subtitles"
|
||||
|
||||
extract_audio(video_path, audio_temp_path)
|
||||
transcribe_to_srt(audio_temp_path, output_dir, output_prefix)
|
||||
|
||||
if os.path.exists(audio_temp_path):
|
||||
os.remove(audio_temp_path)
|
||||
transcribe_to_srt("download/clips/AbnegateAgitatedGrassPJSalt/AbnegateAgitatedGrassPJSalt.mp4")
|
||||
Reference in New Issue
Block a user