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 = [
|
dependencies = [
|
||||||
"matplotlib",
|
"matplotlib",
|
||||||
"numpy",
|
"numpy",
|
||||||
|
"rich",
|
||||||
"sounddevice",
|
"sounddevice",
|
||||||
"FreeSimpleGUI"
|
"FreeSimpleGUI"
|
||||||
]
|
]
|
||||||
|
@ -6,24 +6,32 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
import logging
|
||||||
import queue
|
import queue
|
||||||
|
import sys
|
||||||
from typing import cast, Any
|
from typing import cast, Any
|
||||||
|
|
||||||
from matplotlib.animation import FuncAnimation
|
from matplotlib.animation import FuncAnimation
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from rich.logging import RichHandler
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
|
|
||||||
|
|
||||||
q = queue.Queue()
|
q = queue.Queue()
|
||||||
|
|
||||||
window = 200
|
window = 10000
|
||||||
downsample = 10
|
downsample = 100
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()]
|
||||||
|
)
|
||||||
|
log = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def audio_callback(indata, _frames, _time, status):
|
def audio_callback(indata, _frames, _time, status):
|
||||||
if status:
|
if status:
|
||||||
print(status)
|
log.error(status)
|
||||||
q.put(indata[::downsample, 0].copy())
|
q.put(indata[::downsample, 0].copy())
|
||||||
|
|
||||||
|
|
||||||
@ -52,8 +60,8 @@ def main():
|
|||||||
parser.add_argument("-l", "--list-devices", action="store_true")
|
parser.add_argument("-l", "--list-devices", action="store_true")
|
||||||
args, remaining = parser.parse_known_args()
|
args, remaining = parser.parse_known_args()
|
||||||
if args.list_devices:
|
if args.list_devices:
|
||||||
print(sd.query_devices())
|
log.info(sd.query_devices())
|
||||||
parser.exit(0)
|
return 0
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter, parents=[parser]
|
formatter_class=argparse.RawDescriptionHelpFormatter, parents=[parser]
|
||||||
)
|
)
|
||||||
@ -61,6 +69,10 @@ def main():
|
|||||||
args = parser.parse_args(remaining)
|
args = parser.parse_args(remaining)
|
||||||
|
|
||||||
device_info = cast(dict[str, Any], sd.query_devices(args.device, "input"))
|
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"]
|
samplerate = device_info["default_samplerate"]
|
||||||
|
|
||||||
length = int(window * samplerate / (1000 * downsample))
|
length = int(window * samplerate / (1000 * downsample))
|
||||||
@ -87,12 +99,14 @@ def main():
|
|||||||
_ani = FuncAnimation(
|
_ani = FuncAnimation(
|
||||||
fig,
|
fig,
|
||||||
partial(update_plot, lines=lines, plotdata=plotdata),
|
partial(update_plot, lines=lines, plotdata=plotdata),
|
||||||
interval=30,
|
interval=10,
|
||||||
blit=True,
|
blit=True,
|
||||||
|
cache_frame_data=False,
|
||||||
)
|
)
|
||||||
with stream:
|
with stream:
|
||||||
plt.show()
|
plt.show()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
sys.exit(main())
|
||||||
|
Loading…
Reference in New Issue
Block a user