juancopi81 commited on
Commit
d357f9b
·
1 Parent(s): 5c20ea7

Update transforming/whispertransform.py

Browse files
Files changed (1) hide show
  1. transforming/whispertransform.py +19 -14
transforming/whispertransform.py CHANGED
@@ -40,22 +40,27 @@ class WhisperTransform(Transform):
40
  print(f"Video title and url: {video.title} {video.url}")
41
  audio_file = self._get_audio_from_video(yt)
42
 
43
- result = self.model.transcribe(audio_file,
44
- without_timestamps=self.without_timestamps)
45
- transcription = result["text"]
46
-
47
- data = []
48
- for seg in result['segments']:
49
- data.append(OrderedDict({'start': seg['start'], 'end': seg['end'],'text': seg['text']}))
 
 
 
 
 
50
 
51
- os.remove(audio_file)
52
 
53
- return YoutubeVideo(channel_name = video.channel_name,
54
- url = video.url,
55
- title = video.title,
56
- description = video.description,
57
- transcription = transcription,
58
- segments = data)
59
 
60
  def _get_audio_from_video(self, yt: Any) -> Path:
61
  # TODO: Add credits
 
40
  print(f"Video title and url: {video.title} {video.url}")
41
  audio_file = self._get_audio_from_video(yt)
42
 
43
+ try:
44
+ result = self.model.transcribe(audio_file,
45
+ without_timestamps=self.without_timestamps)
46
+ except Exception as e:
47
+ print(f"Audio exception print: {e}")
48
+ pass
49
+ else:
50
+ transcription = result["text"]
51
+
52
+ data = []
53
+ for seg in result['segments']:
54
+ data.append(OrderedDict({'start': seg['start'], 'end': seg['end'],'text': seg['text']}))
55
 
56
+ os.remove(audio_file)
57
 
58
+ return YoutubeVideo(channel_name = video.channel_name,
59
+ url = video.url,
60
+ title = video.title,
61
+ description = video.description,
62
+ transcription = transcription,
63
+ segments = data)
64
 
65
  def _get_audio_from_video(self, yt: Any) -> Path:
66
  # TODO: Add credits