Skip to content

Commit

Permalink
fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Mar 13, 2024
1 parent fb63545 commit 0e48484
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ specify [`gtts`](https://github.com/pndurette/gTTS) with the flag
$ echo "Are you ready to join Link and Zelda in fighting off this unprecedented threat to Hyrule?" > /tmp/artbox/text.md
$ artbox speech text-to-speech \
--title artbox \
--text-path /tmp/artbox/text.md \
--input-path /tmp/artbox/text.md \
--output-path /tmp/artbox/speech.mp3 \
--engine edge-tts
```
Expand All @@ -52,7 +52,7 @@ If you need to generate the audio for different language, you can use the flag
$ echo "Bom dia, mundo!" > /tmp/artbox/text.md
$ artbox speech text-to-speech \
--title artbox \
--text-path /tmp/artbox/text.md \
--input-path /tmp/artbox/text.md \
--output-path /tmp/artbox/speech.mp3 \
--lang pt
```
Expand All @@ -64,7 +64,7 @@ locale for that language, for example:
$ echo "Are you ready to join Link and Zelda in fighting off this unprecedented threat to Hyrule?" > /tmp/artbox/text.md
$ artbox speech text-to-speech \
--title artbox \
--text-path /tmp/artbox/text.md \
--input-path /tmp/artbox/text.md \
--output-path /tmp/artbox/speech.mp3 \
--engine edge-tts \
--lang en-IN
Expand All @@ -77,7 +77,7 @@ and `--pitch`, for example:
$ echo "Do you want some coffee?" > /tmp/artbox/text.md
$ artbox speech text-to-speech \
--title artbox \
--text-path /tmp/artbox/text.md \
--input-path /tmp/artbox/text.md \
--output-path /tmp/artbox/speech.mp3 \
--engine edge-tts \
--lang en \
Expand Down
22 changes: 17 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mkdocs-material = ">=9.1.15"
mkdocstrings = ">=0.21.2"
mkdocstrings-python = ">=1.1.2"
jupyterlab = ">=4.0.5"
makim = "1.12.0"
makim = "1.13.0"

[tool.pytest.ini_options]
testpaths = [
Expand All @@ -78,10 +78,12 @@ verbose = false
line-length = 79
force-exclude = true
src = ["./"]
ignore = ["PLR0913"]
exclude = [
'docs',
]
fix = true

[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # pyflakes
Expand All @@ -91,12 +93,12 @@ select = [
"RUF", # Ruff-specific rules
"I001", # isort
]
fix = true
ignore = ["PLR0913"]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.isort]
[tool.ruff.lint.isort]
# Use a single line between direct and from import
lines-between-types = 1

Expand Down
17 changes: 9 additions & 8 deletions src/artbox/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ref: https://thepythoncode.com/article/convert-text-to-speech-in-python
"""

import asyncio
import os
import random
Expand Down Expand Up @@ -70,16 +71,16 @@ class SpeechEngineGTTS(SpeechFromTextEngineBase):
def convert(self) -> None:
"""Convert text to audio speech."""
title: str = self.args.get("title", "")
text_path: str = self.args.get("text-path", "")
input_path: str = self.args.get("input-path", "")
lang: str = self.args.get("lang", "en")

if not title:
raise Exception("Argument `title` not given")

if not text_path:
raise Exception("Argument `text_path` not given")
if not input_path:
raise Exception("Argument `input_path` not given")

with open(text_path, "r") as f:
with open(input_path, "r") as f:
text = f.read()

tts = gtts.gTTS(text, lang=lang, slow=False)
Expand All @@ -92,7 +93,7 @@ class SpeechEngineMSEdgeTTS(SpeechFromTextEngineBase):
async def async_convert(self) -> None:
"""Convert text to audio speech in async mode."""
title: str = self.args.get("title", "")
text_path: str = self.args.get("input-path", "")
input_path: str = self.args.get("input-path", "")
lang: str = self.args.get("lang", "en")
rate = self.args.get("rate", "+0%")
volume = self.args.get("volume", "+0%")
Expand All @@ -101,10 +102,10 @@ async def async_convert(self) -> None:
if not title:
raise Exception("Argument `title` not given")

if not text_path:
raise Exception("Argument `text_path` not given")
if not input_path:
raise Exception("Argument `input_path` not given")

with open(text_path, "r") as f:
with open(input_path, "r") as f:
text = f.read()

params = {"Locale": lang} if "-" in lang else {"Language": lang}
Expand Down
7 changes: 4 additions & 3 deletions tests/test_speech.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Set of tests for the voices module."""

import os

from pathlib import Path
Expand All @@ -16,15 +17,15 @@
@pytest.mark.parametrize("engine", ["gtts", "edge-tts"])
def test_convert_from_text(engine) -> None:
"""Test the conversion from text to audio."""
text_path = TMP_PATH / f"totk-{engine}.txt"
input_path = TMP_PATH / f"totk-{engine}.txt"
params = {
"title": "totk",
"text-path": str(text_path),
"input-path": str(input_path),
"output-path": str(TMP_PATH / f"speech-{engine}.mp3"),
"engine": engine,
}

with open(text_path, "w") as f:
with open(input_path, "w") as f:
f.write(
"Are you ready to join Link and Zelda in fighting "
"off this unprecedented threat to Hyrule?"
Expand Down

0 comments on commit 0e48484

Please sign in to comment.