diff --git a/main.py b/main.py index f4c2d64..862175b 100644 --- a/main.py +++ b/main.py @@ -6,10 +6,6 @@ import soundfile as sf import numpy as np import time from PyQt6.QtGui import QAction, QPen -from PyQt6.QtCore import Qt, QTimer -import sounddevice as sd -import soundfile as sf -import numpy as np class MainWindow(QMainWindow): def __init__(self): @@ -211,6 +207,24 @@ class MainWindow(QMainWindow): outdata[chunksize:].fill(0) self.playback_pos += chunksize + def update_time_label(self): + if self.audio_data is None: + self.time_label.setText("00:00 / 00:00") + return + + current_time = self.playback_pos / self.sample_rate + total_time = len(self.audio_data) / self.sample_rate + + current_time_str = self.format_time(current_time) + total_time_str = self.format_time(total_time) + + self.time_label.setText(f"{current_time_str} / {total_time_str}") + + def format_time(self, time_seconds): + minutes = int(time_seconds // 60) + seconds = int(time_seconds % 60) + return f"{minutes:02}:{seconds:02}" + if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow()