Skip to content

Commit

Permalink
Merge branch 'main' into feat-rename-exec-execute-to-perform
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Jan 11, 2025
2 parents a8cbb88 + fda1e71 commit 3a48d53
Show file tree
Hide file tree
Showing 47 changed files with 1,141 additions and 621 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ jobs:
git fetch private refs/tags/${{ env.PRODUCTION_REPOSITORY_TAG }}
git -c user.name=dummy -c [email protected] merge FETCH_HEAD
) > /dev/null 2>&1
- name: Set up Python 3.8
- name: Set up Python 3.10
if: matrix.python_whl
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
architecture: ${{ contains(matrix.artifact_name,'x86') && 'x86' || 'x64' }}
- name: set up ${{ matrix.target }}
uses: ./.github/actions/rust-toolchain-from-file
Expand Down Expand Up @@ -225,7 +225,9 @@ jobs:
- name: set cargo version
run: |
cargo set-version "$VERSION" --exclude voicevox_core_python_api --exclude downloader --exclude xtask
if ${{ matrix.python_whl }}; then cargo set-version "$VERSION" -p voicevox_core_python_api; fi
if ${{ matrix.python_whl }}; then
sed -i_ 's/version = "\(0\.0\.0\)"/version = "'"$VERSION"'"/' ./crates/voicevox_core_python_api/pyproject.toml
fi
- name: cache target
uses: Swatinem/rust-cache@v2
if: ${{ !inputs.is_production }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate_document.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: Setup Java
uses: actions/setup-java@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: Install Poetry
run: |
python -m pip install --upgrade poetry
poetry config virtualenvs.create false
- name: Validate poetry.lock
run: |
poetry lock --no-update
poetry lock
git diff --exit-code
- name: Install dependencies
run: poetry install --with test
Expand Down
28 changes: 20 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y shellcheck
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: Install Pyflakes
run: pip install 'pyflakes>3,<4'
- name: actionlint
Expand All @@ -67,10 +67,10 @@ jobs:
uses: ./.github/actions/rust-toolchain-from-file
with:
components: clippy,rustfmt
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- uses: Swatinem/rust-cache@v2
- run: cargo clippy -v --tests -- -D clippy::all -D warnings --no-deps
- run: cargo clippy -v -- -D clippy::all -D warnings --no-deps
Expand Down Expand Up @@ -125,10 +125,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: Set up Rust
uses: ./.github/actions/rust-toolchain-from-file
- uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -272,10 +272,10 @@ jobs:
working-directory: ./crates/voicevox_core_python_api
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: Set up Rust
uses: ./.github/actions/rust-toolchain-from-file
- run: |
Expand All @@ -296,6 +296,18 @@ jobs:
for file in ../../example/python/run{,-asyncio}.py; do
poetry run python "$file" ../test_util/data/model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11
done
# https://github.com/VOICEVOX/voicevox_core/issues/873 が再発しないかの確認。
#
# Python 3.8においては、プロセスの終了までにFatal Python errorに至らなくても`StopIteration`までは達することが多い。
# #873の要因は依然として不明であるが、`StopIteration`が出ないことの確認をもって#873の解決とすることにする。
#
# TODO: 10回の実行におよそ60秒ほどかかるため、状況の経過を見てやめる。
for _ in {1..10}; do
poetry run python ../../example/python/run-asyncio.py ../test_util/data/model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11 \
2> >(tee ./stderr.txt >&2)
# shellcheck disable=SC2059
! grep -q StopIteration ./stderr.txt
done
build-and-test-java-api:
strategy:
fail-fast: false
Expand Down
8 changes: 6 additions & 2 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ typetag = "0.2.18"
url = "2.5.4"
uuid = "1.10.0"
voicevox_core = { path = "crates/voicevox_core" }
voicevox_core_macros = { path = "crates/voicevox_core_macros" }
windows = "0.43.0"
zip = "0.6.3"

[workspace.dependencies.voicevox-ort]
git = "https://github.com/VOICEVOX/ort.git"
rev = "09a9fe1619c1561efafc02f68f0bda4aad879771"
rev = "cecd844162a1c6188de03b4566c81d9d38a28600"

[workspace.dependencies.open_jtalk]
git = "https://github.com/VOICEVOX/open_jtalk-rs.git"
Expand All @@ -114,7 +115,8 @@ rev = "de226a26e8e18edbdb1d6f986afe37bbbf35fbf4"
version = "0.0.0"
edition = "2021"
publish = false
rust-version = "1.81.0"
rust-version = "1.84.0"
license = "MIT"

# min-sized-rustを元にrelease buildのサイズが小さくなるようにした
# https://github.com/johnthagen/min-sized-rust
Expand Down
1 change: 1 addition & 0 deletions crates/downloader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "downloader"
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[[bin]]
name = "download"
Expand Down
1 change: 1 addition & 0 deletions crates/test_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "test_util"
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[dependencies]
libloading.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ thiserror.workspace = true
tracing.workspace = true
uuid = { workspace = true, features = ["v4", "serde"] }
voicevox-ort = { workspace = true, features = ["download-binaries", "__init-for-voicevox"] }
voicevox_core_macros = { path = "../voicevox_core_macros" }
voicevox_core_macros.workspace = true

[dev-dependencies]
heck.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/voicevox_core/src/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod adjust;

pub(crate) use self::adjust::{ensure_minimum_phoneme_length, pad_decoder_feature};
6 changes: 6 additions & 0 deletions crates/voicevox_core/src/core/adjust.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! 推論操作の前処理と後処理。
mod post;
mod pre;

pub(crate) use self::{post::ensure_minimum_phoneme_length, pre::pad_decoder_feature};
12 changes: 12 additions & 0 deletions crates/voicevox_core/src/core/adjust/post.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! 推論の出力の後処理。
pub(crate) fn ensure_minimum_phoneme_length(mut output: Vec<f32>) -> Vec<f32> {
const PHONEME_LENGTH_MINIMAL: f32 = 0.01;

for output_item in output.iter_mut() {
if *output_item < PHONEME_LENGTH_MINIMAL {
*output_item = PHONEME_LENGTH_MINIMAL;
}
}
output
}
37 changes: 37 additions & 0 deletions crates/voicevox_core/src/core/adjust/pre.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! 推論の入力の前処理。
/// 音が途切れてしまうのを避けるworkaround処理。
// TODO: 改善したらここのpadding処理を取り除く
pub(crate) fn pad_decoder_feature<const PADDING_FRAME_LENGTH: usize>(
f0: ndarray::Array1<f32>,
phoneme: ndarray::Array2<f32>,
) -> (usize, ndarray::Array1<f32>, ndarray::Array2<f32>) {
let start_and_end_padding_size = 2 * PADDING_FRAME_LENGTH;
let length_with_padding = f0.len() + start_and_end_padding_size;
let f0_with_padding = make_f0_with_padding(f0, PADDING_FRAME_LENGTH);
let phoneme_with_padding = make_phoneme_with_padding(phoneme, PADDING_FRAME_LENGTH);
return (length_with_padding, f0_with_padding, phoneme_with_padding);

fn make_f0_with_padding(
f0_slice: ndarray::Array1<f32>,
padding_size: usize,
) -> ndarray::Array1<f32> {
// 音が途切れてしまうのを避けるworkaround処理
// 改善したらこの関数を削除する
let padding = ndarray::Array1::<f32>::zeros(padding_size);
ndarray::concatenate![ndarray::Axis(0), padding, f0_slice, padding]
}

fn make_phoneme_with_padding(
phoneme_slice: ndarray::Array2<f32>,
padding_size: usize,
) -> ndarray::Array2<f32> {
// 音が途切れてしまうのを避けるworkaround処理
// 改善したらこの関数を削除する
let mut padding = ndarray::Array2::<f32>::zeros((padding_size, phoneme_slice.ncols()));
padding
.slice_mut(ndarray::s![.., 0])
.assign(&ndarray::arr0(1.0));
ndarray::concatenate![ndarray::Axis(0), padding, phoneme_slice, padding]
}
}
28 changes: 28 additions & 0 deletions crates/voicevox_core/src/engine/audio_file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
use std::io::{Cursor, Write as _};

use super::AudioQuery;

pub(crate) fn to_s16le_pcm<const BASE_SAMPLING_RATE: u32>(
wave: &[f32],
&AudioQuery {
volume_scale,
output_sampling_rate,
output_stereo,
..
}: &AudioQuery,
) -> Vec<u8> {
let num_channels: u16 = if output_stereo { 2 } else { 1 };
let repeat_count: u32 = (output_sampling_rate / BASE_SAMPLING_RATE) * num_channels as u32;
let bytes_size = wave.len() as u32 * repeat_count * 2;
let buf: Vec<u8> = Vec::with_capacity(bytes_size as usize);
let mut cur = Cursor::new(buf);

for value in wave {
let v = (value * volume_scale).clamp(-1., 1.);
let data = (v * 0x7fff as f32) as i16;
for _ in 0..repeat_count {
cur.write_all(&data.to_le_bytes()).unwrap();
}
}

cur.into_inner()
}

/// 16bit PCMにヘッダを付加しWAVフォーマットのバイナリを生成する。
pub fn wav_from_s16le(pcm: &[u8], sampling_rate: u32, is_stereo: bool) -> Vec<u8> {
let num_channels: u16 = if is_stereo { 2 } else { 1 };
Expand Down
Loading

0 comments on commit 3a48d53

Please sign in to comment.