Skip to content

Commit

Permalink
Merge branch 'main' into add-morphing
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Mar 16, 2024
2 parents 2443754 + 0848630 commit 1925685
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 92 deletions.
44 changes: 17 additions & 27 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ jobs:
- name: Raplace resource
if: inputs.is_production
shell: bash
run: |
run:
mv -f download/resource/core/README.md ./README.md
- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall
Expand Down Expand Up @@ -320,7 +320,7 @@ jobs:
cp -v target/${{ matrix.target }}/release/libvoicevox_core_java_api.so java_artifact/ || true
- name: Code signing (Windows)
if: startsWith(matrix.os, 'windows') && inputs.code_signing
run: |
run:
bash build_util/codesign.bash "artifact/${{ env.ASSET_NAME }}/voicevox_core.dll"
env:
ESIGNERCKA_USERNAME: ${{ secrets.ESIGNERCKA_USERNAME }}
Expand Down Expand Up @@ -366,44 +366,34 @@ jobs:
needs: [config, build_and_deploy]
runs-on: macos-12
env:
IOS_X86_64_PATH: artifact/voicevox_core-x86_64-apple-ios
IOS_AARCH64_SIM_PATH: artifact/voicevox_core-aarch64-apple-ios-sim
IOS_AARCH64_PATH: artifact/voicevox_core-aarch64-apple-ios
ASSET_NAME: voicevox_core-ios-xcframework-cpu-${{ needs.config.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v2
with:
name: voicevox_core-x86_64-apple-ios
path: artifact/voicevox_core-x86_64-apple-ios
path: ${{ env.IOS_X86_64_PATH }}
- uses: actions/download-artifact@v2
with:
name: voicevox_core-aarch64-apple-ios-sim
path: artifact/voicevox_core-aarch64-apple-ios-sim
path: ${{ env.IOS_AARCH64_SIM_PATH }}
- uses: actions/download-artifact@v2
with:
name: voicevox_core-aarch64-apple-ios
path: artifact/voicevox_core-aarch64-apple-ios
- name: Create fat binary
path: ${{ env.IOS_AARCH64_PATH }}
- name: Create xcframework
id: create-xcframework
run: |
mkdir -p "artifact/voicevox_core-sim"
lipo -create "artifact/voicevox_core-x86_64-apple-ios/libvoicevox_core.dylib" "artifact/voicevox_core-aarch64-apple-ios-sim/libvoicevox_core.dylib" -output "artifact/voicevox_core-sim/libvoicevox_core.dylib"
- name: Create XCFramework
run: |
mkdir -p "artifact/${{ env.ASSET_NAME }}"
# 必要なファイルだけコピー
mkdir -p "Headers-sim"
cp -v artifact/voicevox_core-x86_64-apple-ios/voicevox_core.h "Headers-sim"
cp -v crates/voicevox_core_c_api/xcframework/Headers/module.modulemap "Headers-sim"
mkdir -p "Headers-aarch64"
cp -v artifact/voicevox_core-aarch64-apple-ios/voicevox_core.h "Headers-aarch64"
cp -v crates/voicevox_core_c_api/xcframework/Headers/module.modulemap "Headers-aarch64"
xcodebuild -create-xcframework \
-library "artifact/voicevox_core-sim/libvoicevox_core.dylib" \
-headers "Headers-sim" \
-library "artifact/voicevox_core-aarch64-apple-ios/libvoicevox_core.dylib" \
-headers "Headers-aarch64" \
-output "artifact/${{ env.ASSET_NAME }}/voicevox_core.xcframework"
build_util/make_ios_xcframework.bash
echo "output_asset_path=${OUTPUT_ASSET_PATH}" >> "$GITHUB_OUTPUT"
env:
OUTPUT_ASSET_PATH: artifact/voicevox_core-ios-xcframework-cpu
- name: Archive artifact
run: |
cd artifact/${{ env.ASSET_NAME }}
cd ${{ steps.create-xcframework.outputs.output_asset_path }}
7z a "../../${{ env.ASSET_NAME }}.zip" "voicevox_core.xcframework"
- name: Upload to Release
if: fromJson(needs.config.outputs.deploy)
Expand Down Expand Up @@ -432,7 +422,7 @@ jobs:
- name: Raplace resource
if: inputs.is_production
shell: bash
run: |
run:
rm -r ./model; mv download/fat_resource/core/model ./model
- name: Create artifact
run: |
Expand Down Expand Up @@ -474,7 +464,7 @@ jobs:
- name: Install cargo-edit
run: cargo binstall cargo-edit@^0.11 --no-confirm
- name: set cargo version
run: |
run:
cargo set-version "$VERSION" -p voicevox_core_java_api

- name: "Download artifact (android-arm64-cpu)"
Expand Down
79 changes: 79 additions & 0 deletions build_util/make_ios_xcframework.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -eu

if [ ! -v IOS_X86_64_PATH ]; then # X86_64用のモジュールのディレクトリ(simulator)
echo "IOS_X86_64_PATHが未定義です"
exit 1
fi
if [ ! -v IOS_AARCH64_SIM_PATH ]; then # AARCH64_SIM用のモジュールのディレクトリ(simulator)
echo "IOS_AARCH64_SIM_PATHが未定義です"
exit 1
fi
if [ ! -v IOS_AARCH64_PATH ]; then # AARCH64用のモジュールのディレクトリ(実機)
echo "IOS_AARCH64_PATHが未定義です"
exit 1
fi
if [ ! -v OUTPUT_ASSET_PATH ]; then # 出力するASSETのディレクトリ
echo "OUTPUT_ASSET_PATHが未定義です"
exit 1
fi

echo "* Get original onnxruntime file name from rpath"
output=$(otool -L "${IOS_AARCH64_PATH}/libvoicevox_core.dylib")
matched_line=$(echo "$output" | grep "@rpath" | grep "libonnxruntime")
if [[ $matched_line ]]; then
if [[ $matched_line =~ (@rpath/([^ ]+\.dylib)) ]]; then
dylib_string=${BASH_REMATCH[2]}
else
echo "Expected pattern not found in the matched line"
echo "$output"
exit 1
fi
else
echo "No line containing '@rpath' and 'libonnxruntime' found"
echo "$output"
exit 1
fi
echo "Original onnx dylib file name: $dylib_string"

echo "* Copy Framework template"
arches=("aarch64" "sim")
artifacts=("${IOS_AARCH64_PATH}" "${IOS_AARCH64_SIM_PATH}")
for i in "${!arches[@]}"; do
arch="${arches[$i]}"
artifact="${artifacts[$i]}"
echo "* Copy Framework-${arch} template"
mkdir -p "Framework-${arch}/voicevox_core.framework/Headers"
cp -vr "crates/voicevox_core_c_api/xcframework/Frameworks/${arch}/" "Framework-${arch}/"
cp -v "${artifact}/voicevox_core.h" \
"Framework-${arch}/voicevox_core.framework/Headers/voicevox_core.h"
done

echo "* Create dylib"
# aarch64はdylibをコピー
cp -v "${IOS_AARCH64_PATH}/libvoicevox_core.dylib" \
"Framework-aarch64/voicevox_core.framework/voicevox_core"

# simはx86_64とarrch64を合わせてdylib作成
lipo -create "${IOS_X86_64_PATH}/libvoicevox_core.dylib" \
"${IOS_AARCH64_SIM_PATH}/libvoicevox_core.dylib" \
-output "Framework-sim/voicevox_core.framework/voicevox_core"

for arch in "${arches[@]}"; do
echo "* Change ${arch} @rpath"
# 自身への@rpathを変更
install_name_tool -id "@rpath/voicevox_core.framework/voicevox_core" \
"Framework-${arch}/voicevox_core.framework/voicevox_core"

# 依存ライブラリonnxruntimeへの@rpathを変更
install_name_tool -change "@rpath/$dylib_string" \
"@rpath/onnxruntime.framework/onnxruntime" \
"Framework-${arch}/voicevox_core.framework/voicevox_core"
done

echo "* Create XCFramework"
mkdir -p "${OUTPUT_ASSET_PATH}"
xcodebuild -create-xcframework \
-framework "Framework-sim/voicevox_core.framework" \
-framework "Framework-aarch64/voicevox_core.framework" \
-output "${OUTPUT_ASSET_PATH}/voicevox_core.xcframework"
2 changes: 1 addition & 1 deletion crates/test_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub const OPEN_JTALK_DIC_DIR: &str = concat!(
"/data/open_jtalk_dic_utf_8-1.11"
);

pub const EXAMPLE_DATA_JSON: &str = include_str!(concat!(
const EXAMPLE_DATA_JSON: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/data/example_data.json"
));
Expand Down
10 changes: 5 additions & 5 deletions crates/voicevox_core/src/engine/acoustic_feature_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static PHONEME_MAP: Lazy<HashMap<&str, i64>> = Lazy::new(|| {
});

#[derive(Debug, Clone, PartialEq, new, Default, Getters)]
pub struct OjtPhoneme {
pub(crate) struct OjtPhoneme {
phoneme: String,
#[allow(dead_code)]
start: f32,
Expand All @@ -70,23 +70,23 @@ pub struct OjtPhoneme {
}

impl OjtPhoneme {
pub fn num_phoneme() -> usize {
pub(crate) fn num_phoneme() -> usize {
PHONEME_MAP.len()
}

pub fn space_phoneme() -> String {
fn space_phoneme() -> String {
"pau".into()
}

pub fn phoneme_id(&self) -> i64 {
pub(crate) fn phoneme_id(&self) -> i64 {
if self.phoneme.is_empty() {
-1
} else {
*PHONEME_MAP.get(&self.phoneme.as_str()).unwrap()
}
}

pub fn convert(phonemes: &[OjtPhoneme]) -> Vec<OjtPhoneme> {
pub(crate) fn convert(phonemes: &[OjtPhoneme]) -> Vec<OjtPhoneme> {
let mut phonemes = phonemes.to_owned();
if let Some(first_phoneme) = phonemes.first_mut() {
if first_phoneme.phoneme.contains("sil") {
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/engine/kana_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub(crate) fn parse_kana(text: &str) -> KanaParseResult<Vec<AccentPhraseModel>>
Ok(parsed_result)
}

pub fn create_kana(accent_phrases: &[AccentPhraseModel]) -> String {
pub(crate) fn create_kana(accent_phrases: &[AccentPhraseModel]) -> String {
let mut text = String::new();
for phrase in accent_phrases {
let moras = phrase.moras();
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/engine/mora_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub(super) const MORA_LIST_MINIMUM: &[[&str; 3]] = &[
["ア", "", "a"],
];

pub fn mora2text(mora: &str) -> &str {
pub(crate) fn mora2text(mora: &str) -> &str {
for &[text, consonant, vowel] in MORA_LIST_MINIMUM {
if mora.len() >= consonant.len()
&& &mora[..consonant.len()] == consonant
Expand Down
14 changes: 7 additions & 7 deletions crates/voicevox_core/src/infer/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ pub(crate) struct Status<R: InferenceRuntime, D: InferenceDomain> {
}

impl<R: InferenceRuntime, D: InferenceDomain> Status<R, D> {
pub fn new(session_options: EnumMap<D::Operation, InferenceSessionOptions>) -> Self {
pub(crate) fn new(session_options: EnumMap<D::Operation, InferenceSessionOptions>) -> Self {
Self {
loaded_models: Default::default(),
session_options,
}
}

pub fn insert_model(
pub(crate) fn insert_model(
&self,
model_header: &VoiceModelHeader,
model_bytes: &EnumMap<D::Operation, Vec<u8>>,
Expand All @@ -64,30 +64,30 @@ impl<R: InferenceRuntime, D: InferenceDomain> Status<R, D> {
Ok(())
}

pub fn unload_model(&self, voice_model_id: &VoiceModelId) -> Result<()> {
pub(crate) fn unload_model(&self, voice_model_id: &VoiceModelId) -> Result<()> {
self.loaded_models.lock().unwrap().remove(voice_model_id)
}

pub fn metas(&self) -> VoiceModelMeta {
pub(crate) fn metas(&self) -> VoiceModelMeta {
self.loaded_models.lock().unwrap().metas()
}

pub(crate) fn ids_for(&self, style_id: StyleId) -> Result<(VoiceModelId, ModelInnerId)> {
self.loaded_models.lock().unwrap().ids_for(style_id)
}

pub fn is_loaded_model(&self, voice_model_id: &VoiceModelId) -> bool {
pub(crate) fn is_loaded_model(&self, voice_model_id: &VoiceModelId) -> bool {
self.loaded_models
.lock()
.unwrap()
.contains_voice_model(voice_model_id)
}

pub fn is_loaded_model_by_style_id(&self, style_id: StyleId) -> bool {
pub(crate) fn is_loaded_model_by_style_id(&self, style_id: StyleId) -> bool {
self.loaded_models.lock().unwrap().contains_style(style_id)
}

pub fn validate_speaker_id(&self, style_id: StyleId) -> bool {
pub(crate) fn validate_speaker_id(&self, style_id: StyleId) -> bool {
self.is_loaded_model_by_style_id(style_id)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ mod numerics;
mod result;
mod synthesizer;
mod task;
mod text_analyzer;
mod user_dict;
mod version;
mod voice_model;

pub mod __internal;
pub mod blocking;
pub mod text_analyzer;
pub mod tokio;

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use crate::Result;

pub async fn open_default_vvm_file() -> crate::tokio::VoiceModel {
pub(crate) async fn open_default_vvm_file() -> crate::tokio::VoiceModel {
crate::tokio::VoiceModel::from_path(
::test_util::convert_zip_vvm(
PathBuf::from(env!("CARGO_WORKSPACE_DIR"))
Expand Down
8 changes: 4 additions & 4 deletions crates/voicevox_core/src/text_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::{
AccentPhraseModel, FullcontextExtractor, Result,
};

pub trait TextAnalyzer {
pub(crate) trait TextAnalyzer {
fn analyze(&self, text: &str) -> Result<Vec<AccentPhraseModel>>;
}

/// AquesTalk風記法からAccentPhraseの配列を生成するTextAnalyzer
#[derive(Clone)]
pub struct KanaAnalyzer;
pub(crate) struct KanaAnalyzer;

impl TextAnalyzer for KanaAnalyzer {
fn analyze(&self, text: &str) -> Result<Vec<AccentPhraseModel>> {
Expand All @@ -22,10 +22,10 @@ impl TextAnalyzer for KanaAnalyzer {

/// OpenJtalkからAccentPhraseの配列を生成するTextAnalyzer
#[derive(Clone)]
pub struct OpenJTalkAnalyzer<O>(O);
pub(crate) struct OpenJTalkAnalyzer<O>(O);

impl<O> OpenJTalkAnalyzer<O> {
pub fn new(open_jtalk: O) -> Self {
pub(crate) fn new(open_jtalk: O) -> Self {
Self(open_jtalk)
}
}
Expand Down
Loading

0 comments on commit 1925685

Please sign in to comment.