Merge branch 'dev' of github.com:litagin02/Style-Bert-VITS2
This commit is contained in:
@@ -177,9 +177,16 @@ def create_dataset_app() -> gr.Blocks:
|
||||
value=False,
|
||||
)
|
||||
hf_repo_id = gr.Dropdown(
|
||||
["openai/whisper", "kotoba-tech/kotoba-whisper-v1.1"],
|
||||
label="HuggingFaceのWhisperモデル",
|
||||
value="openai/whisper",
|
||||
[
|
||||
"openai/whisper-large-v3-turbo",
|
||||
"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,
|
||||
)
|
||||
compute_type = gr.Dropdown(
|
||||
|
||||
@@ -897,7 +897,7 @@ initial_md = """
|
||||
- 話者数が違うモデル同士はおそらくマージできません。
|
||||
"""
|
||||
|
||||
style_merge_md = f"""
|
||||
style_merge_md = """
|
||||
## 3. スタイルベクトルのマージ
|
||||
|
||||
1. マージ後のモデルにいくつスタイルを追加したいかを「作りたいスタイル数」で指定
|
||||
|
||||
@@ -2,7 +2,7 @@ import argparse
|
||||
import json
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from random import sample, shuffle
|
||||
from random import sample
|
||||
from typing import Optional
|
||||
|
||||
from tqdm import tqdm
|
||||
|
||||
@@ -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 onnxruntime
|
||||
|
||||
@@ -11,8 +11,10 @@ import torch
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from style_bert_vits2.logging import logger
|
||||
from style_bert_vits2.models.utils import checkpoints # type: ignore
|
||||
from style_bert_vits2.models.utils import safetensors # type: ignore
|
||||
from style_bert_vits2.models.utils import (
|
||||
checkpoints, # type: ignore # noqa: F401
|
||||
safetensors, # type: ignore # noqa: F401
|
||||
)
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 onnxruntime
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 onnxruntime
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 onnxruntime
|
||||
|
||||
@@ -11,8 +11,9 @@ Style-Bert-VITS2 の ONNX 推論に必要な各言語ごとの ONNX 版 BERT モ
|
||||
|
||||
import gc
|
||||
import time
|
||||
from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional, Sequence, Union
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
import onnxruntime
|
||||
from huggingface_hub import hf_hub_download
|
||||
|
||||
@@ -2,8 +2,9 @@ from __future__ import annotations
|
||||
|
||||
import gc
|
||||
import time
|
||||
from collections.abc import Sequence
|
||||
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 onnxruntime
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import Any, Sequence, Union
|
||||
from collections.abc import Sequence
|
||||
from typing import Any, Union
|
||||
|
||||
import onnxruntime
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import Any, Literal, Sequence
|
||||
from collections.abc import Sequence
|
||||
from typing import Any, Literal
|
||||
|
||||
import pytest
|
||||
from scipy.io import wavfile
|
||||
|
||||
@@ -67,8 +67,7 @@ def transcribe_files_with_hf_whisper(
|
||||
"num_beams": num_beams,
|
||||
"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(
|
||||
model=model_id,
|
||||
max_new_tokens=128,
|
||||
@@ -79,6 +78,7 @@ def transcribe_files_with_hf_whisper(
|
||||
trust_remote_code=True,
|
||||
# generate_kwargs=generate_kwargs,
|
||||
)
|
||||
logger.info("Loaded pipeline")
|
||||
if initial_prompt is not None:
|
||||
prompt_ids: torch.Tensor = pipe.tokenizer.get_prompt_ids(
|
||||
initial_prompt, return_tensors="pt"
|
||||
@@ -195,9 +195,6 @@ if __name__ == "__main__":
|
||||
wav_rel_path = wav_file.relative_to(input_dir)
|
||||
with open(output_file, "a", encoding="utf-8") as f:
|
||||
f.write(f"{wav_rel_path}|{model_name}|{language_id}|{text}\n")
|
||||
else:
|
||||
if 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})")
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user