diff --git a/sclat/gui/addon/fft.py b/sclat/gui/addon/fft.py index c427068..333a742 100644 --- a/sclat/gui/addon/fft.py +++ b/sclat/gui/addon/fft.py @@ -10,14 +10,14 @@ def run(audio_data): audio_index = int(screen.vid.get_pos() / screen.vid.duration * len(audio_data)) + if audio_index >= len(audio_data): + audio_index = len(audio_data) if audio_index + buffer_size < len(audio_data): audio_chunk = audio_data[audio_index:audio_index + buffer_size] else: audio_chunk = audio_data[audio_index:] fft_data = np.fft.fft(audio_chunk) audio_index += buffer_size - if audio_index >= len(audio_data): - audio_index = 0 plot_spectrum(fft_data, audio_chunk) def plot_spectrum(fft_data, audio_chunk): diff --git a/sclat/gui/gui.py b/sclat/gui/gui.py index 039cd8c..4d3116f 100644 --- a/sclat/gui/gui.py +++ b/sclat/gui/gui.py @@ -7,13 +7,16 @@ from typing import Optional from gui import screen, cache from gui.addon import ascii, subtitle, with_play, fft -from gui.addon.control import gesture, stt import gui.font from download import download, subtitles from sockets import client, server from sockets import setting as socket_setting from setting import setting as user_setting import discord_rpc.client +if user_setting.stt: + from gui.addon.control import stt +if user_setting.Gesture or user_setting.Gesture_show: + from gui.addon.control import gesture # Global state @dataclass @@ -82,6 +85,10 @@ def handle_key_event(key: str) -> None: case "l": cache.loop = not cache.loop state.msg_text = f"Loop: {'On' if cache.loop else 'Off'}" + case "f": + user_setting.FFT = not user_setting.FFT + user_setting.change_setting_data('FFT', user_setting.FFT) + state.msg_text = f"FFT: {user_setting.FFT}" case "up" | "down": volume_delta = 10 if key == "up" else -10 if 0 <= user_setting.volume + volume_delta <= 100: diff --git a/sclat/sclat.py b/sclat/sclat.py index 02eb6c3..73f8977 100644 --- a/sclat/sclat.py +++ b/sclat/sclat.py @@ -1,7 +1,6 @@ import sys,time from gui import gui, nogui, screen, cache from gui.addon import with_play -from gui.addon.control import stt from pypresence.exceptions import DiscordNotFound from setting import setting as user_setting import discord_rpc.client