sonusai 0.15.9__py3-none-any.whl → 0.16.1__py3-none-any.whl
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.
- sonusai/__init__.py +36 -4
- sonusai/audiofe.py +111 -106
- sonusai/calc_metric_spenh.py +38 -22
- sonusai/genft.py +15 -6
- sonusai/genmix.py +14 -6
- sonusai/genmixdb.py +15 -7
- sonusai/gentcst.py +13 -6
- sonusai/lsdb.py +15 -5
- sonusai/main.py +58 -61
- sonusai/mixture/__init__.py +1 -0
- sonusai/mixture/config.py +1 -2
- sonusai/mkmanifest.py +43 -8
- sonusai/mkwav.py +15 -6
- sonusai/onnx_predict.py +16 -6
- sonusai/plot.py +16 -6
- sonusai/post_spenh_targetf.py +13 -6
- sonusai/summarize_metric_spenh.py +71 -0
- sonusai/tplot.py +14 -6
- sonusai/utils/__init__.py +4 -7
- sonusai/utils/asl_p56.py +3 -3
- sonusai/utils/asr.py +35 -8
- sonusai/utils/asr_functions/__init__.py +0 -5
- sonusai/utils/asr_functions/aaware_whisper.py +2 -2
- sonusai/utils/asr_manifest_functions/__init__.py +1 -0
- sonusai/utils/asr_manifest_functions/mcgill_speech.py +29 -0
- sonusai/utils/{trim_docstring.py → docstring.py} +20 -0
- sonusai/utils/model_utils.py +30 -0
- sonusai/utils/onnx_utils.py +19 -45
- {sonusai-0.15.9.dist-info → sonusai-0.16.1.dist-info}/METADATA +7 -25
- {sonusai-0.15.9.dist-info → sonusai-0.16.1.dist-info}/RECORD +32 -46
- sonusai/data_generator/__init__.py +0 -5
- sonusai/data_generator/dataset_from_mixdb.py +0 -143
- sonusai/data_generator/keras_from_mixdb.py +0 -169
- sonusai/data_generator/torch_from_mixdb.py +0 -122
- sonusai/keras_onnx.py +0 -86
- sonusai/keras_predict.py +0 -231
- sonusai/keras_train.py +0 -334
- sonusai/torchl_onnx.py +0 -216
- sonusai/torchl_predict.py +0 -542
- sonusai/torchl_train.py +0 -223
- sonusai/utils/asr_functions/aixplain_whisper.py +0 -59
- sonusai/utils/asr_functions/data.py +0 -16
- sonusai/utils/asr_functions/deepgram.py +0 -97
- sonusai/utils/asr_functions/fastwhisper.py +0 -90
- sonusai/utils/asr_functions/google.py +0 -95
- sonusai/utils/asr_functions/whisper.py +0 -49
- sonusai/utils/keras_utils.py +0 -226
- {sonusai-0.15.9.dist-info → sonusai-0.16.1.dist-info}/WHEEL +0 -0
- {sonusai-0.15.9.dist-info → sonusai-0.16.1.dist-info}/entry_points.txt +0 -0
sonusai/__init__.py
CHANGED
@@ -5,6 +5,25 @@ from os.path import dirname
|
|
5
5
|
__version__ = metadata.version(__package__)
|
6
6
|
BASEDIR = dirname(__file__)
|
7
7
|
|
8
|
+
commands_doc = """
|
9
|
+
audiofe Audio front end
|
10
|
+
calc_metric_spenh Run speech enhancement and analysis
|
11
|
+
doc Documentation
|
12
|
+
genft Generate feature and truth data
|
13
|
+
genmix Generate mixture and truth data
|
14
|
+
genmixdb Generate a mixture database
|
15
|
+
gentcst Generate target configuration from a subdirectory tree
|
16
|
+
lsdb List information about a mixture database
|
17
|
+
mkmanifest Make ASR manifest JSON file
|
18
|
+
mkwav Make WAV files from a mixture database
|
19
|
+
onnx_predict Run ONNX predict on a trained model
|
20
|
+
plot Plot mixture data
|
21
|
+
post_spenh_targetf Run post-processing for speech enhancement targetf data
|
22
|
+
summarize_metric_spenh Summarize speech enhancement and analysis results
|
23
|
+
tplot Plot truth data
|
24
|
+
vars List custom SonusAI variables
|
25
|
+
"""
|
26
|
+
|
8
27
|
# create logger
|
9
28
|
logger = logging.getLogger('sonusai')
|
10
29
|
logger.setLevel(logging.DEBUG)
|
@@ -21,7 +40,7 @@ class SonusAIError(Exception):
|
|
21
40
|
|
22
41
|
|
23
42
|
# create file handler
|
24
|
-
def create_file_handler(filename: str):
|
43
|
+
def create_file_handler(filename: str) -> None:
|
25
44
|
fh = logging.FileHandler(filename=filename, mode='w')
|
26
45
|
fh.setLevel(logging.DEBUG)
|
27
46
|
fh.setFormatter(formatter)
|
@@ -29,7 +48,7 @@ def create_file_handler(filename: str):
|
|
29
48
|
|
30
49
|
|
31
50
|
# update console handler
|
32
|
-
def update_console_handler(verbose: bool):
|
51
|
+
def update_console_handler(verbose: bool) -> None:
|
33
52
|
if not verbose:
|
34
53
|
logger.removeHandler(console_handler)
|
35
54
|
console_handler.setLevel(logging.INFO)
|
@@ -37,14 +56,17 @@ def update_console_handler(verbose: bool):
|
|
37
56
|
|
38
57
|
|
39
58
|
# write initial log message
|
40
|
-
def initial_log_messages(name: str):
|
59
|
+
def initial_log_messages(name: str, subprocess: str = None) -> None:
|
41
60
|
from datetime import datetime
|
42
61
|
from getpass import getuser
|
43
62
|
from os import getcwd
|
44
63
|
from socket import gethostname
|
45
64
|
from sys import argv
|
46
65
|
|
47
|
-
|
66
|
+
if subprocess is None:
|
67
|
+
logger.info(f'SonusAI {__version__}')
|
68
|
+
else:
|
69
|
+
logger.info(f'SonusAI {subprocess}')
|
48
70
|
logger.info(f'{name}')
|
49
71
|
logger.info('')
|
50
72
|
logger.debug(f'Host: {gethostname()}')
|
@@ -53,3 +75,13 @@ def initial_log_messages(name: str):
|
|
53
75
|
logger.debug(f'Date: {datetime.now()}')
|
54
76
|
logger.debug(f'Command: {" ".join(argv)}')
|
55
77
|
logger.debug('')
|
78
|
+
|
79
|
+
|
80
|
+
def commands_list(doc: str = commands_doc) -> list[str]:
|
81
|
+
lines = doc.split('\n')
|
82
|
+
commands = []
|
83
|
+
for line in lines:
|
84
|
+
command = line.strip().split(' ').pop(0)
|
85
|
+
if command:
|
86
|
+
commands.append(command)
|
87
|
+
return commands
|
sonusai/audiofe.py
CHANGED
@@ -24,6 +24,10 @@ audiofe_capture_<TIMESTAMP>.wav.
|
|
24
24
|
If a model is specified, run prediction on audio data from this model. Then compute the inverse transform of the
|
25
25
|
prediction result and save to audiofe_predict_<TIMESTAMP>.wav.
|
26
26
|
|
27
|
+
Also, if a model is specified, save plots of the capture data (time-domain signal and feature) to
|
28
|
+
audiofe_capture_<TIMESTAMP>.png and predict data (time-domain signal and feature) to
|
29
|
+
audiofe_predict_<TIMESTAMP>.png.
|
30
|
+
|
27
31
|
If an ASR is specified, run ASR on the captured audio and print the results. In addition, if a model was also specified,
|
28
32
|
run ASR on the predict audio and print the results.
|
29
33
|
|
@@ -31,41 +35,32 @@ If the debug option is enabled, write capture audio, feature, reconstruct audio,
|
|
31
35
|
audiofe_<TIMESTAMP>.h5.
|
32
36
|
|
33
37
|
"""
|
34
|
-
|
35
|
-
from select import select
|
36
|
-
from sys import stdin
|
37
|
-
from typing import Any
|
38
|
+
import signal
|
38
39
|
|
39
|
-
import h5py
|
40
40
|
import numpy as np
|
41
|
-
|
42
|
-
import torch
|
43
|
-
from docopt import docopt
|
44
|
-
from docopt import printable_usage
|
45
|
-
|
46
|
-
import sonusai
|
47
|
-
from sonusai import create_file_handler
|
48
|
-
from sonusai import initial_log_messages
|
49
|
-
from sonusai import logger
|
50
|
-
from sonusai import update_console_handler
|
41
|
+
|
51
42
|
from sonusai.mixture import AudioT
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
from sonusai
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
43
|
+
|
44
|
+
|
45
|
+
def signal_handler(_sig, _frame):
|
46
|
+
import sys
|
47
|
+
|
48
|
+
from sonusai import logger
|
49
|
+
|
50
|
+
logger.info('Canceled due to keyboard interrupt')
|
51
|
+
sys.exit(1)
|
52
|
+
|
53
|
+
|
54
|
+
signal.signal(signal.SIGINT, signal_handler)
|
64
55
|
|
65
56
|
|
66
57
|
def main() -> None:
|
58
|
+
from docopt import docopt
|
59
|
+
|
60
|
+
import sonusai
|
61
|
+
from sonusai.utils import trim_docstring
|
62
|
+
|
67
63
|
args = docopt(trim_docstring(__doc__), version=sonusai.__version__, options_first=True)
|
68
|
-
ts = create_timestamp()
|
69
64
|
|
70
65
|
verbose = args['--verbose']
|
71
66
|
length = float(args['--length'])
|
@@ -77,8 +72,34 @@ def main() -> None:
|
|
77
72
|
debug = args['--debug']
|
78
73
|
show = args['--show']
|
79
74
|
|
80
|
-
|
81
|
-
|
75
|
+
from os.path import exists
|
76
|
+
|
77
|
+
import h5py
|
78
|
+
import pyaudio
|
79
|
+
import torch
|
80
|
+
from docopt import printable_usage
|
81
|
+
from sonusai_torchl.utils import load_torchl_ckpt_model
|
82
|
+
|
83
|
+
from sonusai import create_file_handler
|
84
|
+
from sonusai import initial_log_messages
|
85
|
+
from sonusai import logger
|
86
|
+
from sonusai import update_console_handler
|
87
|
+
from sonusai.mixture import SAMPLE_RATE
|
88
|
+
from sonusai.mixture import get_audio_from_feature
|
89
|
+
from sonusai.mixture import get_feature_from_audio
|
90
|
+
from sonusai.utils import calc_asr
|
91
|
+
from sonusai.utils import create_timestamp
|
92
|
+
from sonusai.utils import get_input_devices
|
93
|
+
from sonusai.utils import trim_docstring
|
94
|
+
from sonusai.utils import write_wav
|
95
|
+
|
96
|
+
ts = create_timestamp()
|
97
|
+
capture_name = f'audiofe_capture_{ts}'
|
98
|
+
capture_wav = capture_name + '.wav'
|
99
|
+
capture_png = capture_name + '.png'
|
100
|
+
predict_name = f'audiofe_predict_{ts}'
|
101
|
+
predict_wav = predict_name + '.wav'
|
102
|
+
predict_png = predict_name + '.png'
|
82
103
|
h5_name = f'audiofe_{ts}.h5'
|
83
104
|
|
84
105
|
if model_name is not None and ckpt_name is None:
|
@@ -109,9 +130,9 @@ def main() -> None:
|
|
109
130
|
logger.exception(e)
|
110
131
|
return
|
111
132
|
|
112
|
-
write_wav(
|
133
|
+
write_wav(capture_wav, capture_audio, SAMPLE_RATE)
|
113
134
|
logger.info('')
|
114
|
-
logger.info(f'Wrote capture audio with shape {capture_audio.shape} to {
|
135
|
+
logger.info(f'Wrote capture audio with shape {capture_audio.shape} to {capture_wav}')
|
115
136
|
if debug:
|
116
137
|
with h5py.File(h5_name, 'a') as f:
|
117
138
|
if 'capture_audio' in f:
|
@@ -124,9 +145,13 @@ def main() -> None:
|
|
124
145
|
logger.info(f'Capture audio ASR: {capture_asr}')
|
125
146
|
|
126
147
|
if model_name is not None:
|
127
|
-
model =
|
148
|
+
model = load_torchl_ckpt_model(model_name=model_name, ckpt_name=ckpt_name)
|
149
|
+
model.eval()
|
128
150
|
|
129
151
|
feature = get_feature_from_audio(audio=capture_audio, feature_mode=model.hparams.feature)
|
152
|
+
save_figure(capture_png, capture_audio, feature)
|
153
|
+
logger.info(f'Wrote capture plots to {capture_png}')
|
154
|
+
|
130
155
|
if debug:
|
131
156
|
with h5py.File(h5_name, 'a') as f:
|
132
157
|
if 'feature' in f:
|
@@ -134,22 +159,9 @@ def main() -> None:
|
|
134
159
|
f.create_dataset('feature', data=feature)
|
135
160
|
logger.info(f'Wrote feature with shape {feature.shape} to {h5_name}')
|
136
161
|
|
137
|
-
# if debug:
|
138
|
-
# reconstruct_name = f'audiofe_reconstruct_{ts}.wav'
|
139
|
-
# reconstruct_audio = get_audio_from_feature(feature=feature, feature_mode=model.hparams.feature)
|
140
|
-
# samples = min(len(capture_audio), len(reconstruct_audio))
|
141
|
-
# max_err = np.max(np.abs(capture_audio[:samples] - reconstruct_audio[:samples]))
|
142
|
-
# logger.info(f'Maximum error between capture and reconstruct: {max_err}')
|
143
|
-
# write_wav(reconstruct_name, reconstruct_audio, SAMPLE_RATE)
|
144
|
-
# logger.info(f'Wrote reconstruct audio with shape {reconstruct_audio.shape} to {reconstruct_name}')
|
145
|
-
# with h5py.File(h5_name, 'a') as f:
|
146
|
-
# if 'reconstruct_audio' in f:
|
147
|
-
# del f['reconstruct_audio']
|
148
|
-
# f.create_dataset('reconstruct_audio', data=reconstruct_audio)
|
149
|
-
# logger.info(f'Wrote reconstruct audio with shape {reconstruct_audio.shape} to {h5_name}')
|
150
|
-
|
151
162
|
with torch.no_grad():
|
152
|
-
|
163
|
+
# model wants batch x timesteps x feature_parameters
|
164
|
+
predict = model(torch.tensor(feature).permute((1, 0, 2))).permute(1, 0, 2).numpy()
|
153
165
|
if debug:
|
154
166
|
with h5py.File(h5_name, 'a') as f:
|
155
167
|
if 'predict' in f:
|
@@ -157,9 +169,9 @@ def main() -> None:
|
|
157
169
|
f.create_dataset('predict', data=predict)
|
158
170
|
logger.info(f'Wrote predict with shape {predict.shape} to {h5_name}')
|
159
171
|
|
160
|
-
predict_audio = get_audio_from_feature(feature=predict
|
161
|
-
write_wav(
|
162
|
-
logger.info(f'Wrote predict audio with shape {predict_audio.shape} to {
|
172
|
+
predict_audio = get_audio_from_feature(feature=predict, feature_mode=model.hparams.feature)
|
173
|
+
write_wav(predict_wav, predict_audio, SAMPLE_RATE)
|
174
|
+
logger.info(f'Wrote predict audio with shape {predict_audio.shape} to {predict_wav}')
|
163
175
|
if debug:
|
164
176
|
with h5py.File(h5_name, 'a') as f:
|
165
177
|
if 'predict_audio' in f:
|
@@ -167,69 +179,26 @@ def main() -> None:
|
|
167
179
|
f.create_dataset('predict_audio', data=predict_audio)
|
168
180
|
logger.info(f'Wrote predict audio with shape {predict_audio.shape} to {h5_name}')
|
169
181
|
|
182
|
+
save_figure(predict_png, predict_audio, predict)
|
183
|
+
logger.info(f'Wrote predict plots to {predict_png}')
|
184
|
+
|
170
185
|
if asr_name is not None:
|
171
186
|
predict_asr = calc_asr(predict_audio, engine=asr_name, whisper_model_name=whisper_name).text
|
172
187
|
logger.info(f'Predict audio ASR: {predict_asr}')
|
173
188
|
|
174
189
|
|
175
|
-
def
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
# Load checkpoint first to get hparams if available
|
180
|
-
try:
|
181
|
-
checkpoint = torch.load(ckpt_name, map_location=lambda storage, loc: storage)
|
182
|
-
except Exception as e:
|
183
|
-
logger.exception(f'Error: could not load checkpoint from {ckpt_name}: {e}')
|
184
|
-
raise SystemExit(1)
|
185
|
-
|
186
|
-
# Import model definition file
|
187
|
-
logger.info(f'Importing {model_name}')
|
188
|
-
litemodule = import_keras_model(model_name)
|
189
|
-
|
190
|
-
if 'hyper_parameters' in checkpoint:
|
191
|
-
logger.info(f'Found checkpoint file with hyper-parameters')
|
192
|
-
hparams = checkpoint['hyper_parameters']
|
193
|
-
if hparams['batch_size'] != batch_size:
|
194
|
-
logger.info(
|
195
|
-
f'Overriding model default batch_size of {hparams["batch_size"]} with batch_size of {batch_size}')
|
196
|
-
hparams["batch_size"] = batch_size
|
197
|
-
|
198
|
-
if hparams['timesteps'] != 0 and timesteps == 0:
|
199
|
-
timesteps = hparams['timesteps']
|
200
|
-
logger.warning(f'Using model default timesteps of {timesteps}')
|
201
|
-
|
202
|
-
logger.info(f'Building model with {len(hparams)} total hparams')
|
203
|
-
try:
|
204
|
-
model = litemodule.MyHyperModel(**hparams)
|
205
|
-
except Exception as e:
|
206
|
-
logger.exception(f'Error: model build (MyHyperModel) in {model_name} failed: {e}')
|
207
|
-
raise SystemExit(1)
|
208
|
-
else:
|
209
|
-
logger.info(f'Found checkpoint file with no hyper-parameters')
|
210
|
-
logger.info(f'Building model with defaults')
|
211
|
-
try:
|
212
|
-
tmp = litemodule.MyHyperModel()
|
213
|
-
except Exception as e:
|
214
|
-
logger.exception(f'Error: model build (MyHyperModel) in {model_name} failed: {e}')
|
215
|
-
raise SystemExit(1)
|
216
|
-
|
217
|
-
if tmp.batch_size != batch_size:
|
218
|
-
logger.info(f'Overriding model default batch_size of {tmp.batch_size} with batch_size of {batch_size}')
|
219
|
-
|
220
|
-
if tmp.timesteps != 0 and timesteps == 0:
|
221
|
-
timesteps = tmp.timesteps
|
222
|
-
logger.warning(f'Using model default timesteps of {timesteps}')
|
223
|
-
|
224
|
-
model = litemodule.MyHyperModel(timesteps=timesteps, batch_size=batch_size)
|
190
|
+
def get_frames_from_device(input_name: str | None, length: float, chunk: int = 1024) -> AudioT:
|
191
|
+
from select import select
|
192
|
+
from sys import stdin
|
225
193
|
|
226
|
-
|
227
|
-
model.load_state_dict(checkpoint["state_dict"])
|
228
|
-
model.eval()
|
229
|
-
return model
|
194
|
+
import pyaudio
|
230
195
|
|
196
|
+
from sonusai import logger
|
197
|
+
from sonusai.mixture import CHANNEL_COUNT
|
198
|
+
from sonusai.mixture import SAMPLE_RATE
|
199
|
+
from sonusai.utils import get_input_device_index_by_name
|
200
|
+
from sonusai.utils import get_input_devices
|
231
201
|
|
232
|
-
def get_frames_from_device(input_name: str | None, length: float, chunk: int = 1024) -> AudioT:
|
233
202
|
p = pyaudio.PyAudio()
|
234
203
|
|
235
204
|
input_devices = get_input_devices(p)
|
@@ -280,6 +249,10 @@ def get_frames_from_device(input_name: str | None, length: float, chunk: int = 1
|
|
280
249
|
|
281
250
|
|
282
251
|
def get_frames_from_file(input_name: str, length: float) -> AudioT:
|
252
|
+
from sonusai import logger
|
253
|
+
from sonusai.mixture import SAMPLE_RATE
|
254
|
+
from sonusai.mixture import read_audio
|
255
|
+
|
283
256
|
logger.info(f'Capturing from {input_name}')
|
284
257
|
frames = read_audio(input_name)
|
285
258
|
if length != -1:
|
@@ -289,5 +262,37 @@ def get_frames_from_file(input_name: str, length: float) -> AudioT:
|
|
289
262
|
return frames
|
290
263
|
|
291
264
|
|
265
|
+
def save_figure(name: str, audio: np.ndarray, feature: np.ndarray) -> None:
|
266
|
+
import matplotlib.pyplot as plt
|
267
|
+
from scipy.interpolate import CubicSpline
|
268
|
+
|
269
|
+
from sonusai.mixture import SAMPLE_RATE
|
270
|
+
from sonusai.utils import unstack_complex
|
271
|
+
|
272
|
+
spectrum = 20 * np.log(np.abs(np.squeeze(unstack_complex(feature)).transpose()))
|
273
|
+
frames = spectrum.shape[1]
|
274
|
+
samples = (len(audio) // frames) * frames
|
275
|
+
length_in_s = samples / SAMPLE_RATE
|
276
|
+
interp = samples // frames
|
277
|
+
|
278
|
+
ts = np.arange(0.0, length_in_s, interp / SAMPLE_RATE)
|
279
|
+
t = np.arange(0.0, length_in_s, 1 / SAMPLE_RATE)
|
280
|
+
|
281
|
+
spectrum = CubicSpline(ts, spectrum, axis=-1)(t)
|
282
|
+
|
283
|
+
fig, (ax1, ax2) = plt.subplots(nrows=2)
|
284
|
+
ax1.set_title(name)
|
285
|
+
ax1.plot(t, audio[:samples])
|
286
|
+
ax1.set_ylabel('Signal')
|
287
|
+
ax1.set_xlim(0, length_in_s)
|
288
|
+
ax1.set_ylim(-1, 1)
|
289
|
+
|
290
|
+
ax2.imshow(spectrum, origin='lower', aspect='auto')
|
291
|
+
ax2.set_xticks([])
|
292
|
+
ax2.set_ylabel('Feature')
|
293
|
+
|
294
|
+
plt.savefig(name, dpi=300)
|
295
|
+
|
296
|
+
|
292
297
|
if __name__ == '__main__':
|
293
298
|
main()
|
sonusai/calc_metric_spenh.py
CHANGED
@@ -60,6 +60,7 @@ Metric and extraction data are written into prediction location PLOC as separate
|
|
60
60
|
Inputs:
|
61
61
|
|
62
62
|
"""
|
63
|
+
import signal
|
63
64
|
from dataclasses import dataclass
|
64
65
|
from typing import Optional
|
65
66
|
|
@@ -67,14 +68,24 @@ import matplotlib
|
|
67
68
|
import matplotlib.pyplot as plt
|
68
69
|
import numpy as np
|
69
70
|
import pandas as pd
|
70
|
-
|
71
|
-
from sonusai import logger
|
72
71
|
from sonusai.mixture import AudioF
|
73
72
|
from sonusai.mixture import AudioT
|
74
73
|
from sonusai.mixture import Feature
|
75
74
|
from sonusai.mixture import MixtureDatabase
|
76
75
|
from sonusai.mixture import Predict
|
77
76
|
|
77
|
+
|
78
|
+
def signal_handler(_sig, _frame):
|
79
|
+
import sys
|
80
|
+
|
81
|
+
from sonusai import logger
|
82
|
+
|
83
|
+
logger.info('Canceled due to keyboard interrupt')
|
84
|
+
sys.exit(1)
|
85
|
+
|
86
|
+
|
87
|
+
signal.signal(signal.SIGINT, signal_handler)
|
88
|
+
|
78
89
|
matplotlib.use('SVG')
|
79
90
|
|
80
91
|
|
@@ -758,13 +769,18 @@ def _process_mixture(mixid: int) -> tuple[pd.DataFrame, pd.DataFrame]:
|
|
758
769
|
predict = stack_complex(predict)
|
759
770
|
|
760
771
|
# 2) Collect true target, noise, mixture data, trim to predict size if needed
|
761
|
-
|
762
|
-
target_f = mixdb.
|
763
|
-
|
764
|
-
|
765
|
-
|
772
|
+
tmp = mixdb.mixture_targets(mixid) # targets is list of pre-IR and pre-specaugment targets
|
773
|
+
target_f = mixdb.mixture_targets_f(mixid, targets=tmp)[0]
|
774
|
+
target = tmp[0]
|
775
|
+
mixture = mixdb.mixture_mixture(mixid) # note: gives full reverberated/distorted target, but no specaugment
|
776
|
+
# noise_wodist = mixdb.mixture_noise(mixid) # noise without specaugment and distortion
|
777
|
+
# noise_wodist_f = mixdb.mixture_noise_f(mixid, noise=noise_wodist)
|
778
|
+
noise = mixture - target # has time-domain distortion (ir,etc.) but does not have specaugment
|
779
|
+
# noise_f = mixdb.mixture_noise_f(mixid, noise=noise)
|
780
|
+
segsnr_f = mixdb.mixture_segsnr(mixid, target=target, noise=noise) # note: uses pre-IR, pre-specaug audio
|
766
781
|
mixture_f = mixdb.mixture_mixture_f(mixid, mixture=mixture)
|
767
|
-
|
782
|
+
noise_f = mixture_f - target_f # true noise in freq domain includes specaugment and time-domain ir,distortions
|
783
|
+
# segsnr_f = mixdb.mixture_segsnr(mixid, target=target, noise=noise)
|
768
784
|
segsnr_f[segsnr_f == inf] = 7.944e8 # 99db
|
769
785
|
segsnr_f[segsnr_f == -inf] = 1.258e-10 # -99db
|
770
786
|
# need to use inv-tf to match #samples & latency shift properties of predict inv tf
|
@@ -920,8 +936,9 @@ def _process_mixture(mixid: int) -> tuple[pd.DataFrame, pd.DataFrame]:
|
|
920
936
|
'NLERR': lerr_n_frame,
|
921
937
|
'SPD': phd_frame})
|
922
938
|
metr2 = metr2.describe() # Use pandas stat function
|
923
|
-
|
924
|
-
|
939
|
+
# Change SSNR stats to dB, except count. SSNR is index 0, pandas requires using iloc
|
940
|
+
# metr2['SSNR'][1:] = metr2['SSNR'][1:].apply(lambda x: 10 * np.log10(x + 1.01e-10))
|
941
|
+
metr2.iloc[1:, 0] = metr2['SSNR'][1:].apply(lambda x: 10 * np.log10(x + 1.01e-10))
|
925
942
|
# create a single row in multi-column header
|
926
943
|
new_labels = pd.MultiIndex.from_product([metr2.columns,
|
927
944
|
['Avg', 'Min', 'Med', 'Max', 'Std']],
|
@@ -978,11 +995,11 @@ def _process_mixture(mixid: int) -> tuple[pd.DataFrame, pd.DataFrame]:
|
|
978
995
|
plot_fname = base_name + '_metric_spenh.pdf'
|
979
996
|
|
980
997
|
# Reshape feature to eliminate overlap redundancy for easier to understand spectrogram view
|
981
|
-
# Original size (frames, stride,
|
982
|
-
# Reshape to get frames*decimated_stride,
|
998
|
+
# Original size (frames, stride, num_bands), decimates in stride dimension only if step is > 1
|
999
|
+
# Reshape to get frames*decimated_stride, num_bands
|
983
1000
|
step = int(mixdb.feature_samples / mixdb.feature_step_samples)
|
984
1001
|
if feature.ndim != 3:
|
985
|
-
raise SonusAIError(f'feature does not have 3 dimensions: frames, stride,
|
1002
|
+
raise SonusAIError(f'feature does not have 3 dimensions: frames, stride, num_bands')
|
986
1003
|
|
987
1004
|
# for feature cn*00n**
|
988
1005
|
feat_sgram = unstack_complex(feature)
|
@@ -1166,7 +1183,7 @@ def main():
|
|
1166
1183
|
# Individual mixtures use pandas print, set precision to 2 decimal places
|
1167
1184
|
# pd.set_option('float_format', '{:.2f}'.format)
|
1168
1185
|
progress = tqdm(total=len(mixids), desc='calc_metric_spenh')
|
1169
|
-
all_metrics_tables = pp_tqdm_imap(_process_mixture, mixids, progress=progress, num_cpus=
|
1186
|
+
all_metrics_tables = pp_tqdm_imap(_process_mixture, mixids, progress=progress, num_cpus=8)
|
1170
1187
|
progress.close()
|
1171
1188
|
|
1172
1189
|
all_metrics_table_1 = pd.concat([item[0] for item in all_metrics_tables])
|
@@ -1192,6 +1209,7 @@ def main():
|
|
1192
1209
|
if ~np.isnan(tmp.iloc[0].to_numpy()[0]).any():
|
1193
1210
|
mtab_snr_summary_em = pd.concat([mtab_snr_summary_em, tmp])
|
1194
1211
|
|
1212
|
+
mtab_snr_summary = mtab_snr_summary.sort_values(by=['MXSNR'], ascending=False)
|
1195
1213
|
# Correct percentages in snr summary table
|
1196
1214
|
mtab_snr_summary['PESQi%'] = 100 * (mtab_snr_summary['PESQ'] - mtab_snr_summary['MXPESQ']) / np.maximum(
|
1197
1215
|
mtab_snr_summary['MXPESQ'], 0.01)
|
@@ -1202,9 +1220,11 @@ def main():
|
|
1202
1220
|
else:
|
1203
1221
|
mtab_snr_summary['WERi%'].iloc[i] = -999.0
|
1204
1222
|
else:
|
1205
|
-
mtab_snr_summary['
|
1206
|
-
|
1207
|
-
|
1223
|
+
if ~np.isnan(mtab_snr_summary['WER'].iloc[i]) and ~np.isnan(mtab_snr_summary['MXWER'].iloc[i]):
|
1224
|
+
# update WERi% in 6th col
|
1225
|
+
mtab_snr_summary.iloc[i, 6] = 100 * (mtab_snr_summary['MXWER'].iloc[i] -
|
1226
|
+
mtab_snr_summary['WER'].iloc[i]) / \
|
1227
|
+
mtab_snr_summary['MXWER'].iloc[i]
|
1208
1228
|
|
1209
1229
|
# Calculate avg metrics over all mixtures except -99
|
1210
1230
|
all_mtab1_sorted_nom99 = all_mtab1_sorted[all_mtab1_sorted.MXSNR != -99]
|
@@ -1317,8 +1337,4 @@ def main():
|
|
1317
1337
|
|
1318
1338
|
|
1319
1339
|
if __name__ == '__main__':
|
1320
|
-
|
1321
|
-
main()
|
1322
|
-
except KeyboardInterrupt:
|
1323
|
-
logger.info('Canceled due to keyboard interrupt')
|
1324
|
-
exit()
|
1340
|
+
main()
|
sonusai/genft.py
CHANGED
@@ -23,14 +23,26 @@ Outputs the following to the mixture database directory:
|
|
23
23
|
genft.log
|
24
24
|
|
25
25
|
"""
|
26
|
+
import signal
|
26
27
|
from dataclasses import dataclass
|
27
28
|
|
28
|
-
from sonusai import logger
|
29
29
|
from sonusai.mixture import GenFTData
|
30
30
|
from sonusai.mixture import GeneralizedIDs
|
31
31
|
from sonusai.mixture import MixtureDatabase
|
32
32
|
|
33
33
|
|
34
|
+
def signal_handler(_sig, _frame):
|
35
|
+
import sys
|
36
|
+
|
37
|
+
from sonusai import logger
|
38
|
+
|
39
|
+
logger.info('Canceled due to keyboard interrupt')
|
40
|
+
sys.exit(1)
|
41
|
+
|
42
|
+
|
43
|
+
signal.signal(signal.SIGINT, signal_handler)
|
44
|
+
|
45
|
+
|
34
46
|
@dataclass
|
35
47
|
class MPGlobal:
|
36
48
|
mixdb: MixtureDatabase = None
|
@@ -123,6 +135,7 @@ def main() -> None:
|
|
123
135
|
|
124
136
|
from sonusai import create_file_handler
|
125
137
|
from sonusai import initial_log_messages
|
138
|
+
from sonusai import logger
|
126
139
|
from sonusai import update_console_handler
|
127
140
|
from sonusai.mixture import check_audio_files_exist
|
128
141
|
from sonusai.utils import human_readable_size
|
@@ -177,8 +190,4 @@ def main() -> None:
|
|
177
190
|
|
178
191
|
|
179
192
|
if __name__ == '__main__':
|
180
|
-
|
181
|
-
main()
|
182
|
-
except KeyboardInterrupt:
|
183
|
-
logger.info('Canceled due to keyboard interrupt')
|
184
|
-
raise SystemExit(0)
|
193
|
+
main()
|
sonusai/genmix.py
CHANGED
@@ -27,14 +27,26 @@ Outputs the following to the mixture database directory:
|
|
27
27
|
<id>.txt
|
28
28
|
genmix.log
|
29
29
|
"""
|
30
|
+
import signal
|
30
31
|
from dataclasses import dataclass
|
31
32
|
|
32
|
-
from sonusai import logger
|
33
33
|
from sonusai.mixture import GenMixData
|
34
34
|
from sonusai.mixture import GeneralizedIDs
|
35
35
|
from sonusai.mixture import MixtureDatabase
|
36
36
|
|
37
37
|
|
38
|
+
def signal_handler(_sig, _frame):
|
39
|
+
import sys
|
40
|
+
|
41
|
+
from sonusai import logger
|
42
|
+
|
43
|
+
logger.info('Canceled due to keyboard interrupt')
|
44
|
+
sys.exit(1)
|
45
|
+
|
46
|
+
|
47
|
+
signal.signal(signal.SIGINT, signal_handler)
|
48
|
+
|
49
|
+
|
38
50
|
@dataclass
|
39
51
|
class MPGlobal:
|
40
52
|
mixdb: MixtureDatabase = None
|
@@ -210,8 +222,4 @@ def main() -> None:
|
|
210
222
|
|
211
223
|
|
212
224
|
if __name__ == '__main__':
|
213
|
-
|
214
|
-
main()
|
215
|
-
except KeyboardInterrupt:
|
216
|
-
logger.info('Canceled due to keyboard interrupt')
|
217
|
-
raise SystemExit(0)
|
225
|
+
main()
|
sonusai/genmixdb.py
CHANGED
@@ -112,13 +112,25 @@ targets:
|
|
112
112
|
will find all .wav files in the specified directories and process them as targets.
|
113
113
|
|
114
114
|
"""
|
115
|
+
import signal
|
115
116
|
from dataclasses import dataclass
|
116
117
|
|
117
|
-
from sonusai import logger
|
118
118
|
from sonusai.mixture import Mixture
|
119
119
|
from sonusai.mixture import MixtureDatabase
|
120
120
|
|
121
121
|
|
122
|
+
def signal_handler(_sig, _frame):
|
123
|
+
import sys
|
124
|
+
|
125
|
+
from sonusai import logger
|
126
|
+
|
127
|
+
logger.info('Canceled due to keyboard interrupt')
|
128
|
+
sys.exit(1)
|
129
|
+
|
130
|
+
|
131
|
+
signal.signal(signal.SIGINT, signal_handler)
|
132
|
+
|
133
|
+
|
122
134
|
@dataclass
|
123
135
|
class MPGlobal:
|
124
136
|
mixdb: MixtureDatabase = None
|
@@ -225,7 +237,7 @@ def genmixdb(location: str,
|
|
225
237
|
if logging:
|
226
238
|
logger.info('Collecting impulse responses')
|
227
239
|
|
228
|
-
impulse_response_files = get_impulse_response_files(config
|
240
|
+
impulse_response_files = get_impulse_response_files(config)
|
229
241
|
|
230
242
|
populate_impulse_response_file_table(location, impulse_response_files, test)
|
231
243
|
|
@@ -509,8 +521,4 @@ def main() -> None:
|
|
509
521
|
|
510
522
|
|
511
523
|
if __name__ == '__main__':
|
512
|
-
|
513
|
-
main()
|
514
|
-
except KeyboardInterrupt:
|
515
|
-
logger.info('Canceled due to keyboard interrupt')
|
516
|
-
raise SystemExit(0)
|
524
|
+
main()
|
sonusai/gentcst.py
CHANGED
@@ -44,10 +44,21 @@ Outputs:
|
|
44
44
|
gentcst.log
|
45
45
|
|
46
46
|
"""
|
47
|
+
import signal
|
47
48
|
from dataclasses import dataclass
|
48
49
|
from typing import Optional
|
49
50
|
|
50
|
-
|
51
|
+
|
52
|
+
def signal_handler(_sig, _frame):
|
53
|
+
import sys
|
54
|
+
|
55
|
+
from sonusai import logger
|
56
|
+
|
57
|
+
logger.info('Canceled due to keyboard interrupt')
|
58
|
+
sys.exit(1)
|
59
|
+
|
60
|
+
|
61
|
+
signal.signal(signal.SIGINT, signal_handler)
|
51
62
|
|
52
63
|
CONFIG_FILE = 'config.yml'
|
53
64
|
|
@@ -621,8 +632,4 @@ def main() -> None:
|
|
621
632
|
|
622
633
|
|
623
634
|
if __name__ == '__main__':
|
624
|
-
|
625
|
-
main()
|
626
|
-
except KeyboardInterrupt:
|
627
|
-
logger.info('Canceled due to keyboard interrupt')
|
628
|
-
raise SystemExit(0)
|
635
|
+
main()
|