Update handler.py
Browse files- handler.py +4 -8
handler.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
from typing import Dict
|
2 |
-
from faster_whisper import WhisperModel
|
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 |
-
#
|
21 |
-
|
22 |
-
segments, info = streaming.transcribe(audio_file, beam_size=1)
|
23 |
|
24 |
# Compile the results into a text string and extract language information
|
25 |
-
|
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 |
|