From c98424cbc67cc6a44cdb7c7ffaf6c636f79e0d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=A9=20Cassiop=C3=A9e=20Gauthier?= Date: Fri, 8 Nov 2024 16:35:26 -0500 Subject: [PATCH] Increase the size of the rolling window to display 10 seconds of data --- pyproject.toml | 1 + src/voice_lab/main.py | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 729fa02..a8f6bf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ classifiers = [ dependencies = [ "matplotlib", "numpy", + "rich", "sounddevice", "FreeSimpleGUI" ] diff --git a/src/voice_lab/main.py b/src/voice_lab/main.py index c0f7b1e..5ae8f4d 100644 --- a/src/voice_lab/main.py +++ b/src/voice_lab/main.py @@ -6,24 +6,32 @@ import argparse from functools import partial +import logging import queue +import sys from typing import cast, Any from matplotlib.animation import FuncAnimation import matplotlib.pyplot as plt import numpy as np +from rich.logging import RichHandler import sounddevice as sd q = queue.Queue() -window = 200 -downsample = 10 +window = 10000 +downsample = 100 + +logging.basicConfig( + level=logging.INFO, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()] +) +log = logging.getLogger() def audio_callback(indata, _frames, _time, status): if status: - print(status) + log.error(status) q.put(indata[::downsample, 0].copy()) @@ -52,8 +60,8 @@ def main(): parser.add_argument("-l", "--list-devices", action="store_true") args, remaining = parser.parse_known_args() if args.list_devices: - print(sd.query_devices()) - parser.exit(0) + log.info(sd.query_devices()) + return 0 parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, parents=[parser] ) @@ -61,6 +69,10 @@ def main(): args = parser.parse_args(remaining) device_info = cast(dict[str, Any], sd.query_devices(args.device, "input")) + log.info( + "Selected input device: %(name)s [sample rate %(default_samplerate)d]", + device_info, + ) samplerate = device_info["default_samplerate"] length = int(window * samplerate / (1000 * downsample)) @@ -87,12 +99,14 @@ def main(): _ani = FuncAnimation( fig, partial(update_plot, lines=lines, plotdata=plotdata), - interval=30, + interval=10, blit=True, + cache_frame_data=False, ) with stream: plt.show() + return 0 if __name__ == "__main__": - main() + sys.exit(main())