FarhadMadadzade commited on
Commit
4b85b27
1 Parent(s): 536f3e9

try to chunk into pieces

Browse files
Files changed (2) hide show
  1. app.py +14 -4
  2. requirements.txt +2 -1
app.py CHANGED
@@ -5,6 +5,8 @@ from video_downloader import download_video
5
  from moviepy.editor import AudioFileClip
6
  import datetime
7
  import os
 
 
8
 
9
  pipe = pipeline("automatic-speech-recognition", model="Artanis1551/whisper_romanian3")
10
 
@@ -17,10 +19,18 @@ def process_video(date):
17
  audio_path = f"audio_{date}.wav"
18
  AudioFileClip(video_path).write_audiofile(audio_path)
19
 
20
- # Transcribe the audio
21
- with open(audio_path, "rb") as audio_file:
22
- audio = audio_file.read()
23
- transcription = pipe(audio)["text"]
 
 
 
 
 
 
 
 
24
 
25
  # Remove the audio file
26
  os.remove(audio_path)
 
5
  from moviepy.editor import AudioFileClip
6
  import datetime
7
  import os
8
+ from pydub import AudioSegment
9
+ from pydub.silence import split_on_silence
10
 
11
  pipe = pipeline("automatic-speech-recognition", model="Artanis1551/whisper_romanian3")
12
 
 
19
  audio_path = f"audio_{date}.wav"
20
  AudioFileClip(video_path).write_audiofile(audio_path)
21
 
22
+ # Split the audio into chunks
23
+ audio = AudioSegment.from_wav(audio_path)
24
+ chunks = split_on_silence(audio, min_silence_len=500, silence_thresh=-40)
25
+
26
+ # Transcribe each chunk
27
+ transcription = ""
28
+ for i, chunk in enumerate(chunks):
29
+ chunk.export(f"chunk{i}.wav", format="wav")
30
+ with open(f"chunk{i}.wav", "rb") as audio_file:
31
+ audio = audio_file.read()
32
+ transcription += pipe(audio)["text"] + "\n "
33
+ os.remove(f"chunk{i}.wav")
34
 
35
  # Remove the audio file
36
  os.remove(audio_path)
requirements.txt CHANGED
@@ -6,4 +6,5 @@ gradio
6
  transformers
7
  torch
8
  urllib3
9
- moviepy
 
 
6
  transformers
7
  torch
8
  urllib3
9
+ moviepy
10
+ pydub