younes21000 commited on
Commit
9c779fd
·
verified ·
1 Parent(s): e70c3e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import moviepy.editor as mp
3
  import librosa
 
4
  from transformers import pipeline
5
  from concurrent.futures import ThreadPoolExecutor
6
 
@@ -39,17 +40,13 @@ def generate_subtitles(video_file, language_name):
39
 
40
  print(f"Processing video from path: {video_path}")
41
 
42
- # Extract audio from video using moviepy
43
  video = mp.VideoFileClip(video_path)
44
- audio_path = "temp_audio.wav"
45
  audio = video.audio
46
- audio.write_audiofile(audio_path, codec='pcm_s16le')
47
 
48
  print("Starting speech-to-text transcription")
49
 
50
- # Load the audio file as a waveform using librosa
51
- waveform, sr = librosa.load(audio_path, sr=16000) # sr=16000 for Whisper
52
-
53
  # Process audio in chunks
54
  chunk_duration = 15 # seconds
55
  chunk_size = sr * chunk_duration # number of samples per chunk
 
1
  import gradio as gr
2
  import moviepy.editor as mp
3
  import librosa
4
+ import numpy as np
5
  from transformers import pipeline
6
  from concurrent.futures import ThreadPoolExecutor
7
 
 
40
 
41
  print(f"Processing video from path: {video_path}")
42
 
43
+ # Load the video and extract audio directly
44
  video = mp.VideoFileClip(video_path)
 
45
  audio = video.audio
46
+ waveform, sr = librosa.load(audio.reader, sr=16000) # Load directly from audio reader
47
 
48
  print("Starting speech-to-text transcription")
49
 
 
 
 
50
  # Process audio in chunks
51
  chunk_duration = 15 # seconds
52
  chunk_size = sr * chunk_duration # number of samples per chunk