karin.brisker commited on
Commit
5ac1e08
·
1 Parent(s): dd76b9f

openning audio file

Browse files
Files changed (1) hide show
  1. audio_to_transcript.py +3 -9
audio_to_transcript.py CHANGED
@@ -3,7 +3,6 @@ from typing import Dict
3
 
4
  import torch
5
  import whisper
6
- from whisper.utils import get_writer
7
 
8
  import numpy as np # for counting parameters
9
 
@@ -19,7 +18,7 @@ class TranscribeAudio:
19
  f"Model is {'multilingual' if self.model.is_multilingual else 'English-only'} "
20
  f"and has {sum(np.prod(p.shape) for p in self.model.parameters()):,} parameters."
21
  )
22
- self.options = {"max_line_width": 20, "max_line_count": 3, "highlight_words": True}
23
 
24
  def transcribe(self, audio_file_path: str, language: str = "en") -> Dict:
25
  log(f"Transcribing {audio_file_path} in {language}")
@@ -32,18 +31,13 @@ class TranscribeAudio:
32
  filename, ext = os.path.splitext(audio_file_path)
33
  directory = os.path.dirname(filename)
34
  log(f"Saving output to {directory} directory as {filename}.vtt")
 
 
35
  # Save as an SRT file
36
- srt_writer = get_writer("srt", directory)
37
  srt_writer(transcript_output, audio_file_path, self.options)
38
 
39
  # Save as a VTT file
40
- vtt_writer = get_writer("vtt", directory)
41
  vtt_writer(transcript_output, audio_file_path, self.options)
42
- # Save as an SRT file
43
- srt_writer(transcript_output, audio_file_path, {"max_line_width": None, "max_line_count": None, "highlight_words": True})
44
-
45
- # Save as a VTT file
46
- vtt_writer(transcript_output, audio_file_path, {"max_line_width": None, "max_line_count": None, "highlight_words": True})
47
 
48
  return f"{filename}.vtt"
49
 
 
3
 
4
  import torch
5
  import whisper
 
6
 
7
  import numpy as np # for counting parameters
8
 
 
18
  f"Model is {'multilingual' if self.model.is_multilingual else 'English-only'} "
19
  f"and has {sum(np.prod(p.shape) for p in self.model.parameters()):,} parameters."
20
  )
21
+ self.options = {"max_line_width": None, "max_line_count": None, "highlight_words": True}
22
 
23
  def transcribe(self, audio_file_path: str, language: str = "en") -> Dict:
24
  log(f"Transcribing {audio_file_path} in {language}")
 
31
  filename, ext = os.path.splitext(audio_file_path)
32
  directory = os.path.dirname(filename)
33
  log(f"Saving output to {directory} directory as {filename}.vtt")
34
+ srt_writer = whisper.utils.get_writer("srt", directory)
35
+ vtt_writer = whisper.utils.get_writer("vtt", directory)
36
  # Save as an SRT file
 
37
  srt_writer(transcript_output, audio_file_path, self.options)
38
 
39
  # Save as a VTT file
 
40
  vtt_writer(transcript_output, audio_file_path, self.options)
 
 
 
 
 
41
 
42
  return f"{filename}.vtt"
43