juancopi81 commited on
Commit
a09bf24
1 Parent(s): b56303a

Update transforming/whispertransform.py

Browse files
Files changed (1) hide show
  1. transforming/whispertransform.py +15 -25
transforming/whispertransform.py CHANGED
@@ -30,36 +30,26 @@ class WhisperTransform(Transform):
30
  """Creates a new video with transcriptions created by Whisper.
31
  """
32
  # Create a YouTube object
33
- try:
34
- yt = YouTube(video.url)
35
- except Exception as e:
36
- print ("Video not available \n")
37
- print(f"Exception: {e}")
38
-
39
  print(f"Video title and url: {video.title} {video.url}")
40
 
41
- try:
42
- audio_file = self._get_audio_from_video(yt)
43
- result = self.model.transcribe(audio_file,
44
- without_timestamps=self.without_timestamps)
45
- except Exception as e:
46
- print(f"Audio exception print: {e}")
47
-
48
- else:
49
- transcription = result["text"]
50
 
51
- data = []
52
- for seg in result['segments']:
53
- data.append(OrderedDict({'start': seg['start'], 'end': seg['end'],'text': seg['text']}))
54
 
55
- os.remove(audio_file)
56
 
57
- return YoutubeVideo(channel_name = video.channel_name,
58
- url = video.url,
59
- title = video.title,
60
- description = video.description,
61
- transcription = transcription,
62
- segments = data)
63
 
64
  def _get_audio_from_video(self, yt: Any) -> Path:
65
  # TODO: Add credits
 
30
  """Creates a new video with transcriptions created by Whisper.
31
  """
32
  # Create a YouTube object
33
+ yt = YouTube(video.url)
 
 
 
 
 
34
  print(f"Video title and url: {video.title} {video.url}")
35
 
36
+ audio_file = self._get_audio_from_video(yt)
37
+ result = self.model.transcribe(audio_file,
38
+ without_timestamps=self.without_timestamps)
39
+ transcription = result["text"]
 
 
 
 
 
40
 
41
+ data = []
42
+ for seg in result['segments']:
43
+ data.append(OrderedDict({'start': seg['start'], 'end': seg['end'],'text': seg['text']}))
44
 
45
+ os.remove(audio_file)
46
 
47
+ return YoutubeVideo(channel_name = video.channel_name,
48
+ url = video.url,
49
+ title = video.title,
50
+ description = video.description,
51
+ transcription = transcription,
52
+ segments = data)
53
 
54
  def _get_audio_from_video(self, yt: Any) -> Path:
55
  # TODO: Add credits