srd4 commited on
Commit
93617b7
1 Parent(s): 6c96652

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +4 -8
handler.py CHANGED
@@ -1,7 +1,6 @@
1
  from typing import Dict
2
- from faster_whisper import WhisperModel, Streaming
3
  import io
4
- import re
5
 
6
  class EndpointHandler:
7
  def __init__(self, model_dir=None):
@@ -17,14 +16,11 @@ class EndpointHandler:
17
  # Convert bytes to a file-like object
18
  audio_file = io.BytesIO(audio_bytes)
19
 
20
- # Enable VAD and perform transcription using the model with a reduced beam size
21
- streaming = Streaming(device="cuda", compute_type="float16", vad=True)
22
- segments, info = streaming.transcribe(audio_file, beam_size=1)
23
 
24
  # Compile the results into a text string and extract language information
25
- # Strip leading and trailing whitespace and replace multiple spaces with a single space
26
- text = " ".join(segment.text.strip() for segment in segments)
27
- text = re.sub(' +', ' ', text)
28
  language_code = info.language
29
  language_prob = info.language_probability
30
 
 
1
  from typing import Dict
2
+ from faster_whisper import WhisperModel
3
  import io
 
4
 
5
  class EndpointHandler:
6
  def __init__(self, model_dir=None):
 
16
  # Convert bytes to a file-like object
17
  audio_file = io.BytesIO(audio_bytes)
18
 
19
+ # Perform transcription using the model
20
+ segments, info = self.model.transcribe(audio_file)
 
21
 
22
  # Compile the results into a text string and extract language information
23
+ text = " ".join(segment.text for segment in segments)
 
 
24
  language_code = info.language
25
  language_prob = info.language_probability
26