-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcriber.py
34 lines (25 loc) · 955 Bytes
/
transcriber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import logging
import pathlib
from converter import Converter
from wrapper import WhisperWrapper
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger()
class Transcriber:
def __init__(self, audio_path: str) -> None:
self.converter = None
working_path = pathlib.Path(audio_path)
if not working_path.suffix.startswith(".wav"):
logger.info(f"Converting {working_path.suffix} to .wav")
self.converter = Converter(str(working_path))
source_path = self.converter.temp_file_path
else:
source_path = str(working_path)
self.whisper_model = WhisperWrapper(source_path)
print(self.whisper_model.json)
if self.converter:
logger.info("Cleaning up temporary files")
self.converter.clean_up()
if __name__ == "__main__":
Transcriber("samples/bruce.mp3")