Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,20 @@
|
|
| 1 |
-
# Install
|
| 2 |
-
# pip install
|
| 3 |
|
| 4 |
-
import
|
| 5 |
from gtts import gTTS
|
| 6 |
import subprocess
|
| 7 |
|
| 8 |
-
# Step 1: Extract Text from
|
| 9 |
-
def
|
| 10 |
-
# Load the Whisper model
|
| 11 |
-
|
| 12 |
|
| 13 |
-
# Transcribe the
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
text = result["text"]
|
| 18 |
-
|
| 19 |
-
# Save the transcribed text to a file (optional)
|
| 20 |
with open("video_text.txt", "w") as f:
|
| 21 |
f.write(text)
|
| 22 |
|
|
@@ -48,8 +46,8 @@ def add_voice_over_to_video(video_path, audio_path, output_video_path="output_vi
|
|
| 48 |
|
| 49 |
# Run the complete process
|
| 50 |
def main(video_path):
|
| 51 |
-
# Step 1: Extract text from video
|
| 52 |
-
text =
|
| 53 |
print("Extracted Text:", text)
|
| 54 |
|
| 55 |
# Step 2: Generate voice-over from extracted text
|
|
|
|
| 1 |
+
# Install dependencies if not already done in your environment
|
| 2 |
+
# pip install transformers torch gtts ffmpeg-python
|
| 3 |
|
| 4 |
+
from transformers import pipeline
|
| 5 |
from gtts import gTTS
|
| 6 |
import subprocess
|
| 7 |
|
| 8 |
+
# Step 1: Extract Text from Audio using Hugging Face Transformers
|
| 9 |
+
def extract_text_from_audio(audio_path):
|
| 10 |
+
# Load the ASR pipeline from Hugging Face with a Whisper-like model
|
| 11 |
+
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 12 |
|
| 13 |
+
# Transcribe the audio file
|
| 14 |
+
transcription = transcriber(audio_path)
|
| 15 |
+
text = transcription["text"]
|
| 16 |
|
| 17 |
+
# Save transcribed text to a file (optional)
|
|
|
|
|
|
|
|
|
|
| 18 |
with open("video_text.txt", "w") as f:
|
| 19 |
f.write(text)
|
| 20 |
|
|
|
|
| 46 |
|
| 47 |
# Run the complete process
|
| 48 |
def main(video_path):
|
| 49 |
+
# Step 1: Extract text from video/audio
|
| 50 |
+
text = extract_text_from_audio(video_path)
|
| 51 |
print("Extracted Text:", text)
|
| 52 |
|
| 53 |
# Step 2: Generate voice-over from extracted text
|