slm_open_api_package 0.2.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- slm_open_api_package-0.2.10/PKG-INFO +206 -0
- slm_open_api_package-0.2.10/README.md +186 -0
- slm_open_api_package-0.2.10/pyproject.toml +33 -0
- slm_open_api_package-0.2.10/pyproject.toml.orig +32 -0
- slm_open_api_package-0.2.10/src/slm_api/CPB_example.py +74 -0
- slm_open_api_package-0.2.10/src/slm_api/__init__.py +5 -0
- slm_open_api_package-0.2.10/src/slm_api/enums/fast_log_intervals_enum.py +16 -0
- slm_open_api_package-0.2.10/src/slm_api/enums/sequence_id_enum.py +352 -0
- slm_open_api_package-0.2.10/src/slm_api/example_multi.py +78 -0
- slm_open_api_package-0.2.10/src/slm_api/fast_log_example.py +172 -0
- slm_open_api_package-0.2.10/src/slm_api/flac_example.py +164 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/FigureHandler.py +65 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/Leq.py +87 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/__init__.py +5 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/buffer.py +27 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/data_handler.py +94 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/fft.py +38 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/flac_stream_2_samples.py +64 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/https_requests.py +79 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/measurment_handler.py +20 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/sequence_handler.py +43 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/stream_handler.py +105 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/stream_handlers.py +434 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/tmpFileStateMachine.py +93 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/websocket_handler.py +12 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/webxi_helper_functions.py +79 -0
- slm_open_api_package-0.2.10/src/slm_api/helpers/webxi_root.pem +24 -0
- slm_open_api_package-0.2.10/src/slm_api/mp3_example.py +165 -0
- slm_open_api_package-0.2.10/src/slm_api/multi_device_flac.py +105 -0
- slm_open_api_package-0.2.10/src/slm_api/multi_instrument_example.py +74 -0
- slm_open_api_package-0.2.10/src/slm_api/screen_record_example.py +64 -0
- slm_open_api_package-0.2.10/src/slm_api/webxi/README.md +25 -0
- slm_open_api_package-0.2.10/src/slm_api/webxi/__init__.py +5 -0
- slm_open_api_package-0.2.10/src/slm_api/webxi/webxi-header.ksy +32 -0
- slm_open_api_package-0.2.10/src/slm_api/webxi/webxi-stream.ksy +342 -0
- slm_open_api_package-0.2.10/src/slm_api/webxi/webxi_header.py +42 -0
- slm_open_api_package-0.2.10/src/slm_api/webxi/webxi_stream.py +450 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: slm_open_api_package
|
|
3
|
+
Version: 0.2.10
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author: Sofus Vingaard
|
|
6
|
+
Author-email: Sofus Vingaard <sofus.krebsvingaard@hbkworld.com>
|
|
7
|
+
Requires-Dist: requests
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Requires-Dist: websockets
|
|
10
|
+
Requires-Dist: kaitaistruct
|
|
11
|
+
Requires-Dist: packaging
|
|
12
|
+
Requires-Dist: pyqtgraph
|
|
13
|
+
Requires-Dist: pyqt5
|
|
14
|
+
Requires-Dist: pyqt5-qt5<5.15.11
|
|
15
|
+
Requires-Dist: miniaudio
|
|
16
|
+
Requires-Dist: matplotlib>=3.11.1
|
|
17
|
+
Requires-Dist: cryptography>=50.0.1
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# SLM Open API Package
|
|
22
|
+
|
|
23
|
+
Python helpers for streaming measurements and audio from an HBK sound level meter (SLM) through WebXi.
|
|
24
|
+
|
|
25
|
+
This PyPI package is made for the [Open Interface for Sound Level Meter](https://github.com/hbkworld/Open-Interface-for-Sound-Level-Meter) repository. Refer to that repository for more detailed usage information and additional examples.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```powershell
|
|
32
|
+
pip install slm_open_api_package
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or add it to an `uv` project:
|
|
36
|
+
|
|
37
|
+
```powershell
|
|
38
|
+
uv add slm_open_api_package
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The package requires Python 3.12 or newer and a network connection to a compatible SLM.
|
|
42
|
+
|
|
43
|
+
## Connect To A Device
|
|
44
|
+
|
|
45
|
+
Give every stream one `host`, either an IP address or host name:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
host = "192.168.1.183"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The bundled examples use `set_host()` to read a host from a local `slm_ip` file. If the file is missing, it prompts once and creates it:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from slm_api.helpers import webxi_helper_functions as webxi_helper
|
|
55
|
+
|
|
56
|
+
host = webxi_helper.set_host(__file__)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Basic Leq Stream
|
|
60
|
+
|
|
61
|
+
`WebXiStreamHandler` is the main API. `mode="leq"` is the default and streams one sequence selected by `sequenceID`.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
65
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
66
|
+
|
|
67
|
+
streamer = WebXiStreamHandler(
|
|
68
|
+
host="192.168.1.183",
|
|
69
|
+
sequenceID=SequenceIdEnums.LAeq.value,
|
|
70
|
+
mode="leq",
|
|
71
|
+
saving="csv",
|
|
72
|
+
saving_path="saved_data/laeq",
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
streamer.startStream()
|
|
77
|
+
except KeyboardInterrupt:
|
|
78
|
+
streamer.stopStream()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`stopStream()` stops the measurement, removes the device stream, and writes buffered saved data. Supported saving formats are `"csv"`, `"json"`, and `"pickle"`; their extensions are added automatically.
|
|
82
|
+
|
|
83
|
+
## Multiple Sequences
|
|
84
|
+
|
|
85
|
+
Based on [example_multi.py](src/slm_api/example_multi.py), use `mode="multi"` for several enabled broadband sequences in a single stream:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from slm_api.helpers.data_handler import DataHandler
|
|
89
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class PrintHandler(DataHandler):
|
|
93
|
+
def handle(self, *, host, name, value, **data):
|
|
94
|
+
print(f"{host} {name}: {value}")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
streamer = WebXiStreamHandler(
|
|
98
|
+
host="192.168.1.183",
|
|
99
|
+
sequenceNames=["LAeq", "LCeq", "LAF"],
|
|
100
|
+
mode="multi",
|
|
101
|
+
saving="json",
|
|
102
|
+
saving_path="saved_data/broadband",
|
|
103
|
+
)
|
|
104
|
+
streamer.setDataHandler(PrintHandler())
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
streamer.startStream()
|
|
108
|
+
except KeyboardInterrupt:
|
|
109
|
+
streamer.stopStream()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Enable the requested sequences and frequency weightings on the SLM before starting the stream. Each `DataHandler.handle()` call receives the source `host`, `name`, and `value`. The `saving=` handler continues saving when a custom handler is attached.
|
|
113
|
+
|
|
114
|
+
## Fast Logging
|
|
115
|
+
|
|
116
|
+
Based on [fast_log_example.py](src/slm_api/fast_log_example.py), use `mode="fast_logging"` for fast broadband samples:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from slm_api.enums.fast_log_intervals_enum import FastLogInterval
|
|
120
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
121
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
122
|
+
|
|
123
|
+
streamer = WebXiStreamHandler(
|
|
124
|
+
host="192.168.1.183",
|
|
125
|
+
sequenceID=SequenceIdEnums.FastLAF.value,
|
|
126
|
+
mode="fast_logging",
|
|
127
|
+
fast_logging_interval=FastLogInterval.interval_1000ms.value,
|
|
128
|
+
saving="csv",
|
|
129
|
+
saving_path="saved_data/fast_laf",
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
streamer.startStream()
|
|
134
|
+
except KeyboardInterrupt:
|
|
135
|
+
streamer.stopStream()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Audio
|
|
139
|
+
|
|
140
|
+
Use the MP3 or FLAC examples for decoded audio samples:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
144
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
145
|
+
|
|
146
|
+
streamer = WebXiStreamHandler(
|
|
147
|
+
host="192.168.1.183",
|
|
148
|
+
sequenceID=SequenceIdEnums.MP3Signal.value,
|
|
149
|
+
mode="mp3",
|
|
150
|
+
)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The matching `flac` form uses `SequenceIdEnums.FLACSignal.value` and `mode="flac"`. Audio setup is enabled by the handler. The SLM can take a few seconds to initialize audio recording when its quality setting changes.
|
|
154
|
+
|
|
155
|
+
## Synchronized Multi-Device Stream
|
|
156
|
+
|
|
157
|
+
Based on [multi_device_flac.py](src/slm_api/multi_device_flac.py), pass `multi_device=True` and start/stop the group through the synchronized helpers:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
161
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler, start_all_synced, stop_all
|
|
162
|
+
|
|
163
|
+
hosts = ["192.168.1.183", "192.168.1.216"]
|
|
164
|
+
streams = [
|
|
165
|
+
WebXiStreamHandler(
|
|
166
|
+
host=host,
|
|
167
|
+
sequenceID=SequenceIdEnums.MP3Signal.value,
|
|
168
|
+
mode="mp3",
|
|
169
|
+
streamName=f"Audio_{host}",
|
|
170
|
+
multi_device=True,
|
|
171
|
+
saving="csv",
|
|
172
|
+
saving_path=f"saved_data/{host}",
|
|
173
|
+
)
|
|
174
|
+
for host in hosts
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
start_all_synced(streams)
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
while True:
|
|
181
|
+
time.sleep(1)
|
|
182
|
+
except KeyboardInterrupt:
|
|
183
|
+
stop_all(streams)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
`stop_all()` synchronizes the device measurement stops, flushes saving handlers, and removes each device stream.
|
|
187
|
+
|
|
188
|
+
## Modes
|
|
189
|
+
|
|
190
|
+
| Mode | Use |
|
|
191
|
+
| --- | --- |
|
|
192
|
+
| `"leq"` | One broadband sequence; this is the default. |
|
|
193
|
+
| `"multi"` | Several named broadband sequences. |
|
|
194
|
+
| `"cpb"` | Constant-percentage-band data. |
|
|
195
|
+
| `"fast_logging"` | Fast broadband samples. |
|
|
196
|
+
| `"flac"` / `"mp3"` | Decoded audio samples. |
|
|
197
|
+
| `"screen_record"` | Latest SLM screen image in `streamer.image_bytes`. |
|
|
198
|
+
|
|
199
|
+
Legacy flags such as `mp3=True` remain supported, but `mode=` is preferred. Only select one mode per stream.
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Troubleshooting
|
|
203
|
+
|
|
204
|
+
- **No values arrive:** Confirm the requested sequences are enabled on the SLM.
|
|
205
|
+
- **Audio returns no samples after first enable:** Allow the SLM a few seconds to initialize audio recording before retrying.
|
|
206
|
+
- **Saved file is missing:** Call `stopStream()` or `stop_all()`; buffered files are written during shutdown.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# SLM Open API Package
|
|
2
|
+
|
|
3
|
+
Python helpers for streaming measurements and audio from an HBK sound level meter (SLM) through WebXi.
|
|
4
|
+
|
|
5
|
+
This PyPI package is made for the [Open Interface for Sound Level Meter](https://github.com/hbkworld/Open-Interface-for-Sound-Level-Meter) repository. Refer to that repository for more detailed usage information and additional examples.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```powershell
|
|
12
|
+
pip install slm_open_api_package
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or add it to an `uv` project:
|
|
16
|
+
|
|
17
|
+
```powershell
|
|
18
|
+
uv add slm_open_api_package
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The package requires Python 3.12 or newer and a network connection to a compatible SLM.
|
|
22
|
+
|
|
23
|
+
## Connect To A Device
|
|
24
|
+
|
|
25
|
+
Give every stream one `host`, either an IP address or host name:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
host = "192.168.1.183"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The bundled examples use `set_host()` to read a host from a local `slm_ip` file. If the file is missing, it prompts once and creates it:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from slm_api.helpers import webxi_helper_functions as webxi_helper
|
|
35
|
+
|
|
36
|
+
host = webxi_helper.set_host(__file__)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Basic Leq Stream
|
|
40
|
+
|
|
41
|
+
`WebXiStreamHandler` is the main API. `mode="leq"` is the default and streams one sequence selected by `sequenceID`.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
45
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
46
|
+
|
|
47
|
+
streamer = WebXiStreamHandler(
|
|
48
|
+
host="192.168.1.183",
|
|
49
|
+
sequenceID=SequenceIdEnums.LAeq.value,
|
|
50
|
+
mode="leq",
|
|
51
|
+
saving="csv",
|
|
52
|
+
saving_path="saved_data/laeq",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
streamer.startStream()
|
|
57
|
+
except KeyboardInterrupt:
|
|
58
|
+
streamer.stopStream()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`stopStream()` stops the measurement, removes the device stream, and writes buffered saved data. Supported saving formats are `"csv"`, `"json"`, and `"pickle"`; their extensions are added automatically.
|
|
62
|
+
|
|
63
|
+
## Multiple Sequences
|
|
64
|
+
|
|
65
|
+
Based on [example_multi.py](src/slm_api/example_multi.py), use `mode="multi"` for several enabled broadband sequences in a single stream:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from slm_api.helpers.data_handler import DataHandler
|
|
69
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class PrintHandler(DataHandler):
|
|
73
|
+
def handle(self, *, host, name, value, **data):
|
|
74
|
+
print(f"{host} {name}: {value}")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
streamer = WebXiStreamHandler(
|
|
78
|
+
host="192.168.1.183",
|
|
79
|
+
sequenceNames=["LAeq", "LCeq", "LAF"],
|
|
80
|
+
mode="multi",
|
|
81
|
+
saving="json",
|
|
82
|
+
saving_path="saved_data/broadband",
|
|
83
|
+
)
|
|
84
|
+
streamer.setDataHandler(PrintHandler())
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
streamer.startStream()
|
|
88
|
+
except KeyboardInterrupt:
|
|
89
|
+
streamer.stopStream()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Enable the requested sequences and frequency weightings on the SLM before starting the stream. Each `DataHandler.handle()` call receives the source `host`, `name`, and `value`. The `saving=` handler continues saving when a custom handler is attached.
|
|
93
|
+
|
|
94
|
+
## Fast Logging
|
|
95
|
+
|
|
96
|
+
Based on [fast_log_example.py](src/slm_api/fast_log_example.py), use `mode="fast_logging"` for fast broadband samples:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from slm_api.enums.fast_log_intervals_enum import FastLogInterval
|
|
100
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
101
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
102
|
+
|
|
103
|
+
streamer = WebXiStreamHandler(
|
|
104
|
+
host="192.168.1.183",
|
|
105
|
+
sequenceID=SequenceIdEnums.FastLAF.value,
|
|
106
|
+
mode="fast_logging",
|
|
107
|
+
fast_logging_interval=FastLogInterval.interval_1000ms.value,
|
|
108
|
+
saving="csv",
|
|
109
|
+
saving_path="saved_data/fast_laf",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
streamer.startStream()
|
|
114
|
+
except KeyboardInterrupt:
|
|
115
|
+
streamer.stopStream()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Audio
|
|
119
|
+
|
|
120
|
+
Use the MP3 or FLAC examples for decoded audio samples:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
124
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
125
|
+
|
|
126
|
+
streamer = WebXiStreamHandler(
|
|
127
|
+
host="192.168.1.183",
|
|
128
|
+
sequenceID=SequenceIdEnums.MP3Signal.value,
|
|
129
|
+
mode="mp3",
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The matching `flac` form uses `SequenceIdEnums.FLACSignal.value` and `mode="flac"`. Audio setup is enabled by the handler. The SLM can take a few seconds to initialize audio recording when its quality setting changes.
|
|
134
|
+
|
|
135
|
+
## Synchronized Multi-Device Stream
|
|
136
|
+
|
|
137
|
+
Based on [multi_device_flac.py](src/slm_api/multi_device_flac.py), pass `multi_device=True` and start/stop the group through the synchronized helpers:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
141
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler, start_all_synced, stop_all
|
|
142
|
+
|
|
143
|
+
hosts = ["192.168.1.183", "192.168.1.216"]
|
|
144
|
+
streams = [
|
|
145
|
+
WebXiStreamHandler(
|
|
146
|
+
host=host,
|
|
147
|
+
sequenceID=SequenceIdEnums.MP3Signal.value,
|
|
148
|
+
mode="mp3",
|
|
149
|
+
streamName=f"Audio_{host}",
|
|
150
|
+
multi_device=True,
|
|
151
|
+
saving="csv",
|
|
152
|
+
saving_path=f"saved_data/{host}",
|
|
153
|
+
)
|
|
154
|
+
for host in hosts
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
start_all_synced(streams)
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
while True:
|
|
161
|
+
time.sleep(1)
|
|
162
|
+
except KeyboardInterrupt:
|
|
163
|
+
stop_all(streams)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`stop_all()` synchronizes the device measurement stops, flushes saving handlers, and removes each device stream.
|
|
167
|
+
|
|
168
|
+
## Modes
|
|
169
|
+
|
|
170
|
+
| Mode | Use |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `"leq"` | One broadband sequence; this is the default. |
|
|
173
|
+
| `"multi"` | Several named broadband sequences. |
|
|
174
|
+
| `"cpb"` | Constant-percentage-band data. |
|
|
175
|
+
| `"fast_logging"` | Fast broadband samples. |
|
|
176
|
+
| `"flac"` / `"mp3"` | Decoded audio samples. |
|
|
177
|
+
| `"screen_record"` | Latest SLM screen image in `streamer.image_bytes`. |
|
|
178
|
+
|
|
179
|
+
Legacy flags such as `mp3=True` remain supported, but `mode=` is preferred. Only select one mode per stream.
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Troubleshooting
|
|
183
|
+
|
|
184
|
+
- **No values arrive:** Confirm the requested sequences are enabled on the SLM.
|
|
185
|
+
- **Audio returns no samples after first enable:** Allow the SLM a few seconds to initialize audio recording before retrying.
|
|
186
|
+
- **Saved file is missing:** Call `stopStream()` or `stop_all()`; buffered files are written during shutdown.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "slm_open_api_package"
|
|
3
|
+
version = "0.2.10"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"requests",
|
|
9
|
+
"numpy",
|
|
10
|
+
"websockets",
|
|
11
|
+
"kaitaistruct",
|
|
12
|
+
"packaging",
|
|
13
|
+
"pyqtgraph",
|
|
14
|
+
"PyQt5",
|
|
15
|
+
"PyQt5-Qt5<5.15.11",
|
|
16
|
+
"miniaudio",
|
|
17
|
+
"matplotlib>=3.11.1",
|
|
18
|
+
"cryptography>=50.0.1",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[[project.authors]]
|
|
22
|
+
name = "Sofus Vingaard"
|
|
23
|
+
email = "sofus.krebsvingaard@hbkworld.com"
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
open-api-package = "slm_api:main"
|
|
27
|
+
|
|
28
|
+
[tool.uv.build-backend]
|
|
29
|
+
module-name = "slm_api"
|
|
30
|
+
|
|
31
|
+
[build-system]
|
|
32
|
+
requires = ["uv_build>=0.12.5,<0.13.0"]
|
|
33
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "slm_open_api_package"
|
|
3
|
+
version = "0.2.10"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Sofus Vingaard", email = "sofus.krebsvingaard@hbkworld.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"requests",
|
|
12
|
+
"numpy",
|
|
13
|
+
"websockets",
|
|
14
|
+
"kaitaistruct",
|
|
15
|
+
"packaging",
|
|
16
|
+
"pyqtgraph",
|
|
17
|
+
"PyQt5",
|
|
18
|
+
"PyQt5-Qt5<5.15.11",
|
|
19
|
+
"miniaudio",
|
|
20
|
+
"matplotlib>=3.11.1",
|
|
21
|
+
"cryptography>=50.0.1",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
open-api-package = "slm_api:main"
|
|
26
|
+
|
|
27
|
+
[tool.uv.build-backend]
|
|
28
|
+
module-name = "slm_api"
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv_build>=0.12.5,<0.13.0"]
|
|
32
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
import numpy as np
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
from matplotlib.animation import FuncAnimation
|
|
5
|
+
|
|
6
|
+
from slm_api.helpers.stream_handlers import WebXiStreamHandler
|
|
7
|
+
from slm_api.helpers import webxi_helper_functions as webxi_helper
|
|
8
|
+
from slm_api.enums.sequence_id_enum import SequenceIdEnums
|
|
9
|
+
from slm_api.helpers.data_handler import CsvDataHandler,PickleDataHandler,JsonDataHandler,MultiDataHandler, DataHandler
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
host = webxi_helper.set_host(__file__)
|
|
13
|
+
# sequence_names = ["LAeq"]
|
|
14
|
+
cpb_sequence_names = ["CPBLAeq"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
sequenceID= SequenceIdEnums.CPBLAeq.value
|
|
18
|
+
|
|
19
|
+
class PrintHandler(DataHandler):
|
|
20
|
+
def handle(self, value, **data ):
|
|
21
|
+
print(f"{value}")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class FigureHandler:
|
|
25
|
+
|
|
26
|
+
def __init__(self, dataHandler):
|
|
27
|
+
self.dataHandler = dataHandler
|
|
28
|
+
self.fig, self.ax = plt.subplots(1,1, figsize=(10,5))
|
|
29
|
+
self.CPBFreq = dataHandler.calcFreqBands()
|
|
30
|
+
self.freq = [(i.replace("000.0","k")).replace(".0", "") for i in [str(i) for i in self.CPBFreq]]
|
|
31
|
+
self.ln = self.ax.bar(self.freq, np.zeros(len(self.freq)), width=.99)
|
|
32
|
+
self.ax.set_ylim(bottom=-20, top=120)
|
|
33
|
+
self.ax.grid(axis='y')
|
|
34
|
+
self.ax.set_ylabel("dB [SPL]")
|
|
35
|
+
self.ax.set_xlabel("Frequency band [Hz]")
|
|
36
|
+
self.fig.autofmt_xdate()
|
|
37
|
+
self.fig.tight_layout()
|
|
38
|
+
self.fig.canvas.mpl_connect('close_event', on_close)
|
|
39
|
+
|
|
40
|
+
def _update(self, i):
|
|
41
|
+
for rect, h in zip(self.ln.patches, self.dataHandler.CPB_values):
|
|
42
|
+
rect.set_height(h)
|
|
43
|
+
|
|
44
|
+
def startAnimation(self):
|
|
45
|
+
self.ani = FuncAnimation(self.fig, self._update, interval=1000)
|
|
46
|
+
|
|
47
|
+
def on_close(event):
|
|
48
|
+
streamer.stopStream()
|
|
49
|
+
streamer.data_handler.close()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
# turns off all CPB freq weights
|
|
54
|
+
webxi_helper.turn_off_CPB_freq_weight(host)
|
|
55
|
+
|
|
56
|
+
# turns on the CPB freq weight we want to use, in this case A weight
|
|
57
|
+
webxi_helper.turn_on_CPB_freq_weight(host, ["A"])
|
|
58
|
+
|
|
59
|
+
# turns on the CPB eq we want to use
|
|
60
|
+
webxi_helper.turn_on_cpb_leq(host, cpb_sequence_names)
|
|
61
|
+
|
|
62
|
+
streamer = WebXiStreamHandler(host,
|
|
63
|
+
sequenceID=sequenceID,
|
|
64
|
+
mode="cpb",
|
|
65
|
+
sequenceNames=cpb_sequence_names,
|
|
66
|
+
saving_path=r"./saved_data/test_file",
|
|
67
|
+
saving="json")
|
|
68
|
+
# streamer.setDataHandler(JsonDataHandler(r"C:\Users\SKREBSVINGAA\csv_test\csv_test.txt"))
|
|
69
|
+
streamer.setDataHandler(PrintHandler())
|
|
70
|
+
|
|
71
|
+
fig = FigureHandler(streamer)
|
|
72
|
+
threading.Thread(target=streamer.startStream, daemon=True).start()
|
|
73
|
+
fig.startAnimation()
|
|
74
|
+
plt.show()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
class FastLogInterval(Enum):
|
|
4
|
+
"""ControlBBFastLoggingInterval enum indices (member value = device index, name = ms/sample)."""
|
|
5
|
+
interval_1ms = 0
|
|
6
|
+
interval_2ms = 1
|
|
7
|
+
interval_4ms = 2
|
|
8
|
+
interval_8ms = 3
|
|
9
|
+
interval_16ms = 4
|
|
10
|
+
interval_32ms = 5
|
|
11
|
+
interval_63ms = 6
|
|
12
|
+
interval_125ms = 7
|
|
13
|
+
interval_250ms = 8
|
|
14
|
+
interval_500ms = 9
|
|
15
|
+
interval_1000ms = 10
|
|
16
|
+
|