FarhadMadadzade
commited on
Commit
•
4c56b36
1
Parent(s):
43e6a3b
added error handling
Browse files
app.py
CHANGED
@@ -13,36 +13,40 @@ pipe = pipeline("automatic-speech-recognition", model="Artanis1551/whisper_swedi
|
|
13 |
|
14 |
|
15 |
def process_video1(date):
|
16 |
-
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
46 |
|
47 |
return video_path, transcription
|
48 |
|
|
|
13 |
|
14 |
|
15 |
def process_video1(date):
|
16 |
+
try:
|
17 |
+
video_path = download_video1(date)
|
18 |
|
19 |
+
# Get the duration of the video
|
20 |
+
video = VideoFileClip(video_path)
|
21 |
+
duration = video.duration
|
22 |
|
23 |
+
# If the video is longer than 30 seconds, only take the first 30 seconds
|
24 |
+
if duration > 30:
|
25 |
+
video_path = f"short_{date}.mp4"
|
26 |
+
ffmpeg_extract_subclip(video_path, 0, 30, targetname=video_path)
|
27 |
|
28 |
+
# Extract audio from the video
|
29 |
+
audio_path = f"audio_{date}.wav"
|
30 |
+
AudioFileClip(video_path).write_audiofile(audio_path)
|
31 |
|
32 |
+
# Split the audio into chunks
|
33 |
+
audio = AudioSegment.from_wav(audio_path)
|
34 |
+
chunks = split_on_silence(audio, min_silence_len=500, silence_thresh=-40)
|
35 |
|
36 |
+
# Transcribe each chunk
|
37 |
+
transcription = ""
|
38 |
+
for i, chunk in enumerate(chunks):
|
39 |
+
chunk.export(f"chunk{i}.wav", format="wav")
|
40 |
+
with open(f"chunk{i}.wav", "rb") as audio_file:
|
41 |
+
audio = audio_file.read()
|
42 |
+
transcription += pipe(audio)["text"] + "\n "
|
43 |
+
os.remove(f"chunk{i}.wav")
|
44 |
|
45 |
+
# Remove the audio file
|
46 |
+
os.remove(audio_path)
|
47 |
+
except:
|
48 |
+
video_path = ""
|
49 |
+
transcription = "No decision was made on this date."
|
50 |
|
51 |
return video_path, transcription
|
52 |
|