Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Quality

on:
pull_request:

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Run lint
run: uv run ruff check .

format:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Check formatting
run: uv run ruff format --check .

typecheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Run type checker
run: uv run ty check
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test

on:
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Run tests
run: uv run --group dev --with-editable . pytest
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ venv.bak/
# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# ruff
.ruff_cache/

# ty
.ty_cache/

# Pyre type checker
.pyre/
Expand All @@ -159,4 +160,11 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# uv
uv.lock
.python-version

.vscode

# Local agent instructions
AGENTS.md
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ pip install voicepeak-wrapper
import asyncio
import voicepeak_wrapper


async def main():
client = voicepeak_wrapper.Voicepeak()

await client.say_text("本日は快晴なり", "./test.wav") # 出力のサンプル
await client.say_text("本日は快晴なり", "./test.wav") # 出力のサンプル

narrators = await client.get_narrator_list() # ナレーターのリスト取得。時間がかかります。

narrators = await client.get_narrator_list() # ナレーターのリスト取得。時間がかかります。

asyncio.run(main())
```

パスを受け取る引数(exe_path, output_path, text_path)には`str`だけでなく`pathlib.Path`(`Path`)も渡せます。

# License
MITライセンス
詳しくは[LICENSE](./LICENSE)を確認ください。
39 changes: 35 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "voicepeak_wrapper"
version = "1.1.1"
version = "1.2.0"
description = "VOICEPEAKの非公式ラッパーです。詳しくはHomepage(Github)をご覧ください"
requires-python = ">=3.10"
license = { file = "LICENSE" }
Expand All @@ -14,8 +14,39 @@ classifiers = [
[project.urls]
Homepage = "https://github.com/Nanahuse/VoicepeakWrapper"

[project.optional-dependencies]
dev = ["pytest", "pytest-asyncio", "flake8", "black", "isort", "mypy"]
[dependency-groups]
dev = [
"pytest>=9.0.2",
"pytest-asyncio>=1.3.0",
"ruff>=0.14.10",
"ty>=0.0.9",
]

[tool.black]
[tool.ruff]
line-length = 120

[tool.ruff.lint]
ignore = [
"A002",
"COM812",
"D",
"E203",
"E722",
"EM101",
"EM102",
"FIX002",
"RUF002",
"S101",
"TD",
"TRY003",
"TRY300",
]

[tool.pytest.ini_options]
pythonpath = ["."]

[tool.ruff.lint.per-file-ignores]
"test/*" = ["INP001", "PLR2004", "SLF001"]

[tool.ty.environment]
python-version = "3.10"
171 changes: 171 additions & 0 deletions test/test_manual_voicepeak_file_generation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Copyright (c) 2023 Nanahuse
# This software is released under the MIT License
# https://opensource.org/license/mit/

"""VOICEPEAK integration tests that create output files.

These tests require a local VOICEPEAK installation and are marked xfail with
``run=False``, so they are reported as NOTRUN without launching VOICEPEAK. Run
them with pytest's built-in ``--runxfail`` option when file-generation coverage
is needed:

uv run --group dev --with-editable . pytest --runxfail

Or run just this module:

uv run --group dev --with-editable . pytest \\
test/test_manual_voicepeak_file_generation.py --runxfail
"""

import asyncio
import os
from pathlib import Path

import pytest

pytestmark = pytest.mark.xfail(run=False, reason="requires a local VOICEPEAK installation; pass --runxfail to run")

TEST_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
OUTPUT_PATH = os.path.join(TEST_DIRECTORY, "output")


@pytest.mark.asyncio
async def test_get_narrator_list():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()
narrators = await client.get_narrator_list()
lines = []
for narrator in narrators:
lines.append(f"{narrator.name} : {', '.join(narrator.emotions)}\n")

await client.say_text(
"本日は晴天なり",
output_path=os.path.join(OUTPUT_PATH, f"narrator_{narrator.name}.wav"),
narrator=narrator,
emotions={narrator.emotions[1]: 100},
)

await asyncio.to_thread(Path(OUTPUT_PATH, "narrators.txt").write_text, "".join(lines), encoding="UTF-8")


@pytest.mark.asyncio
async def test_get_narrator_name_list():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()
narrator_names = await client.get_narrator_name_list()
await asyncio.to_thread(
Path(OUTPUT_PATH, "narrator_names.txt").write_text,
"".join(f"{name}\n" for name in narrator_names),
encoding="UTF-8",
)


@pytest.mark.asyncio
async def test_get_emotion_list():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()

narrator_names = await client.get_narrator_name_list()
lines = []
for name in narrator_names:
emotion_list = await client.get_emotion_list(name)
lines.append(f"{name} : {', '.join(emotion_list)}\n")

await asyncio.to_thread(Path(OUTPUT_PATH, "emotions.txt").write_text, "".join(lines), encoding="UTF-8")

with pytest.raises(RuntimeError):
await client.get_emotion_list("hogehoge")


@pytest.mark.asyncio
async def test_say_text():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()
await client.say_text("本日は晴天なり", output_path=os.path.join(OUTPUT_PATH, "test_say_text.wav"))
await client.say_text(
"本日は晴天なり", output_path=os.path.join(OUTPUT_PATH, "test_say_text_upper.wav"), speed=200, pitch=300
)
await client.say_text(
"本日は晴天なり", output_path=os.path.join(OUTPUT_PATH, "test_say_text_lower.wav"), speed=50, pitch=-300
)

with pytest.raises(ValueError):
await client.say_text("エラー", output_path=os.path.join(OUTPUT_PATH, "error.wav"), speed=201)
with pytest.raises(ValueError):
await client.say_text("エラー", output_path=os.path.join(OUTPUT_PATH, "error.wav"), speed=49)
with pytest.raises(ValueError):
await client.say_text("エラー", output_path=os.path.join(OUTPUT_PATH, "error.wav"), pitch=-301)
with pytest.raises(ValueError):
await client.say_text("エラー", output_path=os.path.join(OUTPUT_PATH, "error.wav"), pitch=301)

with pytest.raises(RuntimeError):
await client.say_text("1" * 141, output_path=os.path.join(OUTPUT_PATH, "error.wav"))


@pytest.mark.asyncio
async def test_say_testfile():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()

text_file = os.path.join(TEST_DIRECTORY, "sample.txt")

await client.say_textfile(text_file, output_path=os.path.join(OUTPUT_PATH, "say_text.wav"))


@pytest.mark.asyncio
async def test_say_text_overwrites_existing_output_wav():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()
output_path = Path(OUTPUT_PATH) / "test_overwrite.wav"
await asyncio.to_thread(output_path.write_bytes, b"previous generation")

await client.say_text("本日は晴天なり", output_path=output_path)

content = await asyncio.to_thread(output_path.read_bytes)
assert len(content) > 0
assert content != b"previous generation"
assert content[:4] == b"RIFF"


@pytest.mark.asyncio
async def test_say_text_with_pathlib_output_narrator_and_emotions():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()
narrators = await client.get_narrator_list()
assert len(narrators) > 0
narrator = narrators[0]

output_path = Path(OUTPUT_PATH) / "test_narrator_emotions.wav"
emotions = {narrator.emotions[0]: 100} if narrator.emotions else None
await client.say_text(
"本日は晴天なり",
output_path=output_path,
narrator=narrator.name,
emotions=emotions,
)

content = await asyncio.to_thread(output_path.read_bytes)
assert len(content) > 0
assert content[:4] == b"RIFF"


@pytest.mark.asyncio
async def test_say_textfile_with_pathlib_input_and_output():
import voicepeak_wrapper

client = voicepeak_wrapper.Voicepeak()
text_file = Path(TEST_DIRECTORY) / "sample.txt"
output_path = Path(OUTPUT_PATH) / "test_textfile_path.wav"

await client.say_textfile(text_file, output_path=output_path, speed=120, pitch=-50)

content = await asyncio.to_thread(output_path.read_bytes)
assert len(content) > 0
assert content[:4] == b"RIFF"
Loading