Dominik Macháček commited on
Commit
cd221a3
·
1 Parent(s): 1f2352f

auto language detection #56

Browse files
Files changed (1) hide show
  1. whisper_online.py +8 -2
whisper_online.py CHANGED
@@ -30,7 +30,10 @@ class ASRBase:
30
  self.logfile = logfile
31
 
32
  self.transcribe_kargs = {}
33
- self.original_language = lan
 
 
 
34
 
35
  self.model = self.load_model(modelsize, cache_dir, model_dir)
36
 
@@ -118,8 +121,11 @@ class FasterWhisperASR(ASRBase):
118
  return model
119
 
120
  def transcribe(self, audio, init_prompt=""):
 
121
  # tested: beam_size=5 is faster and better than 1 (on one 200 second document from En ESIC, min chunk 0.01)
122
  segments, info = self.model.transcribe(audio, language=self.original_language, initial_prompt=init_prompt, beam_size=5, word_timestamps=True, condition_on_previous_text=True, **self.transcribe_kargs)
 
 
123
  return list(segments)
124
 
125
  def ts_words(self, segments):
@@ -451,7 +457,7 @@ def add_shared_args(parser):
451
  parser.add_argument('--model', type=str, default='large-v2', choices="tiny.en,tiny,base.en,base,small.en,small,medium.en,medium,large-v1,large-v2,large-v3,large".split(","),help="Name size of the Whisper model to use (default: large-v2). The model is automatically downloaded from the model hub if not present in model cache dir.")
452
  parser.add_argument('--model_cache_dir', type=str, default=None, help="Overriding the default model cache dir where models downloaded from the hub are saved")
453
  parser.add_argument('--model_dir', type=str, default=None, help="Dir where Whisper model.bin and other files are saved. This option overrides --model and --model_cache_dir parameter.")
454
- parser.add_argument('--lan', '--language', type=str, default='en', help="Language code for transcription, e.g. en,de,cs.")
455
  parser.add_argument('--task', type=str, default='transcribe', choices=["transcribe","translate"],help="Transcribe or translate.")
456
  parser.add_argument('--backend', type=str, default="faster-whisper", choices=["faster-whisper", "whisper_timestamped"],help='Load only this backend for Whisper processing.')
457
  parser.add_argument('--vad', action="store_true", default=False, help='Use VAD = voice activity detection, with the default parameters.')
 
30
  self.logfile = logfile
31
 
32
  self.transcribe_kargs = {}
33
+ if lan == "auto":
34
+ self.original_language = None
35
+ else:
36
+ self.original_language = lan
37
 
38
  self.model = self.load_model(modelsize, cache_dir, model_dir)
39
 
 
121
  return model
122
 
123
  def transcribe(self, audio, init_prompt=""):
124
+
125
  # tested: beam_size=5 is faster and better than 1 (on one 200 second document from En ESIC, min chunk 0.01)
126
  segments, info = self.model.transcribe(audio, language=self.original_language, initial_prompt=init_prompt, beam_size=5, word_timestamps=True, condition_on_previous_text=True, **self.transcribe_kargs)
127
+ #print(info) # info contains language detection result
128
+
129
  return list(segments)
130
 
131
  def ts_words(self, segments):
 
457
  parser.add_argument('--model', type=str, default='large-v2', choices="tiny.en,tiny,base.en,base,small.en,small,medium.en,medium,large-v1,large-v2,large-v3,large".split(","),help="Name size of the Whisper model to use (default: large-v2). The model is automatically downloaded from the model hub if not present in model cache dir.")
458
  parser.add_argument('--model_cache_dir', type=str, default=None, help="Overriding the default model cache dir where models downloaded from the hub are saved")
459
  parser.add_argument('--model_dir', type=str, default=None, help="Dir where Whisper model.bin and other files are saved. This option overrides --model and --model_cache_dir parameter.")
460
+ parser.add_argument('--lan', '--language', type=str, default='en', help="Source language code, e.g. en,de,cs, or 'auto' for language detection.")
461
  parser.add_argument('--task', type=str, default='transcribe', choices=["transcribe","translate"],help="Transcribe or translate.")
462
  parser.add_argument('--backend', type=str, default="faster-whisper", choices=["faster-whisper", "whisper_timestamped"],help='Load only this backend for Whisper processing.')
463
  parser.add_argument('--vad', action="store_true", default=False, help='Use VAD = voice activity detection, with the default parameters.')