sonusai 0.19.9__py3-none-any.whl → 0.20.2__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/calc_metric_spenh.py +265 -233
- sonusai/data/genmixdb.yml +4 -2
- sonusai/data/silero_vad_v5.1.jit +0 -0
- sonusai/data/silero_vad_v5.1.onnx +0 -0
- sonusai/doc/doc.py +14 -0
- sonusai/genft.py +1 -1
- sonusai/genmetrics.py +15 -18
- sonusai/genmix.py +1 -1
- sonusai/genmixdb.py +30 -52
- sonusai/ir_metric.py +555 -0
- sonusai/metrics_summary.py +322 -0
- sonusai/mixture/__init__.py +6 -2
- sonusai/mixture/audio.py +139 -15
- sonusai/mixture/augmentation.py +199 -84
- sonusai/mixture/config.py +9 -4
- sonusai/mixture/constants.py +0 -1
- sonusai/mixture/datatypes.py +19 -10
- sonusai/mixture/generation.py +52 -64
- sonusai/mixture/helpers.py +38 -26
- sonusai/mixture/ir_delay.py +63 -0
- sonusai/mixture/mixdb.py +190 -46
- sonusai/mixture/targets.py +3 -6
- sonusai/mixture/truth_functions/energy.py +9 -5
- sonusai/mixture/truth_functions/metrics.py +1 -1
- sonusai/mkwav.py +1 -1
- sonusai/onnx_predict.py +1 -1
- sonusai/queries/queries.py +1 -1
- sonusai/utils/__init__.py +2 -0
- sonusai/utils/asr.py +1 -1
- sonusai/utils/load_object.py +8 -2
- sonusai/utils/stratified_shuffle_split.py +1 -1
- sonusai/utils/temp_seed.py +13 -0
- {sonusai-0.19.9.dist-info → sonusai-0.20.2.dist-info}/METADATA +2 -2
- {sonusai-0.19.9.dist-info → sonusai-0.20.2.dist-info}/RECORD +36 -35
- {sonusai-0.19.9.dist-info → sonusai-0.20.2.dist-info}/WHEEL +1 -1
- sonusai/mixture/soundfile_audio.py +0 -130
- sonusai/mixture/sox_audio.py +0 -476
- sonusai/mixture/sox_augmentation.py +0 -136
- sonusai/mixture/torchaudio_audio.py +0 -106
- sonusai/mixture/torchaudio_augmentation.py +0 -109
- {sonusai-0.19.9.dist-info → sonusai-0.20.2.dist-info}/entry_points.txt +0 -0
@@ -1,21 +1,24 @@
|
|
1
1
|
sonusai/__init__.py,sha256=NSb0bvmAh6Rm2MDtchpAGsg8a3BrmVnShYb-vC_emH8,2802
|
2
2
|
sonusai/aawscd_probwrite.py,sha256=QZLMQrmPr3OjZ06buyYDwlnk9YPCpyr4KHkBjPsiqjU,3700
|
3
3
|
sonusai/audiofe.py,sha256=iFdthh4UrOvziT8urjrjD7dACWZPQz9orM5bVAW3WSQ,11269
|
4
|
-
sonusai/calc_metric_spenh.py,sha256=
|
4
|
+
sonusai/calc_metric_spenh.py,sha256=XWa2DzLSCEQ6GzsJv-YHfnN51f_oFwcRMMgMzusAvYA,49304
|
5
5
|
sonusai/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
sonusai/data/genmixdb.yml,sha256=
|
6
|
+
sonusai/data/genmixdb.yml,sha256=qFK_VoUxHmc-EhJYZr4pAEY9tu6zRvloubq0NmrbH6I,956
|
7
|
+
sonusai/data/silero_vad_v5.1.jit,sha256=hcSOHw7LYE5dKiaPPM-5EtT36TWs3IavWj_FsK6nspo,2269612
|
8
|
+
sonusai/data/silero_vad_v5.1.onnx,sha256=JiOilT9v89LB5hdAxs23FoEzR5smff7xFKSjzFvdeI8,2327524
|
7
9
|
sonusai/data/speech_ma01_01.wav,sha256=PK0vMKg-NR6rPE3KouxHGF6PKXnJCr7AwjMqfu98LUA,76644
|
8
10
|
sonusai/data/whitenoise.wav,sha256=I2umov0m34y56F9IsIBi1XtE76ZeZaSKDf70cJRe3pI,1920044
|
9
11
|
sonusai/deprecated/gentcst.py,sha256=nKbHy3aHreHqA-XnLQOzOApS8RuTNUFqnx52a8I5zLQ,19921
|
10
12
|
sonusai/deprecated/plot.py,sha256=xL0w8Dtjdns2KX8tbTrdBGXviy_aoV3WUJSVKPZkQng,17423
|
11
13
|
sonusai/deprecated/tplot.py,sha256=0p238DvTaP4oU9y-dp0JdLaTV4TKrooAwbx7zdz_QAc,14641
|
12
14
|
sonusai/doc/__init__.py,sha256=KyQ26Um0RM8A3GYsb_tbFH64RwpoAw6lja2f_moUWas,33
|
13
|
-
sonusai/doc/doc.py,sha256=
|
15
|
+
sonusai/doc/doc.py,sha256=nEnvau0PIl2xbxET8AjFkwTLVShemmQ4CiTio94aLg0,19275
|
14
16
|
sonusai/doc.py,sha256=zSmXpioB0YS_5-7kqfS5cr--veSaXkxRKzldId9Hyoc,878
|
15
|
-
sonusai/genft.py,sha256=
|
16
|
-
sonusai/genmetrics.py,sha256=
|
17
|
-
sonusai/genmix.py,sha256=
|
18
|
-
sonusai/genmixdb.py,sha256=
|
17
|
+
sonusai/genft.py,sha256=K2wjO5J48UgyhCj2Sx789nkjt0DWtYgnRDbQyNtjCSY,5591
|
18
|
+
sonusai/genmetrics.py,sha256=jORQCdf_SCrtcvDd47lgcPgQTplG956RTAqmf58Xe8Y,5689
|
19
|
+
sonusai/genmix.py,sha256=mSc5FfAYrUt3zloPSnp81dks8ntvSH6jyk-nh97wnww,6707
|
20
|
+
sonusai/genmixdb.py,sha256=SsbHRpPoJ77XzOBQRRDheucyuJzE-tucQtRoYl89ApU,17841
|
21
|
+
sonusai/ir_metric.py,sha256=n35_RssAk2jjqm1iXJ6euMtK00LV4qohdBfDAZZpNlU,19581
|
19
22
|
sonusai/lsdb.py,sha256=0HOGDDndB3LT9cz9AaxKIpt9vslAoSP4F239gply4Xg,5149
|
20
23
|
sonusai/main.py,sha256=HbnEia1B1-Z-mlHkLfojH8aj9GIpL1Btw3oH60T_CCQ,2590
|
21
24
|
sonusai/metrics/__init__.py,sha256=ssV6JEK_oklRSocsp6HMcG-GtJvV8IkRQtdKhHHmwU8,878
|
@@ -35,44 +38,41 @@ sonusai/metrics/class_summary.py,sha256=ZA7zNgwBpmTs1TP_t4jRT0pWnDnATC_up_8qE4aH
|
|
35
38
|
sonusai/metrics/confusion_matrix_summary.py,sha256=zBL_Ke7wF6oKtrKZPr0fsyF_taofdjxBlZmKodu0xUA,3143
|
36
39
|
sonusai/metrics/one_hot.py,sha256=hmuyh-9tpRjb_oyqU3WqZ14zItpRJQfcqBDKJeb5H9I,13930
|
37
40
|
sonusai/metrics/snr_summary.py,sha256=t8Fi_8WtboTi8flkZuOiHq9H3-nIELx4AKvnm-qvxLQ,5785
|
38
|
-
sonusai/
|
39
|
-
sonusai/mixture/
|
40
|
-
sonusai/mixture/
|
41
|
+
sonusai/metrics_summary.py,sha256=DchpgBNYcBPz4t1YRindCm1CVmJLmXY7-oyaXpxBnWA,12106
|
42
|
+
sonusai/mixture/__init__.py,sha256=9TE21nlj4TOrSPopLh5Lh769v68v0kWgNkr_GGk9TEs,5300
|
43
|
+
sonusai/mixture/audio.py,sha256=MlsuhY8Zc8puBClO5utBP3mveAk8MLZtXvF6ztuisW4,6629
|
44
|
+
sonusai/mixture/augmentation.py,sha256=UYNdfVcYCsmegicKpGLTsYyvO97NQOTLoZjwI9sZROk,14646
|
41
45
|
sonusai/mixture/class_count.py,sha256=zcC3BDYMPN6wJYmO1RcOuqmrnTQIbMSznl33oN3e2sc,597
|
42
|
-
sonusai/mixture/config.py,sha256=
|
43
|
-
sonusai/mixture/constants.py,sha256=
|
46
|
+
sonusai/mixture/config.py,sha256=gZUPLGl7VKW32HfnFMEajKgJE35ZJ_edpxaA0TRPE1E,24469
|
47
|
+
sonusai/mixture/constants.py,sha256=yGXNjB87boJVSt1Q8hBTrNzOP0XVZcFf1k34u1yyUWU,1481
|
44
48
|
sonusai/mixture/data_io.py,sha256=KZGqhHd9_ucAfZEAXPIc5XL3aHYgdV5CyqaBx5_t8OM,5551
|
45
|
-
sonusai/mixture/datatypes.py,sha256=
|
49
|
+
sonusai/mixture/datatypes.py,sha256=LFWDsgGVY7Z3VPjWaB5g8q5Ss8v5bR2EfU6ygI0wZaU,10707
|
46
50
|
sonusai/mixture/db_datatypes.py,sha256=kvdUOMS6Pkkj9AmxCiq6zM8x7jbPPi933tVaXRxbTdQ,1534
|
47
51
|
sonusai/mixture/eq_rule_is_valid.py,sha256=O3gCAs_0hpxENK5b7kxxpDmOpKHlXGBWuLGT_97ARSM,1210
|
48
52
|
sonusai/mixture/feature.py,sha256=L0bPFG0RO-CrrtTStUMt_14euYsVo8_TWTP2IKSFKaA,2335
|
49
|
-
sonusai/mixture/generation.py,sha256=
|
50
|
-
sonusai/mixture/helpers.py,sha256=
|
53
|
+
sonusai/mixture/generation.py,sha256=f3DsDvVAAdpvh1lBWV-jMj5qNeZ2qmR9RA_4eI4NDcU,37954
|
54
|
+
sonusai/mixture/helpers.py,sha256=nNqK__MBp8f10telUU3A8FhkNeXYPGCx8dxxDpzCAbg,15464
|
55
|
+
sonusai/mixture/ir_delay.py,sha256=WRoYjuHpsppe0D5qQExNxsCyKbMPDfWJ4CTlr3Ps50k,2036
|
51
56
|
sonusai/mixture/log_duration_and_sizes.py,sha256=qhgl87C2KbjxLdKEpjYOoqNL6rc-8-PB4R7Gx_7UG8g,1240
|
52
|
-
sonusai/mixture/mixdb.py,sha256=
|
53
|
-
sonusai/mixture/soundfile_audio.py,sha256=At_ZC2b9pZ_9IYp1UxyPzRoBK9-1cKPCLMm74F1AjKE,4092
|
54
|
-
sonusai/mixture/sox_audio.py,sha256=7ouCLqXYS6tjG2L0v5lugVO7z5UwJmsr1VigbrXhs74,16725
|
55
|
-
sonusai/mixture/sox_augmentation.py,sha256=DtfGLPaB1BIt2wvTEA__MYkGFNU85Tuup5BFsIVrh0E,4546
|
57
|
+
sonusai/mixture/mixdb.py,sha256=oMBbi0HRiEBtN7lDup8qhPBIQ_td89CHa0bYy2PXdWQ,78744
|
56
58
|
sonusai/mixture/spectral_mask.py,sha256=U9XJ_SAoI9b67K_3SE7bNw6U8cPGFOBttaZAxMjA_Jc,2042
|
57
59
|
sonusai/mixture/target_class_balancing.py,sha256=o_TZ8kVYq10lgeXHh3GUFfflfdUvRt0FekFu2eaNkDs,4251
|
58
|
-
sonusai/mixture/targets.py,sha256=
|
60
|
+
sonusai/mixture/targets.py,sha256=oOeqdE-n-sCq_9luEt82HEP0MRCaHG_7J-p3nCftkAc,6399
|
59
61
|
sonusai/mixture/tokenized_shell_vars.py,sha256=lXTzUDutuBWGV1zIsqeIxWmy-eKm0Vx1y8-iLdsL1gQ,4921
|
60
|
-
sonusai/mixture/torchaudio_audio.py,sha256=72Hxo5TKAW7mYpRy15QFfD7AYDORBk6bVCcHENniWGw,3116
|
61
|
-
sonusai/mixture/torchaudio_augmentation.py,sha256=uFAKxIfs50J5FR-WXodsEACm2Ao-t5dZRSJ0DwTAfBg,3930
|
62
62
|
sonusai/mixture/truth.py,sha256=-CwwawFRGjqodR2yKvAMGL1XaYLct-tli7wZ2gbhLtQ,2121
|
63
63
|
sonusai/mixture/truth_functions/__init__.py,sha256=0mlOFChPnXG5BC0eKOe4n9VH17jY4iOqZFLuF6Gprdk,1505
|
64
64
|
sonusai/mixture/truth_functions/crm.py,sha256=iidcffXfqV8k9O5wt5KTWIAFaTSjmhV5ucKZPbTgpvQ,3809
|
65
|
-
sonusai/mixture/truth_functions/energy.py,sha256=
|
65
|
+
sonusai/mixture/truth_functions/energy.py,sha256=BMpyFoFDRsKEv3ZxZAJPLgMgkBkA6AtGBg3MjRu1do8,6749
|
66
66
|
sonusai/mixture/truth_functions/file.py,sha256=pyCAhx3PhJRBoZMrjoQI4Tbi5TN7sPembSVEr80Bu3g,1431
|
67
67
|
sonusai/mixture/truth_functions/metadata.py,sha256=aEZly5bJEaZpUBZonWvcu14_Dn3M2HamwTaM5Bg7Tm8,778
|
68
|
-
sonusai/mixture/truth_functions/metrics.py,sha256=
|
68
|
+
sonusai/mixture/truth_functions/metrics.py,sha256=AzQjKJ7rihk_UXOz0Atyktpzo2g9ZPMZVZPCESBIoao,876
|
69
69
|
sonusai/mixture/truth_functions/phoneme.py,sha256=jwBYiNwwBwh2tHtOJ2NopYWhT6y19kXzSIag0XW9GSY,778
|
70
70
|
sonusai/mixture/truth_functions/sed.py,sha256=C0n9DkfBNQblFsFCkPbooy54KuHSY7B0f1vLft2asdw,3832
|
71
71
|
sonusai/mixture/truth_functions/target.py,sha256=nSkHFESzCEOljcYf4jQ7FmxsAWJtMCRRWFKM_DyjoLU,4926
|
72
|
-
sonusai/mkwav.py,sha256=
|
73
|
-
sonusai/onnx_predict.py,sha256=
|
72
|
+
sonusai/mkwav.py,sha256=ElivON2G_BT_ffKnePmPoeydl0g2DLGrbIFxfn_I1XI,4058
|
73
|
+
sonusai/onnx_predict.py,sha256=T97ceb9stR_QtJCA-Rmv67OIeaLdyhyCf1jQ9kVOYn8,8698
|
74
74
|
sonusai/queries/__init__.py,sha256=bhoeOFfu9GA5DOUuxRrIev7MYdXaGN8xdKJ6BXyNNtQ,277
|
75
|
-
sonusai/queries/queries.py,sha256=
|
75
|
+
sonusai/queries/queries.py,sha256=srcEYBqLJhjqyfuJ-FwNkUwpjxYiNQeybxL3eQGm2nw,7511
|
76
76
|
sonusai/speech/__init__.py,sha256=vqAymCBPjMUSM4OZKHTai6BYwXsOBlf_G_vOhELVf8I,133
|
77
77
|
sonusai/speech/l2arctic.py,sha256=VQNKuTbmlbW0PJ7bOjx9sr0VjUYxJnxfTiPJIa4OOaA,3829
|
78
78
|
sonusai/speech/librispeech.py,sha256=ugP3NVOenSsBF1cUG4Nyl7dumGHQmE4Ugk1yYjtOyj4,3070
|
@@ -83,9 +83,9 @@ sonusai/speech/types.py,sha256=4eKVPAktpkIrZ2qoVp2iT45zxTVNocQEGT6O_Zlub_w,214
|
|
83
83
|
sonusai/speech/vctk.py,sha256=WInvRRRkZCW6t_NcZAJffJzgCbyetal-j2w0kKX5SDw,1527
|
84
84
|
sonusai/speech/voxceleb.py,sha256=Uu1kB1krf8hess1yuvGbYfV_VgYhklEyoz4I7KfrVpw,2658
|
85
85
|
sonusai/summarize_metric_spenh.py,sha256=2w81ZgJahYvD6wCpE3DFoUFrXexLXjO44ITRVm1HJXw,1858
|
86
|
-
sonusai/utils/__init__.py,sha256=
|
86
|
+
sonusai/utils/__init__.py,sha256=D7IFq4Ozy_DRq4pC50YRxGQybqWEDXglCuAgxNIpFyU,2413
|
87
87
|
sonusai/utils/asl_p56.py,sha256=cPUVwXawF7vLJgs4zUtoRGk7Wdbe5KKti_-v_8xIU10,3862
|
88
|
-
sonusai/utils/asr.py,sha256=
|
88
|
+
sonusai/utils/asr.py,sha256=ubiU3E61HN3r9MhPV7ci37cnLZowll8KfjUS7os3Sho,2822
|
89
89
|
sonusai/utils/asr_functions/__init__.py,sha256=HKGRm_c48tcxlfwqH63m-MvhAoK_pCcw76lxmFmiP_U,63
|
90
90
|
sonusai/utils/asr_functions/aaware_whisper.py,sha256=M9Y8Pgh1oIrDOPZZPSRPDig8foxfgs3f8AsoZ8W00B0,2120
|
91
91
|
sonusai/utils/audio_devices.py,sha256=_Eiah86SZjbdp2baD2AUVF4FmhseiNuG3KJkd_LbULk,2041
|
@@ -104,7 +104,7 @@ sonusai/utils/get_frames_per_batch.py,sha256=xnq4tV7MT74N0H6b5ZsiAezqdXucboCLQw1
|
|
104
104
|
sonusai/utils/get_label_names.py,sha256=df4jZVaQ3WnYQqNj21iUV4aYWyQEZUNmgs93qKW-_rA,820
|
105
105
|
sonusai/utils/grouper.py,sha256=qyZ0nj84yOrC-RZsXHC-KJvcUliGktnV8S6-P3PD6_w,203
|
106
106
|
sonusai/utils/human_readable_size.py,sha256=DOCS7SAymrtTZli8AczvyCMCh44r7ZDgVBA7jSZupmA,356
|
107
|
-
sonusai/utils/load_object.py,sha256
|
107
|
+
sonusai/utils/load_object.py,sha256=if4Vammcd-jZTz_n7QzwNIlN4HqSL0v91I9YQzcvEEA,493
|
108
108
|
sonusai/utils/max_text_width.py,sha256=pxiJMwb_zlkNntexgo7S6lAuF7NLLZvFdOCkxdsQJVY,315
|
109
109
|
sonusai/utils/model_utils.py,sha256=OIJBhOjxR0wpxsd7A2r6J2AjqfdYgZzi6UEThw4S1lI,828
|
110
110
|
sonusai/utils/numeric_conversion.py,sha256=iFPXFU8C_1mW5tmDqHq8-xP1tL8nVaSmhQRakdCqy30,328
|
@@ -117,11 +117,12 @@ sonusai/utils/read_predict_data.py,sha256=PUSroxmWQGtr6_EcdSHmIFQoRGou8CKKqcggWy
|
|
117
117
|
sonusai/utils/reshape.py,sha256=Ozuh3UlmAS5NCeOK7NR8KgcQacHvgq10pys0VfCnOPU,5746
|
118
118
|
sonusai/utils/seconds_to_hms.py,sha256=9Ya9O97txFtTIXZUQw1K8g7b7Xx-ptvUtMUlzsIduTo,260
|
119
119
|
sonusai/utils/stacked_complex.py,sha256=JW6iAa1C-4Tuh4dD5c-D-O-yo-OY5Xm0AKVU0YsqsJU,2782
|
120
|
-
sonusai/utils/stratified_shuffle_split.py,sha256=
|
120
|
+
sonusai/utils/stratified_shuffle_split.py,sha256=fcGW8nkZIwUqq1qtxbK_ZH58sYULqZfv7iNBQnKGH-M,6706
|
121
|
+
sonusai/utils/temp_seed.py,sha256=Ava5TCGpvDBtaRx2l-40CuGIjhgLevu1KFfZsgr38qM,218
|
121
122
|
sonusai/utils/write_audio.py,sha256=0lKdaX57N6H-UWdioqmXCJMjwT1eBz5B-bSGqDvloAc,838
|
122
123
|
sonusai/utils/yes_or_no.py,sha256=0h1okjXmDNbJp7rZJFR2V-HFU1GJDm3YFTUVmYExkOU,263
|
123
124
|
sonusai/vars.py,sha256=kBBzuvC8szmdIZEEDA7XXmD765addZKdM2aFipeGO1w,933
|
124
|
-
sonusai-0.
|
125
|
-
sonusai-0.
|
126
|
-
sonusai-0.
|
127
|
-
sonusai-0.
|
125
|
+
sonusai-0.20.2.dist-info/METADATA,sha256=CT_z1tJfku142nH0PL22DT7EEc8bFfJj9qyWcR7v6FU,2535
|
126
|
+
sonusai-0.20.2.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
127
|
+
sonusai-0.20.2.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
|
128
|
+
sonusai-0.20.2.dist-info/RECORD,,
|
@@ -1,130 +0,0 @@
|
|
1
|
-
from pathlib import Path
|
2
|
-
|
3
|
-
from sonusai.mixture.datatypes import AudioT
|
4
|
-
from sonusai.mixture.datatypes import ImpulseResponseData
|
5
|
-
|
6
|
-
|
7
|
-
def _raw_read(name: str | Path) -> tuple[AudioT, int]:
|
8
|
-
import numpy as np
|
9
|
-
import soundfile
|
10
|
-
from pydub import AudioSegment
|
11
|
-
|
12
|
-
from .tokenized_shell_vars import tokenized_expand
|
13
|
-
|
14
|
-
expanded_name, _ = tokenized_expand(name)
|
15
|
-
|
16
|
-
try:
|
17
|
-
if expanded_name.endswith(".mp3"):
|
18
|
-
sound = AudioSegment.from_mp3(expanded_name)
|
19
|
-
raw = np.array(sound.get_array_of_samples()).astype(np.float32).reshape((-1, sound.channels))
|
20
|
-
raw = raw / 2 ** (sound.sample_width * 8 - 1)
|
21
|
-
sample_rate = sound.frame_rate
|
22
|
-
elif expanded_name.endswith(".m4a"):
|
23
|
-
sound = AudioSegment.from_file(expanded_name)
|
24
|
-
raw = np.array(sound.get_array_of_samples()).astype(np.float32).reshape((-1, sound.channels))
|
25
|
-
raw = raw / 2 ** (sound.sample_width * 8 - 1)
|
26
|
-
sample_rate = sound.frame_rate
|
27
|
-
else:
|
28
|
-
raw, sample_rate = soundfile.read(expanded_name, always_2d=True, dtype="float32")
|
29
|
-
except Exception as e:
|
30
|
-
if name != expanded_name:
|
31
|
-
raise OSError(f"Error reading {name} (expanded: {expanded_name}): {e}") from e
|
32
|
-
else:
|
33
|
-
raise OSError(f"Error reading {name}: {e}") from e
|
34
|
-
|
35
|
-
return np.squeeze(raw[:, 0].astype(np.float32)), sample_rate
|
36
|
-
|
37
|
-
|
38
|
-
def get_sample_rate(name: str | Path) -> int:
|
39
|
-
"""Get sample rate from audio file using soundfile
|
40
|
-
|
41
|
-
:param name: File name
|
42
|
-
:return: Sample rate
|
43
|
-
"""
|
44
|
-
import soundfile
|
45
|
-
from pydub import AudioSegment
|
46
|
-
|
47
|
-
from .tokenized_shell_vars import tokenized_expand
|
48
|
-
|
49
|
-
expanded_name, _ = tokenized_expand(name)
|
50
|
-
|
51
|
-
try:
|
52
|
-
if expanded_name.endswith(".mp3"):
|
53
|
-
return AudioSegment.from_mp3(expanded_name).frame_rate
|
54
|
-
|
55
|
-
if expanded_name.endswith(".m4a"):
|
56
|
-
return AudioSegment.from_file(expanded_name).frame_rate
|
57
|
-
|
58
|
-
return soundfile.info(expanded_name).samplerate
|
59
|
-
except Exception as e:
|
60
|
-
if name != expanded_name:
|
61
|
-
raise OSError(f"Error reading {name} (expanded: {expanded_name}): {e}") from e
|
62
|
-
else:
|
63
|
-
raise OSError(f"Error reading {name}: {e}") from e
|
64
|
-
|
65
|
-
|
66
|
-
def read_ir(name: str | Path) -> ImpulseResponseData:
|
67
|
-
"""Read impulse response data using soundfile
|
68
|
-
|
69
|
-
:param name: File name
|
70
|
-
:return: ImpulseResponseData object
|
71
|
-
"""
|
72
|
-
import numpy as np
|
73
|
-
|
74
|
-
from .datatypes import ImpulseResponseData
|
75
|
-
|
76
|
-
# Read impulse response data from audio file
|
77
|
-
out, sample_rate = _raw_read(name)
|
78
|
-
offset = np.argmax(out)
|
79
|
-
out = out[offset:]
|
80
|
-
out = out / np.linalg.norm(out)
|
81
|
-
|
82
|
-
return ImpulseResponseData(name=str(name), sample_rate=sample_rate, data=out)
|
83
|
-
|
84
|
-
|
85
|
-
def read_audio(name: str | Path) -> AudioT:
|
86
|
-
"""Read audio data from a file using soundfile
|
87
|
-
|
88
|
-
:param name: File name
|
89
|
-
:return: Array of time domain audio data
|
90
|
-
"""
|
91
|
-
import librosa
|
92
|
-
|
93
|
-
from .constants import SAMPLE_RATE
|
94
|
-
|
95
|
-
out, sample_rate = _raw_read(name)
|
96
|
-
out = librosa.resample(out, orig_sr=sample_rate, target_sr=SAMPLE_RATE, res_type="soxr_hq")
|
97
|
-
|
98
|
-
return out
|
99
|
-
|
100
|
-
|
101
|
-
def get_num_samples(name: str | Path) -> int:
|
102
|
-
"""Get the number of samples resampled to the SonusAI sample rate in the given file
|
103
|
-
|
104
|
-
:param name: File name
|
105
|
-
:return: number of samples in resampled audio
|
106
|
-
"""
|
107
|
-
import math
|
108
|
-
|
109
|
-
import soundfile
|
110
|
-
from pydub import AudioSegment
|
111
|
-
|
112
|
-
from .constants import SAMPLE_RATE
|
113
|
-
from .tokenized_shell_vars import tokenized_expand
|
114
|
-
|
115
|
-
expanded_name, _ = tokenized_expand(name)
|
116
|
-
|
117
|
-
if expanded_name.endswith(".mp3"):
|
118
|
-
sound = AudioSegment.from_mp3(expanded_name)
|
119
|
-
samples = sound.frame_count()
|
120
|
-
sample_rate = sound.frame_rate
|
121
|
-
elif expanded_name.endswith(".m4a"):
|
122
|
-
sound = AudioSegment.from_file(expanded_name)
|
123
|
-
samples = sound.frame_count()
|
124
|
-
sample_rate = sound.frame_rate
|
125
|
-
else:
|
126
|
-
info = soundfile.info(name)
|
127
|
-
samples = info.frames
|
128
|
-
sample_rate = info.samplerate
|
129
|
-
|
130
|
-
return math.ceil(SAMPLE_RATE * samples / sample_rate)
|