lingualabpy 0.0.5__py3-none-any.whl → 0.0.6__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.
lingualabpy/__init__.py CHANGED
@@ -4,7 +4,7 @@
4
4
  """lingualabpy"""
5
5
  from __future__ import annotations
6
6
 
7
- __version__ = "0.0.5"
7
+ __version__ = "0.0.6"
8
8
 
9
9
  default_config = {
10
10
  "participant_col": "participant_id",
@@ -0,0 +1,55 @@
1
+ import cv2
2
+ import os
3
+ import click
4
+ from parselmouth import Sound
5
+ import matplotlib.pyplot as plt
6
+ from pathlib import Path
7
+
8
+ from lingualabpy.plot import draw_pitch, draw_spectrogram
9
+
10
+
11
+ @click.command()
12
+ @click.option("--output", default=None, help="")
13
+ @click.argument("audiofile", nargs=1, type=click.Path(exists=True))
14
+ def main(audiofile, output):
15
+ if not output:
16
+ output = Path(audiofile).stem + ".png"
17
+
18
+ sound = Sound(audiofile)
19
+
20
+ pitch = sound.to_pitch()
21
+
22
+ # If desired, pre-emphasize the sound fragment before calculating the spectrogram
23
+ pre_emphasized_snd = sound.copy()
24
+ pre_emphasized_snd.pre_emphasize()
25
+ spectrogram = pre_emphasized_snd.to_spectrogram(
26
+ window_length=0.03, maximum_frequency=8000
27
+ )
28
+
29
+ # amplitude figure
30
+ tmp_amplitude_png = "tmp_amplitude.png"
31
+ amplitude = plt.figure()
32
+ plt.plot(sound.xs(), sound.values.T)
33
+ plt.xlim([sound.xmin, sound.xmax])
34
+ plt.xlabel("time [s]")
35
+ plt.ylabel("amplitude")
36
+ amplitude.set_figwidth(sound.xmax / 4)
37
+ plt.savefig(tmp_amplitude_png)
38
+
39
+ # spectro pitch figure
40
+ tmp_spectro_pitch_png = "tmp_spectro_pitch.png"
41
+ spectro_pitch = plt.figure()
42
+ draw_spectrogram(spectrogram)
43
+ plt.twinx()
44
+ draw_pitch(pitch)
45
+ plt.xlim([sound.xmin, sound.xmax])
46
+ spectro_pitch.set_figwidth(sound.xmax / 4)
47
+ plt.savefig(tmp_spectro_pitch_png)
48
+
49
+ # concatenation
50
+ fig_concat = cv2.vconcat(
51
+ [cv2.imread(tmp_amplitude_png), cv2.imread(tmp_spectro_pitch_png)]
52
+ )
53
+ cv2.imwrite(output, fig_concat)
54
+ os.remove(tmp_amplitude_png)
55
+ os.remove(tmp_spectro_pitch_png)
lingualabpy/plot.py ADDED
@@ -0,0 +1,23 @@
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+
4
+
5
+ def draw_spectrogram(spectrogram, dynamic_range=70):
6
+ X, Y = spectrogram.x_grid(), spectrogram.y_grid()
7
+ sg_db = 10 * np.log10(spectrogram.values)
8
+ plt.pcolormesh(X, Y, sg_db, vmin=sg_db.max() - dynamic_range, cmap="afmhot")
9
+ plt.ylim([spectrogram.ymin, spectrogram.ymax])
10
+ plt.xlabel("time [s]")
11
+ plt.ylabel("frequency [Hz]")
12
+
13
+
14
+ def draw_pitch(pitch):
15
+ # Extract selected pitch contour, and
16
+ # replace unvoiced samples by NaN to not plot
17
+ pitch_values = pitch.selected_array["frequency"]
18
+ pitch_values[pitch_values == 0] = np.nan
19
+ plt.plot(pitch.xs(), pitch_values, "o", markersize=5, color="w")
20
+ plt.plot(pitch.xs(), pitch_values, "o", markersize=2)
21
+ plt.grid(False)
22
+ plt.ylim(0, pitch.ceiling)
23
+ plt.ylabel("fundamental frequency [Hz]")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lingualabpy
3
- Version: 0.0.5
3
+ Version: 0.0.6
4
4
  Summary: Tools and utilities from the LINGUA laboratory
5
5
  Author-email: Christophe Bedetti <christophe.bedetti@umontreal.ca>
6
6
  Requires-Python: >=3.8.1
@@ -19,6 +19,8 @@ Classifier: Programming Language :: Python :: 3.9
19
19
  Classifier: Programming Language :: Python :: 3.10
20
20
  Classifier: Programming Language :: Python :: 3.11
21
21
  Requires-Dist: click
22
+ Requires-Dist: matplotlib
23
+ Requires-Dist: opencv-python
22
24
  Requires-Dist: pandas
23
25
  Requires-Dist: praat-parselmouth
24
26
  Requires-Dist: praat-textgrids
@@ -1,5 +1,6 @@
1
- lingualabpy/__init__.py,sha256=_oiqa1RV-lhkXP60vELtzeIEbRJWn9DagQRqNSDzl-s,642
1
+ lingualabpy/__init__.py,sha256=Ej3OuJSypbV3r_Dv_S1oIf-6Cl6nbzJC2tfOs8HavlQ,642
2
2
  lingualabpy/io.py,sha256=r3Y781XKAea_T3V2L8aJlxoOEQcYCsdd7c-f-8NcEeI,1155
3
+ lingualabpy/plot.py,sha256=KvXXjzUULWy5ibjlgLu4GOHN62YWY2q3IwvBxW_-gfg,859
3
4
  lingualabpy/audio/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
5
  lingualabpy/audio/metrics.py,sha256=u5FlADmqeYQOSpqhY2l1l8CSC4tfBV6cWp3g6Hri6bE,3502
5
6
  lingualabpy/audio/triming.py,sha256=6CY9pH43KFGAPj8Nw34y1YnlOb8gxGLU1btcuRy-Hgc,288
@@ -8,6 +9,7 @@ lingualabpy/cli/audio_metrics.py,sha256=N_kIKmro5bjFEKjHPNfmuY4G5TXQB9qegbc55pUc
8
9
  lingualabpy/cli/audio_triming.py,sha256=H62FTRmwhha-qAXoZ450TNNf_3sHg69GATmbMHQBoCM,1566
9
10
  lingualabpy/cli/docx2json.py,sha256=Bj5f89B76NtA7Xx71xXGnSucrDEyaH9mUFifQo0wfn4,590
10
11
  lingualabpy/cli/jsons2csv.py,sha256=_AcIXiQUCF5SsKqMg6WjTr8fhbuflaJNFrCP91ccSYs,596
12
+ lingualabpy/cli/plot_sound.py,sha256=Vvddh2PWxXLt_uXrHFvHfchEyOCrcMsAhEldgA1LzqE,1658
11
13
  lingualabpy/resources/FilledPauses.praat,sha256=8tY0tAcG71KwnNhawgqyZ7vT__Udf5mSaVutH1eetd8,19623
12
14
  lingualabpy/resources/syllablenucleiv3.praat,sha256=aZYRGB2iLGpYxL3ma-UMutQEyP_NvbbbF1yKhGvVcsA,35818
13
15
  lingualabpy/text/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -16,8 +18,8 @@ lingualabpy/text/textgrid.py,sha256=nTVj3UOCJRsdybxAW0M2jlDq0eMMRYSSo6GdXYkH2wU,
16
18
  lingualabpy/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
19
  lingualabpy/tools/data.py,sha256=FU0_3TaeAZNCu1WpNIOkVBV3bYiEhI1rPw_l8q8z0gk,1523
18
20
  lingualabpy/tools/interval.py,sha256=50lzbMTNHF26mPRG50mykCUQE3pdyRjPWMwsskwy0tg,2060
19
- lingualabpy-0.0.5.dist-info/entry_points.txt,sha256=IXEsa7Cgqjph5bkKSBMXZIBVP4ocrRaSh13dFPBwBmE,247
20
- lingualabpy-0.0.5.dist-info/LICENSE,sha256=s3hbMsmwGq2XFcxpMD3oHc8GSUeXAmPVXJbn7SYXdos,1095
21
- lingualabpy-0.0.5.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
22
- lingualabpy-0.0.5.dist-info/METADATA,sha256=ocw3j6BfTe0NSSKORBs-JjU5KacofzOi81fYRbZ47F4,1703
23
- lingualabpy-0.0.5.dist-info/RECORD,,
21
+ lingualabpy-0.0.6.dist-info/entry_points.txt,sha256=RJc47XeEp4rf6QvUe-o0b9cxPQs3NmreaY_w4hTmIto,302
22
+ lingualabpy-0.0.6.dist-info/LICENSE,sha256=s3hbMsmwGq2XFcxpMD3oHc8GSUeXAmPVXJbn7SYXdos,1095
23
+ lingualabpy-0.0.6.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
24
+ lingualabpy-0.0.6.dist-info/METADATA,sha256=RKuikNjTkwYwXiuwXefV-xpYDmGulMOs6EBgvudyftk,1758
25
+ lingualabpy-0.0.6.dist-info/RECORD,,
@@ -3,4 +3,5 @@ lingualabpy_audio_metrics=lingualabpy.cli.audio_metrics:main
3
3
  lingualabpy_audio_triming=lingualabpy.cli.audio_triming:main
4
4
  lingualabpy_docx2json=lingualabpy.cli.docx2json:main
5
5
  lingualabpy_jsons2csv=lingualabpy.cli.jsons2csv:main
6
+ lingualabpy_plot_sound=lingualabpy.cli.plot_sound:main
6
7