akazmi commited on
Commit
d219730
1 Parent(s): 3739564

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -1,22 +1,20 @@
1
- # Install required libraries
2
- # pip install -U openai-whisper gtts
3
 
4
- import whisper
5
  from gtts import gTTS
6
  import subprocess
7
 
8
- # Step 1: Extract Text from Video using Whisper
9
- def extract_text_from_video(video_path):
10
- # Load the Whisper model
11
- model = whisper.load_model("base")
12
 
13
- # Transcribe the video file's audio
14
- result = model.transcribe(video_path)
 
15
 
16
- # Extract the transcribed text
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 = extract_text_from_video(video_path)
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