import math import pydub import webbrowser from PyQt5.QtWidgets import QProgressBar, QApplication, QMainWindow, QAction, QMessageBox from typing import Union from datatypes import AppSettings, OperationMode from utilities.logger import setup_custom_logger from utilities.settings import load_system_settings, system_settings_exist, save_system_settings from widgets.session import SessionManager from widgets.converter import ConverterWidget from windows.about import AboutWindow, ONLINE_DOCS from windows.project import ProjectDetailsWindow from windows.settings import SettingsWindow LOG_PRIMARY = setup_custom_logger("Primary") class ProgressBarWidget(QProgressBar): """ Custom progress bar for showing the progress of exporting transcription/translation/image/sound files. """ def __init__(self, app: QApplication) -> None: super().__init__() self.app = app self.setMaximum(100) self.setMinimum(0) self.setValue(0) def update_progress(self, value: Union[float, int]) -> None: self.setValue(math.ceil(value * 100)) self.app.processEvents()
from PyQt5.QtWidgets import QDialog, QFileDialog, QGridLayout, QLabel, QLayout, QPushButton, QWidget from PyQt5.QtCore import Qt, QSize from PyQt5.QtGui import QIcon from pygame import mixer from pygame import error as pygerror from utilities.files import resource_path from utilities.record import SimpleAudioRecorder from utilities.logger import setup_custom_logger from datatypes import Transcription, ConverterData, AppSettings from typing import Callable LOG_RECORD_WINDOW = setup_custom_logger("Record Window") class RecordWindow(QDialog): def __init__(self, parent: QWidget, transcription: Transcription, data: ConverterData, update_button: Callable, settings: AppSettings) -> None: super().__init__(parent) self.update_button = update_button self.transcription = transcription self.data = data self.settings = settings self.layout = QGridLayout() self.record_button = QPushButton() self.preview_button = QPushButton('Play Audio') self.recording = False self.output = None self.init_ui() self.recorder = SimpleAudioRecorder(self.data, self.transcription, self.settings)
QPushButton, QLineEdit from PyQt5.QtCore import QThread, QTimer, QEventLoop from PyQt5.QtGui import QFont from box import Box from datatypes import create_lmf, ConverterData, Transcription from datetime import datetime from enum import Enum from utilities.logger import setup_custom_logger from widgets.table import TABLE_COLUMNS from widgets.warning import WarningMessage ################################################################################ # Save/Load Functionality ################################################################################ LOG_SESSION = setup_custom_logger("Session Manager") LOG_AUTOSAVE = setup_custom_logger("Autosave Thread") class SessionManager(object): """ Session Manager handles session operations, providing functionality for Save, Save As, and Open. """ def __init__(self, parent: QMainWindow): self._file_dialog = QFileDialog() self.parent = parent # Converter widget that runs hermes' main operations, set in Primary after initialisation of all elements. self.converter = None # Project Parameters/Paths
app_settings.microphone = system_settings.value('Microphone') app_settings.project_root_dir = system_settings.value('Project Root Dir') if system_settings.contains('FFMPEG Location'): location = system_settings.value('FFMPEG Location') if location == 'None': app_settings.ffmpeg_location = None else: # Test if exists? app_settings.ffmpeg_location = location return app_settings def save_system_settings(app_settings: AppSettings) -> None: system_settings = get_settings() system_settings.setValue('Audio Quality', AUDIO_QUALITY_REV[app_settings.audio_quality]) system_settings.setValue('Output Format', app_settings.output_format.value) system_settings.setValue('Microphone', app_settings.microphone) system_settings.setValue('FFMPEG Location', str(app_settings.ffmpeg_location)) system_settings.setValue('Project Root Dir', str(app_settings.project_root_dir)) system_settings.sync() print_system_settings() def set_ffmpeg_location(app_settings: AppSettings, path: str) -> None: app_settings.ffmpeg_location = path save_system_settings(app_settings) pydub.AudioSegment.converter = path LOG_SETTINGS = setup_custom_logger("SettingsUtil")
import os from typing import Union from PyQt5.QtCore import QUrl from PyQt5.QtMultimedia import QMultimedia, QAudioEncoderSettings, QVideoEncoderSettings, QAudioRecorder from datatypes import AppSettings, Transcription, ConverterData from utilities.logger import setup_custom_logger LOG_RECORDER = setup_custom_logger("Audio Recorder") class SimpleAudioRecorder(QAudioRecorder): def __init__(self, data: ConverterData, transcription: Transcription, app_settings: AppSettings) -> None: super().__init__() self.app_settings = app_settings self.temp = data.get_temp_file() self.transcription = transcription self.file_path = os.path.join(self.temp, f'{self.transcription.id}.wav') self.settings = QAudioEncoderSettings() def start_recording(self) -> None: LOG_RECORDER.info("Audio recording started.") self.settings.setCodec('audio/pcm') self.settings.setChannelCount(1) self.settings.setBitRate(96000) self.settings.setSampleRate(44100) self.settings.setQuality(self.app_settings.audio_quality) self.settings.setEncodingMode(QMultimedia.ConstantQualityEncoding) container = 'audio/x-wav' self.setEncodingSettings(self.settings, QVideoEncoderSettings(),
import pympi import json from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel, QFrame, QLineEdit from PyQt5.QtGui import QDesktopServices, QFont from PyQt5.QtCore import QUrl from datatypes import OperationMode, Transcription, ConverterData, AppSettings, OutputMode, ConverterComponents from utilities.output import create_opie_files, create_dict_files, create_lmf_files from utilities.parse import get_audio_file, extract_elan_data from utilities.logger import setup_custom_logger from widgets.mode import MainProjectSelection, ModeSelection from widgets.elan_import import ELANFileField, TierSelector from widgets.table import TABLE_COLUMNS, FilterTable from widgets.export import ExportLocationField, ExportButton from windows.manifest import ManifestWindow LOG_CONVERTER = setup_custom_logger("Converter Widget") BASE_MARGIN = 10 class ConverterWidget(QWidget): """ The core widget of the application which contains all of the widgets required to convert ELAN files. Manages the process flow of the Hermes app, initialised by primary window. """ def __init__(self, parent: QWidget, settings: AppSettings) -> None: super().__init__() self.parent = parent self.settings = settings self.session = parent.session
from PyQt5.QtWidgets import QWidget, QGridLayout, QPushButton, QMessageBox, QLineEdit, QFileDialog from typing import NewType from os import listdir from utilities.logger import setup_custom_logger from widgets.warning import WarningMessage LOG_EXPORT = setup_custom_logger("Export") ConverterWidget = NewType('ConverterWidget', QWidget) class ExportLocationField(QWidget): def __init__(self, parent: ConverterWidget) -> None: super().__init__() self.layout = QGridLayout() self.parent = parent self.data = parent.data self.export_location_field = None self.export_dialog = QFileDialog() self.init_ui() def init_ui(self) -> None: self.export_location_field = QLineEdit('Choose an export location') self.export_location_field.setReadOnly(True) self.layout.addWidget(self.export_location_field, 0, 0, 1, 7) choose_export_button = QPushButton('Choose') choose_export_button.clicked.connect(self.on_click_choose_export) self.layout.addWidget(choose_export_button, 0, 7, 1, 1) self.setLayout(self.layout) def on_click_choose_export(self) -> None:
from box import Box from PyQt5.QtWidgets import QGridLayout, QLabel, QLineEdit, QPushButton, QMainWindow, QDialog from utilities.logger import setup_custom_logger from widgets.session import SessionManager LOG_PROJECT_WINDOW = setup_custom_logger("Project Details Window") class ProjectDetailsWindow(QDialog): def __init__(self, parent: QMainWindow, session: SessionManager): super().__init__(parent) self.session = session self.layout = QGridLayout() self.widgets = Box() self.init_ui() def init_ui(self): self.setWindowTitle('Project Details') self.setMinimumWidth(300) instruction_label = QLabel( 'Hit save to record any changes to project details.') self.layout.addWidget(instruction_label, 0, 0, 1, 7) transcription_language_label = QLabel('Transcription Language:') self.layout.addWidget(transcription_language_label, 1, 0, 1, 1) self.widgets.transcription_language_field = QLineEdit() self.widgets.transcription_language_field.setText( self.session.data_transcription_language) self.layout.addWidget(self.widgets.transcription_language_field, 1, 1, 1, 7)