mbrola 0.0.2__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.
- mbrola-0.0.2/.github/workflows/python-publish.yml +39 -0
- mbrola-0.0.2/.gitignore +163 -0
- mbrola-0.0.2/LICENSE.txt +9 -0
- mbrola-0.0.2/Makefile +5 -0
- mbrola-0.0.2/PKG-INFO +45 -0
- mbrola-0.0.2/README.md +24 -0
- mbrola-0.0.2/pyproject.toml +61 -0
- mbrola-0.0.2/src/mbrola/__about__.py +4 -0
- mbrola-0.0.2/src/mbrola/__init__.py +3 -0
- mbrola-0.0.2/src/mbrola/mbrola.py +173 -0
- mbrola-0.0.2/tests/__init__.py +3 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# This workflow will upload a Python Package using Twine when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
|
|
3
|
+
|
|
4
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
+
# They are provided by a third-party and are governed by
|
|
6
|
+
# separate terms of service, privacy policy, and support
|
|
7
|
+
# documentation.
|
|
8
|
+
|
|
9
|
+
name: Upload Python Package
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
release:
|
|
13
|
+
types: [published]
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
deploy:
|
|
20
|
+
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- name: Set up Python
|
|
26
|
+
uses: actions/setup-python@v3
|
|
27
|
+
with:
|
|
28
|
+
python-version: '3.x'
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: |
|
|
31
|
+
python -m pip install --upgrade pip
|
|
32
|
+
pip install build
|
|
33
|
+
- name: Build package
|
|
34
|
+
run: python -m build
|
|
35
|
+
- name: Publish package
|
|
36
|
+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
|
|
37
|
+
with:
|
|
38
|
+
user: __token__
|
|
39
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
mbrola-0.0.2/.gitignore
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# mypy
|
|
144
|
+
.mypy_cache/
|
|
145
|
+
.dmypy.json
|
|
146
|
+
dmypy.json
|
|
147
|
+
|
|
148
|
+
# Pyre type checker
|
|
149
|
+
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
#.idea/
|
|
163
|
+
|
mbrola-0.0.2/LICENSE.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present gongcastro <gongarciacastro@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
mbrola-0.0.2/Makefile
ADDED
mbrola-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: mbrola
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A Python front-end for the MBROLA speech synthesizer
|
|
5
|
+
Project-URL: Documentation, https://github.com/gongcastro/pymbrola#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/gongcastro/pymbrola/issues
|
|
7
|
+
Project-URL: Source, https://github.com/gongcastro/pymbrola
|
|
8
|
+
Author-email: gongcastro <gongarciacastro@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# pymbrola
|
|
23
|
+
|
|
24
|
+
[](https://pypi.org/project/pymbrola)
|
|
25
|
+
[](https://pypi.org/project/pymbrola)
|
|
26
|
+
|
|
27
|
+
-----
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Table of Contents
|
|
31
|
+
|
|
32
|
+
- [Installation](#installation)
|
|
33
|
+
- [License](#license)
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
MBROLA is currently available only on Linux-based systems like Ubuntu, or on Windows via the [Windows Susbsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install). Install MBROLA in your machine following the instructions in the [MBROLA repository](https://github.com/numediart/MBROLA). If you are using WSL, install MBROLA in WSL. After this, you should be ready to install **pymbrola** using pip.
|
|
38
|
+
|
|
39
|
+
```console
|
|
40
|
+
pip install pymbrola
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
`pymbrola` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
mbrola-0.0.2/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# pymbrola
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pymbrola)
|
|
4
|
+
[](https://pypi.org/project/pymbrola)
|
|
5
|
+
|
|
6
|
+
-----
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [License](#license)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
MBROLA is currently available only on Linux-based systems like Ubuntu, or on Windows via the [Windows Susbsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install). Install MBROLA in your machine following the instructions in the [MBROLA repository](https://github.com/numediart/MBROLA). If you are using WSL, install MBROLA in WSL. After this, you should be ready to install **pymbrola** using pip.
|
|
17
|
+
|
|
18
|
+
```console
|
|
19
|
+
pip install pymbrola
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
`pymbrola` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mbrola"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = 'A Python front-end for the MBROLA speech synthesizer'
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = []
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "gongcastro", email = "gongarciacastro@gmail.com" },
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Programming Language :: Python",
|
|
19
|
+
"Programming Language :: Python :: 3.8",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
25
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
26
|
+
]
|
|
27
|
+
dependencies = []
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Documentation = "https://github.com/gongcastro/pymbrola#readme"
|
|
31
|
+
Issues = "https://github.com/gongcastro/pymbrola/issues"
|
|
32
|
+
Source = "https://github.com/gongcastro/pymbrola"
|
|
33
|
+
|
|
34
|
+
[tool.hatch.version]
|
|
35
|
+
path = "src/mbrola/__about__.py"
|
|
36
|
+
|
|
37
|
+
[tool.hatch.envs.types]
|
|
38
|
+
extra-dependencies = [
|
|
39
|
+
"mypy>=1.0.0",
|
|
40
|
+
]
|
|
41
|
+
[tool.hatch.envs.types.scripts]
|
|
42
|
+
check = "mypy --install-types --non-interactive {args:src/mbrola tests}"
|
|
43
|
+
|
|
44
|
+
[tool.coverage.run]
|
|
45
|
+
source_pkgs = ["mbrola", "tests"]
|
|
46
|
+
branch = true
|
|
47
|
+
parallel = true
|
|
48
|
+
omit = [
|
|
49
|
+
"src/mbrola/__about__.py",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[tool.coverage.paths]
|
|
53
|
+
pymbrola = ["src/mbrola", "*/pymbrola/src/mbrola"]
|
|
54
|
+
tests = ["tests", "*/pymbrola/tests"]
|
|
55
|
+
|
|
56
|
+
[tool.coverage.report]
|
|
57
|
+
exclude_lines = [
|
|
58
|
+
"no cov",
|
|
59
|
+
"if __name__ == .__main__.:",
|
|
60
|
+
"if TYPE_CHECKING:",
|
|
61
|
+
]
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess as sp
|
|
3
|
+
import platform
|
|
4
|
+
import shutil
|
|
5
|
+
import functools
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MBROLA:
|
|
9
|
+
"""A class for generating MBROLA sounds.
|
|
10
|
+
|
|
11
|
+
An MBROLA class contains the necessary elements to synthesise an audio using MBROLA.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
word (str): label for the mbrola sound.
|
|
15
|
+
phon (list[str]): list of phonemes.
|
|
16
|
+
durations (list[int] | int, optional): phoneme duration in milliseconds. Defaults to 100.
|
|
17
|
+
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.
|
|
18
|
+
pitch (list[int] | int, optional): pitch in Hertz (Hz). Defaults to 200.
|
|
19
|
+
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.
|
|
20
|
+
onset_silence (int, optional): duration in milliseconds of the silence interval to be inserted at onset. Defaults to 1.
|
|
21
|
+
offset_silence (int, optional): duration in milliseconds of the silence interval to be inserted at offset. Defaults to 1.
|
|
22
|
+
|
|
23
|
+
Attributes:
|
|
24
|
+
word (str): label for the mbrola sound.
|
|
25
|
+
phon (list[str]): list of phonemes.
|
|
26
|
+
durations (list[int] | int, optional): phoneme duration in milliseconds. Defaults to 100.
|
|
27
|
+
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.
|
|
28
|
+
pitch (list[int] | int, optional): pitch in Hertz (Hz). Defaults to 200.
|
|
29
|
+
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.
|
|
30
|
+
onset_silence (int, optional): duration in milliseconds of the silence interval to be inserted at onset. Defaults to 1.
|
|
31
|
+
offset_silence (int, optional): duration in milliseconds of the silence interval to be inserted at offset. Defaults to 1.
|
|
32
|
+
|
|
33
|
+
Raises:
|
|
34
|
+
ValueError: ``word`` must be a string
|
|
35
|
+
ValueError: ``phon`` must be a list of strings
|
|
36
|
+
ValueError: ``durations`` must be a list of integers or an integer
|
|
37
|
+
ValueError: ``phon`` and ``durations`` must have the same length
|
|
38
|
+
ValueError: ``pitch`` must be a list of integers or an integer
|
|
39
|
+
ValueError: ``phon`` and ``pitch`` must have the same length
|
|
40
|
+
ValueError: ``onset_silence`` must be an integer
|
|
41
|
+
ValueError: ``offset_silence`` must be an integer
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
word: str,
|
|
47
|
+
phon: list[str],
|
|
48
|
+
durations: list[int] | int = 100,
|
|
49
|
+
pitch: list[int] | int = 200,
|
|
50
|
+
onset_silence: int = 1,
|
|
51
|
+
offset_silence: int = 1,
|
|
52
|
+
):
|
|
53
|
+
self.word = word
|
|
54
|
+
self.phon = phon
|
|
55
|
+
self.durations = durations
|
|
56
|
+
self.pitch = pitch
|
|
57
|
+
self.onset_silence = onset_silence
|
|
58
|
+
self.offset_silence = offset_silence
|
|
59
|
+
|
|
60
|
+
nphon = len(self.phon)
|
|
61
|
+
|
|
62
|
+
if isinstance(self.durations, int):
|
|
63
|
+
self.durations = [self.durations] * nphon
|
|
64
|
+
self.durations = list(map(str, self.durations))
|
|
65
|
+
if isinstance(self.pitch, int):
|
|
66
|
+
self.pitch = [[self.pitch, self.pitch]] * nphon
|
|
67
|
+
if isinstance(self.pitch[0], int):
|
|
68
|
+
self.pitch = [list(map(str, [p, p])) for p in self.pitch]
|
|
69
|
+
self.pitch = [list(map(str, p)) for p in self.pitch]
|
|
70
|
+
|
|
71
|
+
validate_mbrola_args(self)
|
|
72
|
+
|
|
73
|
+
self.pho = make_pho(self)
|
|
74
|
+
|
|
75
|
+
def __str__(self):
|
|
76
|
+
return str("\n".join(self.pho))
|
|
77
|
+
|
|
78
|
+
def __repr__(self):
|
|
79
|
+
return str("\n".join(self.pho))
|
|
80
|
+
|
|
81
|
+
def export_pho(self, file: str):
|
|
82
|
+
try:
|
|
83
|
+
with open(f"{file}", "w+") as f:
|
|
84
|
+
f.write("\n".join(self.pho))
|
|
85
|
+
except FileNotFoundError:
|
|
86
|
+
print(f"{file} is not a valid path")
|
|
87
|
+
|
|
88
|
+
def make_sound(
|
|
89
|
+
self,
|
|
90
|
+
file: str,
|
|
91
|
+
voice: str = "it4",
|
|
92
|
+
f0_ratio: float = 1.0,
|
|
93
|
+
dur_ratio: float = 1.0,
|
|
94
|
+
remove_pho: bool = True,
|
|
95
|
+
):
|
|
96
|
+
with open("tmp.pho", mode="w") as f:
|
|
97
|
+
f.write("\n".join(self.pho))
|
|
98
|
+
|
|
99
|
+
cmd = f"{mbrola_cmd()} -f {f0_ratio} -t {dur_ratio} /usr/share/mbrola/{voice}/{voice} tmp.pho {file}"
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
sp.check_output(cmd)
|
|
103
|
+
except sp.CalledProcessError as e:
|
|
104
|
+
print(f"Error when making sound for {file}")
|
|
105
|
+
f.close()
|
|
106
|
+
if remove_pho:
|
|
107
|
+
os.remove("tmp.pho")
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def validate_mbrola_args(self) -> None:
|
|
112
|
+
nphon = len(self.phon)
|
|
113
|
+
if isinstance(self.durations, list) and len(self.durations) != nphon:
|
|
114
|
+
raise ValueError("`phon` and `durations` must have the same length")
|
|
115
|
+
if isinstance(self.pitch, list):
|
|
116
|
+
if len(self.pitch) != nphon:
|
|
117
|
+
raise ValueError("`phon` and `pitch` must have the same length")
|
|
118
|
+
if self.onset_silence <= 0:
|
|
119
|
+
raise ValueError("`onset_silence` must be a positive integer")
|
|
120
|
+
if self.offset_silence <= 0:
|
|
121
|
+
raise ValueError("`offset_silence` must be a positive integer")
|
|
122
|
+
return None
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def make_pho(self) -> list[str]:
|
|
126
|
+
pho = [f"; {self.word}", f"_ {self.onset_silence}"]
|
|
127
|
+
for ph, d, p in zip(self.phon, self.durations, self.pitch):
|
|
128
|
+
p_seq = " ".join(p)
|
|
129
|
+
pho.append(" ".join([ph, d, p_seq]))
|
|
130
|
+
pho.append(f"_ {self.offset_silence}")
|
|
131
|
+
return pho
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@functools.cache
|
|
135
|
+
def mbrola_cmd():
|
|
136
|
+
"""
|
|
137
|
+
Get MBROLA command for system command line.
|
|
138
|
+
"""
|
|
139
|
+
try:
|
|
140
|
+
if is_wsl() or os.name == "posix":
|
|
141
|
+
return "mbrola"
|
|
142
|
+
if os.name == "nt":
|
|
143
|
+
if wsl_available():
|
|
144
|
+
return "wsl mbrola"
|
|
145
|
+
else:
|
|
146
|
+
raise Exception(
|
|
147
|
+
f"MBROLA only available on {platform.system()} using the Windows Subsystem for Linux (WSL). Please, follow the instructions in the WSL site: https://learn.microsoft.com/en-us/windows/wsl/install."
|
|
148
|
+
)
|
|
149
|
+
except:
|
|
150
|
+
raise Exception(f"MBROLA not available for {platform.system()}")
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@functools.cache
|
|
154
|
+
def is_wsl(version: str = platform.uname().release) -> int:
|
|
155
|
+
"""
|
|
156
|
+
Returns ```True`` if Python is running in WSL, otherwise ```False``
|
|
157
|
+
"""
|
|
158
|
+
return version.endswith("microsoft-standard-WSL2")
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@functools.cache
|
|
162
|
+
def wsl_available() -> int:
|
|
163
|
+
"""
|
|
164
|
+
Returns ```True`` if Windows Subsystem for Linux (WLS) is available from Windows, otherwise ```False``
|
|
165
|
+
"""
|
|
166
|
+
if os.name != "nt" or not shutil.which("wsl"):
|
|
167
|
+
return False
|
|
168
|
+
try:
|
|
169
|
+
return is_wsl(
|
|
170
|
+
sp.check_output(["wsl", "uname", "-r"], text=True, timeout=15).strip()
|
|
171
|
+
)
|
|
172
|
+
except sp.SubprocessError:
|
|
173
|
+
return False
|