lingualabpy 0.0.6__tar.gz → 0.1.1__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.
Files changed (29) hide show
  1. lingualabpy-0.1.1/.gitignore +80 -0
  2. {lingualabpy-0.0.6 → lingualabpy-0.1.1}/LICENSE +21 -21
  3. lingualabpy-0.1.1/PKG-INFO +66 -0
  4. {lingualabpy-0.0.6 → lingualabpy-0.1.1}/README.md +4 -4
  5. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/__init__.py +25 -20
  6. lingualabpy-0.1.1/lingualabpy/_version.py +34 -0
  7. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/audio/metrics.py +85 -85
  8. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/audio/triming.py +11 -11
  9. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/cli/audio_metrics.py +59 -59
  10. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/cli/audio_triming.py +48 -48
  11. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/cli/docx2json.py +21 -21
  12. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/cli/jsons2csv.py +23 -23
  13. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/cli/plot_sound.py +55 -55
  14. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/io.py +49 -49
  15. lingualabpy-0.1.1/lingualabpy/neuroimaging/hcp_connectome.py +151 -0
  16. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/plot.py +23 -23
  17. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/text/parser.py +35 -35
  18. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/text/textgrid.py +41 -41
  19. lingualabpy-0.1.1/lingualabpy/tools/__init__.py +0 -0
  20. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/tools/data.py +41 -41
  21. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/tools/interval.py +59 -59
  22. {lingualabpy-0.0.6 → lingualabpy-0.1.1}/pyproject.toml +78 -56
  23. lingualabpy-0.0.6/PKG-INFO +0 -46
  24. lingualabpy-0.0.6/src/lingualabpy/resources/FilledPauses.praat +0 -536
  25. lingualabpy-0.0.6/src/lingualabpy/resources/syllablenucleiv3.praat +0 -0
  26. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/audio/__init__.py +0 -0
  27. {lingualabpy-0.0.6/src → lingualabpy-0.1.1}/lingualabpy/cli/__init__.py +0 -0
  28. {lingualabpy-0.0.6/src/lingualabpy/text → lingualabpy-0.1.1/lingualabpy/neuroimaging}/__init__.py +0 -0
  29. {lingualabpy-0.0.6/src/lingualabpy/tools → lingualabpy-0.1.1/lingualabpy/text}/__init__.py +0 -0
