Increase the size of the rolling window to display 10 seconds of data
This commit is contained in:
parent
7d567a2068
commit
c98424cbc6
@ -27,6 +27,7 @@ classifiers = [
|
||||
dependencies = [
|
||||
"matplotlib",
|
||||
"numpy",
|
||||
"rich",
|
||||
"sounddevice",
|
||||
"FreeSimpleGUI"
|
||||
]
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user