Minor improvements & docs added
This commit is contained in:
@@ -13,5 +13,4 @@ main.todo
|
|||||||
sample.mp3
|
sample.mp3
|
||||||
*.spec
|
*.spec
|
||||||
|
|
||||||
# лютый завоз
|
|
||||||
ui/assets/question_mark.png
|
ui/assets/question_mark.png
|
||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
name: notecast
|
|
||||||
channels:
|
|
||||||
- pytorch
|
|
||||||
- conda-forge
|
|
||||||
- defaults
|
|
||||||
dependencies:
|
|
||||||
- python=3.10
|
|
||||||
- pytorch::pytorch=2.0.1
|
|
||||||
- pytorch::torchvision=0.15.2
|
|
||||||
- pytorch::torchaudio=2.0.2
|
|
||||||
- transformers=4.30.0
|
|
||||||
- accelerate=0.20.0
|
|
||||||
- ffmpeg
|
|
||||||
- pyinstaller
|
|
||||||
- customtkinter
|
|
||||||
- isort
|
|
||||||
- mypy
|
|
||||||
- black
|
|
||||||
- tqdm
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
name: notecast
|
|
||||||
channels:
|
|
||||||
- pytorch
|
|
||||||
- nvidia
|
|
||||||
- conda-forge
|
|
||||||
- bioconda
|
|
||||||
dependencies:
|
|
||||||
- pytorch
|
|
||||||
- ffmpeg
|
|
||||||
- torchvision
|
|
||||||
- torchaudio
|
|
||||||
- transformers
|
|
||||||
- python=3.12
|
|
||||||
- customtkinter
|
|
||||||
- openai
|
|
||||||
-19
@@ -1,19 +0,0 @@
|
|||||||
name: notecast
|
|
||||||
channels:
|
|
||||||
- pytorch
|
|
||||||
- conda-forge
|
|
||||||
- defaults
|
|
||||||
dependencies:
|
|
||||||
- python=3.10
|
|
||||||
- pytorch::pytorch=2.0.1
|
|
||||||
- pytorch::torchvision=0.15.2
|
|
||||||
- pytorch::torchaudio=2.0.2
|
|
||||||
- transformers=4.30.0
|
|
||||||
- accelerate=0.20.0
|
|
||||||
- ffmpeg
|
|
||||||
- pyinstaller
|
|
||||||
- customtkinter
|
|
||||||
- isort
|
|
||||||
- mypy
|
|
||||||
- black
|
|
||||||
- tqdm
|
|
||||||
@@ -15,7 +15,54 @@ from ui.ui_log_handler import UILogHandler
|
|||||||
|
|
||||||
# TODO: implement transcription with shift
|
# TODO: implement transcription with shift
|
||||||
class AudioTranscription:
|
class AudioTranscription:
|
||||||
model_name = "openai/whisper-large-v2"
|
"""
|
||||||
|
Class for automatical audio transcription using Whisper.
|
||||||
|
|
||||||
|
Provides audio file loading, resampling, conversion to mono,
|
||||||
|
splitting into chunks and batches, running the model, and compiling the final text.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
model_name (str): Whisper model name in HuggingFace.
|
||||||
|
filepath (str): Input filepath.
|
||||||
|
waveform (torch.Tensor): Audiosignal in tensor form.
|
||||||
|
sampling_rate (int): Input file's sampling frequency.
|
||||||
|
chunks (list): Audio's chunks list.
|
||||||
|
batches (list): Batches combined from chunks.
|
||||||
|
chunk_size (int): Chunk size in samples.
|
||||||
|
custom_chunk_length (int): Custom chunk length (in seconds).
|
||||||
|
custom_batch_length (int): Custom batch length (in chunks).
|
||||||
|
device (str): Inference device ("cuda", "cpu", "mps").
|
||||||
|
processor (WhisperProcessor | None): Tokenizator/preprocessor.
|
||||||
|
model (WhisperForConditionalGeneration | None): Whisper model.
|
||||||
|
logger (logging.Logger): Logger.
|
||||||
|
torch_dtype (torch.dtype): Data type for calculations (fp16/fp32).
|
||||||
|
language (str): Transcription language (default "ru").
|
||||||
|
all_transcription (list): List of strings with transcription.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
filepath (str): Input filepath.
|
||||||
|
device_configuration (DeviceConfiguration): Device configuration
|
||||||
|
(GPU/CPU/MPS, model, chunk length, batch etc.).
|
||||||
|
logger (logging.Logger): Logger.
|
||||||
|
language (str, optional): Transcription language. Default "ru".
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>>> from transcription.device_configuration import DeviceConfiguration
|
||||||
|
>>> import logging
|
||||||
|
>>> config = DeviceConfiguration(device="cuda", model_name="openai/whisper-large-v3-turbo") # recheck this, not true i think
|
||||||
|
>>> logger = logging.getLogger("transcription")
|
||||||
|
>>> transcriber = AudioTranscription("audio.wav", config, logger, language="en")
|
||||||
|
>>> text = transcriber.transcribe_audio()
|
||||||
|
>>> print(text)
|
||||||
|
"This is a test audio transcription."
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
transcribe_audio() -> str:
|
||||||
|
Starts full transcription pipeline: model loading,
|
||||||
|
file loading and preprocessing, splitting into chunks/batches,
|
||||||
|
inference and model unloading. Returns the final transcription.
|
||||||
|
"""
|
||||||
|
model_name = "openai/whisper-large-v3-turbo"
|
||||||
|
|
||||||
filepath: str
|
filepath: str
|
||||||
waveform: torch.Tensor
|
waveform: torch.Tensor
|
||||||
@@ -93,12 +140,14 @@ class AudioTranscription:
|
|||||||
def _load_file(self) -> None:
|
def _load_file(self) -> None:
|
||||||
self.logger.info(f"Loading file {self.filepath}")
|
self.logger.info(f"Loading file {self.filepath}")
|
||||||
try:
|
try:
|
||||||
self.waveform, self.sampling_rate = torchaudio.load(
|
# self.waveform, self.sampling_rate = torchaudio.load(
|
||||||
self.filepath, format=self.file_format, backend="ffmpeg"
|
# self.filepath, format=self.file_format, backend="ffmpeg"
|
||||||
)
|
# )
|
||||||
|
self.waveform, self.sampling_rate = torchaudio.load(self.filepath)
|
||||||
self.logger.info(f"Successfully loaded file {self.filepath}.")
|
self.logger.info(f"Successfully loaded file {self.filepath}.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Unable to load file {self.filepath}: {e}")
|
self.logger.error(f"Unable to load file {self.filepath}: {e}")
|
||||||
|
# raise RuntimeError(f"Failed to load file {self.filepath}: {e}")
|
||||||
|
|
||||||
def _resample(self) -> None:
|
def _resample(self) -> None:
|
||||||
self.waveform = torchaudio.functional.resample(
|
self.waveform = torchaudio.functional.resample(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class DeviceConfiguration:
|
|||||||
- "openai/whisper-medium"
|
- "openai/whisper-medium"
|
||||||
- "openai/whisper-large"
|
- "openai/whisper-large"
|
||||||
- "openai/whisper-large-v2"
|
- "openai/whisper-large-v2"
|
||||||
|
- "openai/whisper-large-v3-turbo"
|
||||||
|
|
||||||
batch_size (int): Chunks in one batch. Selected for VRAM.
|
batch_size (int): Chunks in one batch. Selected for VRAM.
|
||||||
|
|
||||||
@@ -24,8 +25,8 @@ class DeviceConfiguration:
|
|||||||
|
|
||||||
data_type (str): custom data type of model. Variants:
|
data_type (str): custom data type of model. Variants:
|
||||||
- torch.float16 - for GPUs
|
- torch.float16 - for GPUs
|
||||||
- torch.float32 - for CPU / weak GPU
|
- torch.float32 - for CPU
|
||||||
- torch.bfloat16 - for GPUs which has BF16 support
|
- torch.bfloat16 - for GPUs which has BF16 support (usually RTX 40XX+)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
device: str = "cuda"
|
device: str = "cuda"
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ class TranscriberApp(ctk.CTk):
|
|||||||
self.device_var = tk.StringVar(value=device_opts[0])
|
self.device_var = tk.StringVar(value=device_opts[0])
|
||||||
self.device_opts = device_opts
|
self.device_opts = device_opts
|
||||||
|
|
||||||
|
# input & output file variables
|
||||||
self.input_file_var = tk.StringVar()
|
self.input_file_var = tk.StringVar()
|
||||||
self.output_file_var = tk.StringVar()
|
self.output_file_var = tk.StringVar()
|
||||||
|
|
||||||
@@ -218,7 +219,6 @@ class TranscriberApp(ctk.CTk):
|
|||||||
tooltip="Choose model for speed recognition",
|
tooltip="Choose model for speed recognition",
|
||||||
variable=self.model_var,
|
variable=self.model_var,
|
||||||
values=[
|
values=[
|
||||||
# maybe delete this option?
|
|
||||||
"openai/whisper-large-v3-turbo",
|
"openai/whisper-large-v3-turbo",
|
||||||
"openai/whisper-large-v2",
|
"openai/whisper-large-v2",
|
||||||
"openai/whisper-large",
|
"openai/whisper-large",
|
||||||
@@ -257,7 +257,7 @@ class TranscriberApp(ctk.CTk):
|
|||||||
text="Chunk length (s):",
|
text="Chunk length (s):",
|
||||||
tooltip="Maximum length of processing audio fragment",
|
tooltip="Maximum length of processing audio fragment",
|
||||||
variable=self.chunk_var,
|
variable=self.chunk_var,
|
||||||
values=["30", "25", "20", "15", "10", "5"],
|
values=["30", "24", "20", "14", "10", "6"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# third row
|
# third row
|
||||||
|
|||||||
Reference in New Issue
Block a user