@@ -0,0 +1,80 @@
1
+ # lingualabpy
2
+ idea/
3
+ docs/
4
+
5
+ # hatch.build.hooks.vcs
6
+ _version.py
7
+
8
+ # Byte-compiled / optimized / DLL files
9
+ __pycache__/
10
+ *.py[codz]
11
+ *$py.class
12
+
13
+ # C extensions
14
+ *.so
15
+
16
+ # Distribution / packaging
17
+ .Python
18
+ build/
19
+ develop-eggs/
20
+ dist/
21
+ downloads/
22
+ eggs/
23
+ .eggs/
24
+ lib/
25
+ lib64/
26
+ parts/
27
+ sdist/
28
+ var/
29
+ wheels/
30
+ share/python-wheels/
31
+ *.egg-info/
32
+ .installed.cfg
33
+ *.egg
34
+ MANIFEST
35
+
36
+ # PyInstaller
37
+ # Usually these files are written by a python script from a template
38
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
39
+ *.manifest
40
+ *.spec
41
+
42
+ # Installer logs
43
+ pip-log.txt
44
+ pip-delete-this-directory.txt
45
+
46
+ # Unit test / coverage reports
47
+ htmlcov/
48
+ .tox/
49
+ .nox/
50
+ .coverage
51
+ .coverage.*
52
+ .cache
53
+ nosetests.xml
54
+ coverage.xml
55
+ *.cover
56
+ *.py.cover
57
+ .hypothesis/
58
+ .pytest_cache/
59
+ cover/
60
+
61
+ # Environments
62
+ .env
63
+ .envrc
64
+ .venv
65
+ env/
66
+ venv/
67
+ ENV/
68
+ env.bak/
69
+ venv.bak/
70
+
71
+ # mkdocs documentation
72
+ /site
73
+
74
+ # mypy
75
+ .mypy_cache/
76
+ .dmypy.json
77
+ dmypy.json
78
+
79
+ # Ruff stuff:
80
+ .ruff_cache/
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Lingua Laboratory
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Lingua Laboratory
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: lingualabpy
3
+ Version: 0.1.1
4
+ Summary: Tools and utilities from the LINGUA laboratory
5
+ Project-URL: Documentation, https://github.com/lingualab/lingualabpy
6
+ Project-URL: Source, https://github.com/lingualab/lingualabpy
7
+ Project-URL: Tracker, https://github.com/lingualab/lingualabpy/issues
8
+ Author-email: Christophe Bedetti <christophe.bedetti@umontreal.ca>
9
+ License: MIT License
10
+
11
+ Copyright (c) 2024 Lingua Laboratory
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Classifier: Development Status :: 3 - Alpha
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: MacOS :: MacOS X
36
+ Classifier: Operating System :: Microsoft :: Windows
37
+ Classifier: Operating System :: POSIX :: Linux
38
+ Classifier: Programming Language :: Python :: 3 :: Only
39
+ Classifier: Programming Language :: Python :: 3.8
40
+ Classifier: Programming Language :: Python :: 3.9
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Topic :: Scientific/Engineering
44
+ Requires-Python: >=3.8.1
45
+ Requires-Dist: click
46
+ Requires-Dist: matplotlib
47
+ Requires-Dist: nilearn==0.12.1
48
+ Requires-Dist: opencv-python
49
+ Requires-Dist: pandas
50
+ Requires-Dist: praat-parselmouth
51
+ Requires-Dist: praat-textgrids
52
+ Requires-Dist: pydub
53
+ Requires-Dist: python-docx
54
+ Provides-Extra: style
55
+ Requires-Dist: black; extra == 'style'
56
+ Requires-Dist: ruff; extra == 'style'
57
+ Provides-Extra: test
58
+ Requires-Dist: pytest; extra == 'test'
59
+ Requires-Dist: pytest-cov; extra == 'test'
60
+ Description-Content-Type: text/markdown
61
+
62
+ # lingualabpy
63
+
64
+ Tools and utilities from the LINGUA laboratory
65
+
66
+ These tools are used in the pipeline [speechmetryflow](https://github.com/lingualab/speechmetryflow)
@@ -1,5 +1,5 @@
1
- # lingualabpy
2
-
3
- Tools and utilities from the LINGUA laboratory
4
-
1
+ # lingualabpy
2
+
3
+ Tools and utilities from the LINGUA laboratory
4
+
5
5
  These tools are used in the pipeline [speechmetryflow](https://github.com/lingualab/speechmetryflow)
@@ -1,20 +1,25 @@
1
- # -------------------------------------------------------------
2
- # Licensed under the MIT License. See LICENSE in project root for information.
3
- # -------------------------------------------------------------
4
- """lingualabpy"""
5
- from __future__ import annotations
6
-
7
- __version__ = "0.0.6"
8
-
9
- default_config = {
10
- "participant_col": "participant_id",
11
- "participant_label": "IE",
12
- "clinician_label": "IV",
13
- "f0_bounds": {
14
- "female": [100.0, 600.0],
15
- "male": [75.0, 300.0],
16
- },
17
- "unit_frequency": "Hertz",
18
- }
19
-
20
- from lingualabpy.io import read_audio, read_docx, read_json, write_json, read_textgrid
1
+ # -------------------------------------------------------------
2
+ # Licensed under the MIT License. See LICENSE in project root for information.
3
+ # -------------------------------------------------------------
4
+ """lingualabpy"""
5
+
6
+ from __future__ import annotations
7
+
8
+ try:
9
+ from lingualabpy._version import __version__
10
+ except ImportError:
11
+ pass
12
+
13
+
14
+ default_config = {
15
+ "participant_col": "participant_id",
16
+ "participant_label": "IE",
17
+ "clinician_label": "IV",
18
+ "f0_bounds": {
19
+ "female": [100.0, 600.0],
20
+ "male": [75.0, 300.0],
21
+ },
22
+ "unit_frequency": "Hertz",
23
+ }
24
+
25
+ from lingualabpy.io import read_audio, read_docx, read_json, write_json, read_textgrid
@@ -0,0 +1,34 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
12
+
13
+ TYPE_CHECKING = False
14
+ if TYPE_CHECKING:
15
+ from typing import Tuple
16
+ from typing import Union
17
+
18
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
20
+ else:
21
+ VERSION_TUPLE = object
22
+ COMMIT_ID = object
23
+
24
+ version: str
25
+ __version__: str
26
+ __version_tuple__: VERSION_TUPLE
27
+ version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
30
+
31
+ __version__ = version = '0.1.1'
32
+ __version_tuple__ = version_tuple = (0, 1, 1)
33
+
34
+ __commit_id__ = commit_id = None
@@ -1,85 +1,85 @@
1
- from collections import defaultdict
2
- import numpy as np
3
- from parselmouth import Sound
4
- from parselmouth.praat import call
5
-
6
- from lingualabpy.tools.data import UnchangeableDict
7
-
8
-
9
- def measure_pitch(sound: Sound, f0min: str, f0max: str, unit: str) -> UnchangeableDict:
10
- """
11
- This function measures duration, pitch, HNR, jitter, and shimmer
12
- This is the function to measure source acoustics using default male parameters.
13
- """
14
- # compute usefull praat object
15
- pitch = call(sound, "To Pitch", 0.0, f0min, f0max)
16
- harmonicity = call(sound, "To Harmonicity (cc)", 0.01, f0min, 0.1, 1.0)
17
- point_process = call(sound, "To PointProcess (periodic, cc)", f0min, f0max)
18
-
19
- # metrics container
20
- metrics = UnchangeableDict()
21
-
22
- # Metrics computation
23
- metrics["duration"] = call(sound, "Get total duration")
24
- metrics["f0_mean"] = call(pitch, "Get mean", 0, 0, unit)
25
- metrics["F0_std"] = call(pitch, "Get standard deviation", 0, 0, unit)
26
- metrics["hnr"] = call(harmonicity, "Get mean", 0, 0)
27
-
28
- # jitter
29
- jitter_types = ["local", ["local", "absolute"], "rap", "ppq5", "ddp"]
30
- for jitter_type in jitter_types:
31
- if isinstance(jitter_type, list):
32
- metric_name = f"jitter_{'_'.join(jitter_type)}"
33
- praat_function = f"Get jitter ({', '.join(jitter_type)})"
34
- else:
35
- metric_name = f"jitter_{jitter_type}"
36
- praat_function = f"Get jitter ({jitter_type})"
37
- metrics[metric_name] = call(
38
- point_process, praat_function, 0, 0, 0.0001, 0.02, 1.3
39
- )
40
-
41
- # shimmer
42
- shimmer_types = ["local", "local_dB", "apq3", "apq5", "apq11", "dda"]
43
- for shimmer_type in shimmer_types:
44
- metric_name = f"shimmer_{shimmer_type}"
45
- praat_function = f"Get shimmer ({shimmer_type})"
46
- metrics[metric_name] = call(
47
- [sound, point_process], praat_function, 0, 0, 0.0001, 0.02, 1.3, 1.6
48
- )
49
-
50
- return metrics
51
-
52
-
53
- def measure_formants(
54
- sound: Sound, f0min: str, f0max: str, unit: str
55
- ) -> UnchangeableDict:
56
- """
57
- This function measures formants at each glottal pulse
58
-
59
- Puts, D. A., Apicella, C. L., & Cárdenas, R. A. (2012). Masculine voices signal men's threat potential in forager and industrial societies. Proceedings of the Royal Society of London B: Biological Sciences, 279(1728), 601-609.
60
-
61
- Adapted from: DOI 10.17605/OSF.IO/K2BHS
62
- """
63
- # compute usefull praat object
64
- point_process = call(sound, "To PointProcess (periodic, cc)", f0min, f0max)
65
- formants = call(sound, "To Formant (burg)", 0.0025, 5, 5000, 0.025, 50)
66
- number_of_points = call(point_process, "Get number of points")
67
-
68
- # metrics container
69
- metrics = UnchangeableDict()
70
-
71
- # Measure formants only at glottal pulses
72
- formants_list = defaultdict(list)
73
- for index in range(1, number_of_points + 1):
74
- time = call(point_process, "Get time from index", index)
75
- for pulse in [1, 2, 3, 4]:
76
- value = call(formants, "Get value at time", pulse, time, unit, "Linear")
77
- if str(value) != "nan":
78
- formants_list[pulse].append(value)
79
-
80
- # calculate mean and median formants across pulses, median is what is used in all subsequent calculations
81
- for pulse in [1, 2, 3, 4]:
82
- metrics[f"formants_{pulse}_mean"] = np.mean(formants_list[pulse])
83
- metrics[f"formants_{pulse}_median"] = np.median(formants_list[pulse])
84
-
85
- return metrics
1
+ from collections import defaultdict
2
+ import numpy as np
3
+ from parselmouth import Sound
4
+ from parselmouth.praat import call
5
+
6
+ from lingualabpy.tools.data import UnchangeableDict
7
+
8
+
9
+ def measure_pitch(sound: Sound, f0min: str, f0max: str, unit: str) -> UnchangeableDict:
10
+ """
11
+ This function measures duration, pitch, HNR, jitter, and shimmer
12
+ This is the function to measure source acoustics using default male parameters.
13
+ """
14
+ # compute usefull praat object
15
+ pitch = call(sound, "To Pitch", 0.0, f0min, f0max)
16
+ harmonicity = call(sound, "To Harmonicity (cc)", 0.01, f0min, 0.1, 1.0)
17
+ point_process = call(sound, "To PointProcess (periodic, cc)", f0min, f0max)
18
+
19
+ # metrics container
20
+ metrics = UnchangeableDict()
21
+
22
+ # Metrics computation
23
+ metrics["duration"] = call(sound, "Get total duration")
24
+ metrics["f0_mean"] = call(pitch, "Get mean", 0, 0, unit)
25
+ metrics["F0_std"] = call(pitch, "Get standard deviation", 0, 0, unit)
26
+ metrics["hnr"] = call(harmonicity, "Get mean", 0, 0)
27
+
28
+ # jitter
29
+ jitter_types = ["local", ["local", "absolute"], "rap", "ppq5", "ddp"]
30
+ for jitter_type in jitter_types:
31
+ if isinstance(jitter_type, list):
32
+ metric_name = f"jitter_{'_'.join(jitter_type)}"
33
+ praat_function = f"Get jitter ({', '.join(jitter_type)})"
34
+ else:
35
+ metric_name = f"jitter_{jitter_type}"
36
+ praat_function = f"Get jitter ({jitter_type})"
37
+ metrics[metric_name] = call(
38
+ point_process, praat_function, 0, 0, 0.0001, 0.02, 1.3
39
+ )
40
+
41
+ # shimmer
42
+ shimmer_types = ["local", "local_dB", "apq3", "apq5", "apq11", "dda"]
43
+ for shimmer_type in shimmer_types:
44
+ metric_name = f"shimmer_{shimmer_type}"
45
+ praat_function = f"Get shimmer ({shimmer_type})"
46
+ metrics[metric_name] = call(
47
+ [sound, point_process], praat_function, 0, 0, 0.0001, 0.02, 1.3, 1.6
48
+ )
49
+
50
+ return metrics
51
+
52
+
53
+ def measure_formants(
54
+ sound: Sound, f0min: str, f0max: str, unit: str
55
+ ) -> UnchangeableDict:
56
+ """
57
+ This function measures formants at each glottal pulse
58
+
59
+ Puts, D. A., Apicella, C. L., & Cárdenas, R. A. (2012). Masculine voices signal men's threat potential in forager and industrial societies. Proceedings of the Royal Society of London B: Biological Sciences, 279(1728), 601-609.
60
+
61
+ Adapted from: DOI 10.17605/OSF.IO/K2BHS
62
+ """
63
+ # compute usefull praat object
64
+ point_process = call(sound, "To PointProcess (periodic, cc)", f0min, f0max)
65
+ formants = call(sound, "To Formant (burg)", 0.0025, 5, 5000, 0.025, 50)
66
+ number_of_points = call(point_process, "Get number of points")
67
+
68
+ # metrics container
69
+ metrics = UnchangeableDict()
70
+
71
+ # Measure formants only at glottal pulses
72
+ formants_list = defaultdict(list)
73
+ for index in range(1, number_of_points + 1):
74
+ time = call(point_process, "Get time from index", index)
75
+ for pulse in [1, 2, 3, 4]:
76
+ value = call(formants, "Get value at time", pulse, time, unit, "Linear")
77
+ if str(value) != "nan":
78
+ formants_list[pulse].append(value)
79
+
80
+ # calculate mean and median formants across pulses, median is what is used in all subsequent calculations
81
+ for pulse in [1, 2, 3, 4]:
82
+ metrics[f"formants_{pulse}_mean"] = np.mean(formants_list[pulse])
83
+ metrics[f"formants_{pulse}_median"] = np.median(formants_list[pulse])
84
+
85
+ return metrics
@@ -1,11 +1,11 @@
1
- from pydub import AudioSegment
2
-
3
-
4
- def extract_audio(audio: AudioSegment, intervals: list[list[float]]) -> AudioSegment:
5
- """"""
6
- new_audio = AudioSegment.empty()
7
-
8
- for start, end in intervals:
9
- new_audio += audio[start * 1000 : end * 1000]
10
-
11
- return new_audio
1
+ from pydub import AudioSegment
2
+
3
+
4
+ def extract_audio(audio: AudioSegment, intervals: list[list[float]]) -> AudioSegment:
5
+ """"""
6
+ new_audio = AudioSegment.empty()
7
+
8
+ for start, end in intervals:
9
+ new_audio += audio[start * 1000 : end * 1000]
10
+
11
+ return new_audio
@@ -1,59 +1,59 @@
1
- import click
2
- from parselmouth import Sound
3
- from pathlib import Path
4
-
5
- from lingualabpy import default_config, write_json
6
- from lingualabpy.audio.metrics import measure_pitch, measure_formants
7
-
8
-
9
- @click.command()
10
- @click.option(
11
- "--sex",
12
- type=click.Choice(["female", "male"]),
13
- help=f"Set f0min and f0max for praat analysis. {default_config['f0_bounds']}",
14
- )
15
- @click.option(
16
- "--f0min",
17
- type=float,
18
- help="Define f0min for praat analysis. Not required if sex is specify",
19
- )
20
- @click.option(
21
- "--f0max",
22
- type=float,
23
- help="Define f0max for praat analysis. Not required if sex is specify",
24
- )
25
- @click.option(
26
- "--unit_frequency",
27
- default=default_config["unit_frequency"],
28
- show_default=True,
29
- )
30
- @click.option("--participant_id", "-p", default=None, help="")
31
- @click.option("--output_json", default=None, help="")
32
- @click.argument("audiofile", nargs=1, type=click.Path(exists=True))
33
- def main(sex, f0min, f0max, unit_frequency, participant_id, output_json, audiofile):
34
- """Doc"""
35
- if sex:
36
- f0min, f0max = default_config["f0_bounds"][sex]
37
- else:
38
- if not f0min or not f0max:
39
- raise click.UsageError(
40
- "'--f0min' and '--f0max' are required if '--sex' is not specified"
41
- )
42
-
43
- sound = Sound(audiofile)
44
- metrics = measure_pitch(sound, f0min, f0max, unit_frequency)
45
- metrics.update(measure_formants(sound, f0min, f0max, unit_frequency))
46
-
47
- audiofile_stem = Path(audiofile).stem
48
-
49
- if participant_id:
50
- metrics["participant_id"] = participant_id
51
-
52
- audiofile = Path(audiofile)
53
-
54
- metrics["filename"] = audiofile.name
55
-
56
- if not output_json:
57
- output_json = audiofile.stem + "_metric-audio.json"
58
-
59
- write_json(dict(metrics), output_json)
1
+ import click
2
+ from parselmouth import Sound
3
+ from pathlib import Path
4
+
5
+ from lingualabpy import default_config, write_json
6
+ from lingualabpy.audio.metrics import measure_pitch, measure_formants
7
+
8
+
9
+ @click.command()
10
+ @click.option(
11
+ "--sex",
12
+ type=click.Choice(["female", "male"]),
13
+ help=f"Set f0min and f0max for praat analysis. {default_config['f0_bounds']}",
14
+ )
15
+ @click.option(
16
+ "--f0min",
17
+ type=float,
18
+ help="Define f0min for praat analysis. Not required if sex is specify",
19
+ )
20
+ @click.option(
21
+ "--f0max",
22
+ type=float,
23
+ help="Define f0max for praat analysis. Not required if sex is specify",
24
+ )
25
+ @click.option(
26
+ "--unit_frequency",
27
+ default=default_config["unit_frequency"],
28
+ show_default=True,
29
+ )
30
+ @click.option("--participant_id", "-p", default=None, help="")
31
+ @click.option("--output_json", default=None, help="")
32
+ @click.argument("audiofile", nargs=1, type=click.Path(exists=True))
33
+ def main(sex, f0min, f0max, unit_frequency, participant_id, output_json, audiofile):
34
+ """Doc"""
35
+ if sex:
36
+ f0min, f0max = default_config["f0_bounds"][sex]
37
+ else:
38
+ if not f0min or not f0max:
39
+ raise click.UsageError(
40
+ "'--f0min' and '--f0max' are required if '--sex' is not specified"
41
+ )
42
+
43
+ sound = Sound(audiofile)
44
+ metrics = measure_pitch(sound, f0min, f0max, unit_frequency)
45
+ metrics.update(measure_formants(sound, f0min, f0max, unit_frequency))
46
+
47
+ audiofile_stem = Path(audiofile).stem
48
+
49
+ if participant_id:
50
+ metrics["participant_id"] = participant_id
51
+
52
+ audiofile = Path(audiofile)
53
+
54
+ metrics["filename"] = audiofile.name
55
+
56
+ if not output_json:
57
+ output_json = audiofile.stem + "_metric-audio.json"
58
+
59
+ write_json(dict(metrics), output_json)