Merge branch 'dev' of github.com:litagin02/Style-Bert-VITS2

This commit is contained in:
tsukumi
2025-03-26 20:09:40 +09:00
15 changed files with 37 additions and 114 deletions

View File

@@ -177,9 +177,16 @@ def create_dataset_app() -> gr.Blocks:
value=False, value=False,
) )
hf_repo_id = gr.Dropdown( hf_repo_id = gr.Dropdown(
["openai/whisper", "kotoba-tech/kotoba-whisper-v1.1"], [
label="HuggingFaceのWhisperモデル", "openai/whisper-large-v3-turbo",
value="openai/whisper", "openai/whisper-large-v3",
"openai/whisper-large-v2",
"kotoba-tech/kotoba-whisper-v1.1",
"kotoba-tech/kotoba-whisper-v2.1",
"litagin/anime-whisper",
],
label="HuggingFaceのWhisper repo_id",
value="openai/whisper-large-v3",
visible=False, visible=False,
) )
compute_type = gr.Dropdown( compute_type = gr.Dropdown(

View File

@@ -897,7 +897,7 @@ initial_md = """
- 話者数が違うモデル同士はおそらくマージできません。 - 話者数が違うモデル同士はおそらくマージできません。
""" """
style_merge_md = f""" style_merge_md = """
## 3. スタイルベクトルのマージ ## 3. スタイルベクトルのマージ
1. マージ後のモデルにいくつスタイルを追加したいかを「作りたいスタイル数」で指定 1. マージ後のモデルにいくつスタイルを追加したいかを「作りたいスタイル数」で指定

View File

@@ -2,7 +2,7 @@ import argparse
import json import json
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
from random import sample, shuffle from random import sample
from typing import Optional from typing import Optional
from tqdm import tqdm from tqdm import tqdm

View File

@@ -1,4 +1,5 @@
from typing import Any, Optional, Sequence, Union from collections.abc import Sequence
from typing import Any, Optional, Union
import numpy as np import numpy as np
import onnxruntime import onnxruntime

View File

@@ -11,8 +11,10 @@ import torch
from numpy.typing import NDArray from numpy.typing import NDArray
from style_bert_vits2.logging import logger from style_bert_vits2.logging import logger
from style_bert_vits2.models.utils import checkpoints # type: ignore from style_bert_vits2.models.utils import (
from style_bert_vits2.models.utils import safetensors # type: ignore checkpoints, # type: ignore # noqa: F401
safetensors, # type: ignore # noqa: F401
)
if TYPE_CHECKING: if TYPE_CHECKING:

View File

@@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Optional, Union
from numpy.typing import NDArray from numpy.typing import NDArray

View File

@@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Optional, Union
import numpy as np import numpy as np
import onnxruntime import onnxruntime

View File

@@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Optional, Union
import numpy as np import numpy as np
import onnxruntime import onnxruntime

View File

@@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Optional, Union
import numpy as np import numpy as np
import onnxruntime import onnxruntime

View File

@@ -11,8 +11,9 @@ Style-Bert-VITS2 の ONNX 推論に必要な各言語ごとの ONNX 版 BERT モ
import gc import gc
import time import time
from collections.abc import Sequence
from pathlib import Path from pathlib import Path
from typing import Any, Optional, Sequence, Union from typing import Any, Optional, Union
import onnxruntime import onnxruntime
from huggingface_hub import hf_hub_download from huggingface_hub import hf_hub_download

View File

@@ -2,8 +2,9 @@ from __future__ import annotations
import gc import gc
import time import time
from collections.abc import Sequence
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union from typing import TYPE_CHECKING, Any, Optional, Union
import numpy as np import numpy as np
import onnxruntime import onnxruntime

View File

@@ -1,4 +1,5 @@
from typing import Any, Sequence, Union from collections.abc import Sequence
from typing import Any, Union
import onnxruntime import onnxruntime

View File

@@ -1,4 +1,5 @@
from typing import Any, Literal, Sequence from collections.abc import Sequence
from typing import Any, Literal
import pytest import pytest
from scipy.io import wavfile from scipy.io import wavfile

View File

@@ -67,8 +67,7 @@ def transcribe_files_with_hf_whisper(
"num_beams": num_beams, "num_beams": num_beams,
"no_repeat_ngram_size": no_repeat_ngram_size, "no_repeat_ngram_size": no_repeat_ngram_size,
} }
logger.info(f"generate_kwargs: {generate_kwargs}") logger.info(f"generate_kwargs: {generate_kwargs}, loading pipeline...")
pipe = pipeline( pipe = pipeline(
model=model_id, model=model_id,
max_new_tokens=128, max_new_tokens=128,
@@ -79,6 +78,7 @@ def transcribe_files_with_hf_whisper(
trust_remote_code=True, trust_remote_code=True,
# generate_kwargs=generate_kwargs, # generate_kwargs=generate_kwargs,
) )
logger.info("Loaded pipeline")
if initial_prompt is not None: if initial_prompt is not None:
prompt_ids: torch.Tensor = pipe.tokenizer.get_prompt_ids( prompt_ids: torch.Tensor = pipe.tokenizer.get_prompt_ids(
initial_prompt, return_tensors="pt" initial_prompt, return_tensors="pt"
@@ -196,10 +196,7 @@ if __name__ == "__main__":
with open(output_file, "a", encoding="utf-8") as f: with open(output_file, "a", encoding="utf-8") as f:
f.write(f"{wav_rel_path}|{model_name}|{language_id}|{text}\n") f.write(f"{wav_rel_path}|{model_name}|{language_id}|{text}\n")
else: else:
if args.hf_repo_id == "": model_id = args.hf_repo_id
model_id = f"openai/whisper-{args.model}"
else:
model_id = args.hf_repo_id
logger.info(f"Loading HF Whisper model ({model_id})") logger.info(f"Loading HF Whisper model ({model_id})")
pbar = tqdm(total=len(wav_files), file=SAFE_STDOUT) pbar = tqdm(total=len(wav_files), file=SAFE_STDOUT)
results = transcribe_files_with_hf_whisper( results = transcribe_files_with_hf_whisper(

View File

@@ -1,92 +0,0 @@
import argparse
import os
import shutil
import sys
from pathlib import Path
import pandas as pd
import torch
from tqdm import tqdm
from style_bert_vits2.logging import logger
vad_model, utils = torch.hub.load(
repo_or_dir="litagin02/silero-vad",
model="silero_vad",
onnx=True,
trust_repo=True,
)
(get_speech_timestamps, _, read_audio, *_) = utils
def get_speech_ratio(audio_file):
sampling_rate = 16000
wav = read_audio(audio_file, sampling_rate=sampling_rate)
speech_timestamps = get_speech_timestamps(
wav, vad_model, sampling_rate=sampling_rate
)
speech_dur_ms = 0
for ts in speech_timestamps:
start_ms = ts["start"] / 16
end_ms = ts["end"] / 16
speech_dur_ms += end_ms - start_ms
total_dur_ms = len(wav) / sampling_rate * 1000
return speech_dur_ms / total_dur_ms
def process(file: Path):
speech_ratio = get_speech_ratio(file)
return file, speech_ratio
def main():
parser = argparse.ArgumentParser(description="Calculate speech ratio.")
parser.add_argument(
"-i", "--input", help="Directory containing audio files", required=True
)
args = parser.parse_args()
if os.path.exists(os.path.join(args.input, "low_speech_ratio")):
logger.info("Low speech ratio directory already exists, skipping...")
exit(0)
data_dir = Path(args.input)
wav_files = list(data_dir.glob("*.wav"))
wav_files.sort()
if len(wav_files) < 100:
logger.warning("Too few files, skipping...")
exit(0)
logger.info(f"Start VAD filtering for {data_dir}...")
results = []
for wav_file in tqdm(wav_files, file=sys.stdout):
speech_ratio = get_speech_ratio(wav_file)
results.append((wav_file, speech_ratio))
results_df = pd.DataFrame(results, columns=["file", "speech_ratio"])
results_df.to_csv(os.path.join(data_dir, "speech_ratio.csv"), index=False)
logger.info(f"Speech ratio stats:\n{results_df['speech_ratio'].describe()}")
threshold = 0.5
low_speech_ratio_dir = os.path.join(data_dir, "low_speech_ratio")
os.makedirs(low_speech_ratio_dir, exist_ok=True)
low_speech_files = results_df[results_df["speech_ratio"] < threshold]["file"]
logger.info(f"Moving {len(low_speech_files)} files to {low_speech_ratio_dir}...")
for low_speech_file in low_speech_files:
shutil.move(low_speech_file, low_speech_ratio_dir)
logger.success("VAD filtering completed.")
if __name__ == "__main__":
main()