You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/mbrola.py
+37-20Lines changed: 37 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
References:
5
5
Dutoit, T., Pagel, V., Pierret, N., Bataille, F., & Van der Vrecken, O. (1996, October). The MBROLA project: Towards a set of high quality speech synthesizers free of use for non commercial purposes. In Proceeding of Fourth International Conference on Spoken Language Processing. ICSLP'96 (Vol. 3, pp. 1393-1396). IEEE. https://doi.org/10.1109/ICSLP.1996.607874
6
-
"""# pylint: disable=line-too-long
6
+
"""
7
7
8
8
importos
9
9
frompathlibimportPath
@@ -32,7 +32,7 @@ def validate_word(
32
32
33
33
Returns:
34
34
str: validated word.
35
-
"""# pylint: disable=line-too-long
35
+
"""
36
36
iflen(word) >max_chars:
37
37
raiseValueError(f"`word` exceeds maximum characters ({max_chars})")
38
38
ifre.search(invalid_chars, word):
@@ -58,7 +58,7 @@ def validate_durations(
58
58
59
59
Returns:
60
60
list[int]: Phoneme durations.
61
-
"""# pylint: disable=line-too-long
61
+
"""
62
62
raiseTypeError(
63
63
f"`durations` must be int or list, but {type(durations)} was provided"
64
64
)
@@ -153,24 +153,24 @@ class MBROLA:
153
153
Attributes:
154
154
word (str): label for the mbrola sound.
155
155
phon (Sequence[str]): list of phonemes.
156
-
durations (list[int] | int, optional): phoneme duration in milliseconds. Defaults to 100. If an integer is provided, all phonemes in ``phon`` are assumed to be the same length. If a list is provided, each element in the list indicates the duration of each phoneme.
157
-
pitch (list[int] | int, optional): pitch in Hertz (Hz). Defaults to 200. If an integer is provided, the pitch contour of each phoneme is assumed to be constant at the indicated value. If a list of integers or strings is provided, each element in the list indicates the value at which the pitch contour of each phoneme is kept constant. If a list of lists (of integers or strings), each value in each element describes the pitch contour for each phoneme.
158
-
outer_silences (tuple[int, int], optional): duration in milliseconds of the silence interval to be inserted at onset and offset. Defaults to (1, 1).
156
+
durations (Sequence[int] | int, optional): phoneme duration in milliseconds. Defaults to 100. If an integer is provided, all phonemes in ``phon`` are assumed to be the same length. If a list is provided, each element in the list indicates the duration of each phoneme.
157
+
pitch (int | Sequence[int] | Sequence[int | Sequence[int]], optional): pitch in Hertz (Hz). Defaults to 200. If an integer is provided, the pitch contour of each phoneme is assumed to be constant at the indicated value. If a list of integers or strings is provided, each element in the list indicates the value at which the pitch contour of each phoneme is kept constant. If a list of lists (of integers or strings), each value in each element describes the pitch contour for each phoneme.
158
+
outer_silences (Sequence[int, int], optional): duration in milliseconds of the silence interval to be inserted at onset and offset. Defaults to (1, 1).
A PHO (.pho) file contains the phonological information of the speech sound in a format that MBROLA can read. See more examples in the MBROLA documentation (https://github.com/numediart/MBROLA).
raiseTypeError("`x` must be an instance of MBROLA class")
259
+
254
260
pho= [f"; {x.word}", f"_ {x.outer_silences[0]}"]
261
+
255
262
forph, d, pinzip(x.phon, x.durations, x.pitch):
256
263
p_seq=" ".join([str(pi) forpiinp])
257
264
pho.append(" ".join(map(str, [ph, d, p_seq])))
265
+
258
266
pho.append(f"_ {x.outer_silences[1]}")
267
+
259
268
returnpho
260
269
261
270
@@ -267,21 +276,24 @@ class PlatformException(Exception):
267
276
"""
268
277
269
278
def__init__(self):
270
-
self.message=f"MBROLA is only available on {platform.system()} using the Windows Subsystem for Linux (WSL).\nPlease, follow the instructions in the WSL site: https://learn.microsoft.com/en-us/windows/wsl/install."# pylint: disable=line-too-long
279
+
self.message=f"MBROLA is only available on {platform.system()} using the Windows Subsystem for Linux (WSL).\nPlease, follow the instructions in the WSL site: https://learn.microsoft.com/en-us/windows/wsl/install."
0 commit comments