Fix: maintain compatibility with Python 3.9
This commit is contained in:
4
app.py
4
app.py
@@ -5,7 +5,7 @@ import gradio as gr
|
|||||||
import torch
|
import torch
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from style_bert_vits2.constants import GRADIO_THEME, VERSION
|
from style_bert_vits2.constants import GRADIO_THEME, LATEST_VERSION
|
||||||
from common.tts_model import ModelHolder
|
from common.tts_model import ModelHolder
|
||||||
from webui import (
|
from webui import (
|
||||||
create_dataset_app,
|
create_dataset_app,
|
||||||
@@ -34,7 +34,7 @@ if device == "cuda" and not torch.cuda.is_available():
|
|||||||
model_holder = ModelHolder(Path(assets_root), device)
|
model_holder = ModelHolder(Path(assets_root), device)
|
||||||
|
|
||||||
with gr.Blocks(theme=GRADIO_THEME) as app:
|
with gr.Blocks(theme=GRADIO_THEME) as app:
|
||||||
gr.Markdown(f"# Style-Bert-VITS2 WebUI (version {VERSION})")
|
gr.Markdown(f"# Style-Bert-VITS2 WebUI (version {LATEST_VERSION})")
|
||||||
with gr.Tabs():
|
with gr.Tabs():
|
||||||
with gr.Tab("音声合成"):
|
with gr.Tab("音声合成"):
|
||||||
create_inference_app(model_holder=model_holder)
|
create_inference_app(model_holder=model_holder)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import zipfile
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import requests
|
import requests
|
||||||
@@ -37,7 +38,7 @@ from style_bert_vits2.constants import (
|
|||||||
DEFAULT_SDP_RATIO,
|
DEFAULT_SDP_RATIO,
|
||||||
DEFAULT_STYLE,
|
DEFAULT_STYLE,
|
||||||
DEFAULT_STYLE_WEIGHT,
|
DEFAULT_STYLE_WEIGHT,
|
||||||
VERSION,
|
LATEST_VERSION,
|
||||||
Languages,
|
Languages,
|
||||||
)
|
)
|
||||||
from style_bert_vits2.logging import logger
|
from style_bert_vits2.logging import logger
|
||||||
@@ -212,7 +213,7 @@ router = APIRouter()
|
|||||||
|
|
||||||
@router.get("/version")
|
@router.get("/version")
|
||||||
def version() -> str:
|
def version() -> str:
|
||||||
return VERSION
|
return LATEST_VERSION
|
||||||
|
|
||||||
|
|
||||||
class MoraTone(BaseModel):
|
class MoraTone(BaseModel):
|
||||||
@@ -265,7 +266,7 @@ class SynthesisRequest(BaseModel):
|
|||||||
silenceAfter: float = 0.5
|
silenceAfter: float = 0.5
|
||||||
pitchScale: float = 1.0
|
pitchScale: float = 1.0
|
||||||
intonationScale: float = 1.0
|
intonationScale: float = 1.0
|
||||||
speaker: str | None = None
|
speaker: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@router.post("/synthesis", response_class=AudioResponse)
|
@router.post("/synthesis", response_class=AudioResponse)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
# Style-Bert-VITS2 のバージョン
|
# Style-Bert-VITS2 のバージョン
|
||||||
VERSION = "2.4"
|
LATEST_VERSION = "2.4"
|
||||||
|
|
||||||
# Style-Bert-VITS2 のベースディレクトリ
|
# Style-Bert-VITS2 のベースディレクトリ
|
||||||
BASE_DIR = Path(__file__).parent.parent
|
BASE_DIR = Path(__file__).parent.parent
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch.nn import functional as F
|
from torch.nn import functional as F
|
||||||
from typing import Any
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
|
||||||
def init_weights(m: torch.nn.Module, mean: float = 0.0, std: float = 0.01) -> None:
|
def init_weights(m: torch.nn.Module, mean: float = 0.0, std: float = 0.01) -> None:
|
||||||
@@ -85,13 +85,13 @@ def slice_segments(x: torch.Tensor, ids_str: torch.Tensor, segment_size: int = 4
|
|||||||
return torch.gather(x, 2, gather_indices)
|
return torch.gather(x, 2, gather_indices)
|
||||||
|
|
||||||
|
|
||||||
def rand_slice_segments(x: torch.Tensor, x_lengths: torch.Tensor | None = None, segment_size: int = 4) -> tuple[torch.Tensor, torch.Tensor]:
|
def rand_slice_segments(x: torch.Tensor, x_lengths: Optional[torch.Tensor] = None, segment_size: int = 4) -> tuple[torch.Tensor, torch.Tensor]:
|
||||||
"""
|
"""
|
||||||
ランダムなセグメントをスライスする
|
ランダムなセグメントをスライスする
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
x (torch.Tensor): 入力テンソル
|
x (torch.Tensor): 入力テンソル
|
||||||
x_lengths (torch.Tensor, optional): 各バッチの長さ (デフォルト: None)
|
x_lengths (Optional[torch.Tensor], optional): 各バッチの長さ (デフォルト: None)
|
||||||
segment_size (int, optional): スライスのサイズ (デフォルト: 4)
|
segment_size (int, optional): スライスのサイズ (デフォルト: 4)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -141,13 +141,13 @@ def fused_add_tanh_sigmoid_multiply(input_a: torch.Tensor, input_b: torch.Tensor
|
|||||||
return acts
|
return acts
|
||||||
|
|
||||||
|
|
||||||
def sequence_mask(length: torch.Tensor, max_length: int | None = None) -> torch.Tensor:
|
def sequence_mask(length: torch.Tensor, max_length: Optional[int] = None) -> torch.Tensor:
|
||||||
"""
|
"""
|
||||||
シーケンスマスクを生成する
|
シーケンスマスクを生成する
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
length (torch.Tensor): 各シーケンスの長さ
|
length (torch.Tensor): 各シーケンスの長さ
|
||||||
max_length (int | None): 最大のシーケンス長さ。指定されていない場合は length の最大値を使用
|
max_length (Optional[int]): 最大のシーケンス長さ。指定されていない場合は length の最大値を使用
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
torch.Tensor: 生成されたシーケンスマスク
|
torch.Tensor: 生成されたシーケンスマスク
|
||||||
@@ -180,13 +180,13 @@ def generate_path(duration: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def clip_grad_value_(parameters: torch.Tensor | list[torch.Tensor], clip_value: float | None, norm_type: float = 2.0) -> float:
|
def clip_grad_value_(parameters: torch.Tensor | list[torch.Tensor], clip_value: Optional[float], norm_type: float = 2.0) -> float:
|
||||||
"""
|
"""
|
||||||
勾配の値をクリップする
|
勾配の値をクリップする
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
parameters (torch.Tensor | list[torch.Tensor]): クリップするパラメータ
|
parameters (torch.Tensor | list[torch.Tensor]): クリップするパラメータ
|
||||||
clip_value (float | None): クリップする値。None の場合はクリップしない
|
clip_value (Optional[float]): クリップする値。None の場合はクリップしない
|
||||||
norm_type (float): ノルムの種類
|
norm_type (float): ノルムの種類
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import torch
|
import torch
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
from style_bert_vits2.constants import Languages
|
from style_bert_vits2.constants import Languages
|
||||||
@@ -45,9 +46,9 @@ def get_text(
|
|||||||
language_str: Languages,
|
language_str: Languages,
|
||||||
hps,
|
hps,
|
||||||
device: str,
|
device: str,
|
||||||
assist_text: str | None = None,
|
assist_text: Optional[str] = None,
|
||||||
assist_text_weight: float = 0.7,
|
assist_text_weight: float = 0.7,
|
||||||
given_tone: list[int] | None = None,
|
given_tone: Optional[list[int]] = None,
|
||||||
):
|
):
|
||||||
use_jp_extra = hps.version.endswith("JP-Extra")
|
use_jp_extra = hps.version.endswith("JP-Extra")
|
||||||
# 推論時のみ呼び出されるので、raise_yomi_error は False に設定
|
# 推論時のみ呼び出されるので、raise_yomi_error は False に設定
|
||||||
@@ -122,9 +123,9 @@ def infer(
|
|||||||
device: str,
|
device: str,
|
||||||
skip_start: bool = False,
|
skip_start: bool = False,
|
||||||
skip_end: bool = False,
|
skip_end: bool = False,
|
||||||
assist_text: str | None = None,
|
assist_text: Optional[str] = None,
|
||||||
assist_text_weight: float = 0.7,
|
assist_text_weight: float = 0.7,
|
||||||
given_tone: list[int] | None = None,
|
given_tone: Optional[list[int]] = None,
|
||||||
):
|
):
|
||||||
is_jp_extra = hps.version.endswith("JP-Extra")
|
is_jp_extra = hps.version.endswith("JP-Extra")
|
||||||
bert, ja_bert, en_bert, phones, tones, lang_ids = get_text(
|
bert, ja_bert, en_bert, phones, tones, lang_ids = get_text(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import torch
|
import torch
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from style_bert_vits2.constants import Languages
|
from style_bert_vits2.constants import Languages
|
||||||
from style_bert_vits2.text_processing.symbols import (
|
from style_bert_vits2.text_processing.symbols import (
|
||||||
@@ -16,7 +17,7 @@ def extract_bert_feature(
|
|||||||
word2ph: list[int],
|
word2ph: list[int],
|
||||||
language: Languages,
|
language: Languages,
|
||||||
device: torch.device | str,
|
device: torch.device | str,
|
||||||
assist_text: str | None = None,
|
assist_text: Optional[str] = None,
|
||||||
assist_text_weight: float = 0.7,
|
assist_text_weight: float = 0.7,
|
||||||
) -> torch.Tensor:
|
) -> torch.Tensor:
|
||||||
"""
|
"""
|
||||||
@@ -27,7 +28,7 @@ def extract_bert_feature(
|
|||||||
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
||||||
language (Languages): テキストの言語
|
language (Languages): テキストの言語
|
||||||
device (torch.device | str): 推論に利用するデバイス
|
device (torch.device | str): 推論に利用するデバイス
|
||||||
assist_text (str | None, optional): 補助テキスト (デフォルト: None)
|
assist_text (Optional[str], optional): 補助テキスト (デフォルト: None)
|
||||||
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Style-Bert-VITS2 の学習・推論に必要な各言語ごとの BERT モデル
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import gc
|
import gc
|
||||||
from typing import cast
|
from typing import cast, Optional
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from transformers import (
|
from transformers import (
|
||||||
@@ -35,23 +35,23 @@ __loaded_tokenizers: dict[Languages, PreTrainedTokenizer | PreTrainedTokenizerFa
|
|||||||
|
|
||||||
def load_model(
|
def load_model(
|
||||||
language: Languages,
|
language: Languages,
|
||||||
pretrained_model_name_or_path: str | None = None,
|
pretrained_model_name_or_path: Optional[str] = None,
|
||||||
) -> PreTrainedModel | DebertaV2Model:
|
) -> PreTrainedModel | DebertaV2Model:
|
||||||
"""
|
"""
|
||||||
指定された言語の BERT モデルをロードし、ロード済みの BERT モデルを返す
|
指定された言語の BERT モデルをロードし、ロード済みの BERT モデルを返す。
|
||||||
一度ロードされていれば、ロード済みの BERT モデルを即座に返す
|
一度ロードされていれば、ロード済みの BERT モデルを即座に返す。
|
||||||
ライブラリ利用時は常に pretrain_model_name_or_path (Hugging Face のリポジトリ名 or ローカルのファイルパス) を指定する必要がある
|
ライブラリ利用時は常に pretrain_model_name_or_path (Hugging Face のリポジトリ名 or ローカルのファイルパス) を指定する必要がある。
|
||||||
ロードにはそれなりに時間がかかるため、ライブラリ利用前に明示的に pretrained_model_name_or_path を指定してロードしておくべき
|
ロードにはそれなりに時間がかかるため、ライブラリ利用前に明示的に pretrained_model_name_or_path を指定してロードしておくべき。
|
||||||
|
|
||||||
Style-Bert-VITS2 では、BERT モデルに下記の 3 つが利用されている
|
Style-Bert-VITS2 では、BERT モデルに下記の 3 つが利用されている。
|
||||||
これ以外の BERT モデルを指定した場合は正常に動作しない可能性が高い
|
これ以外の BERT モデルを指定した場合は正常に動作しない可能性が高い。
|
||||||
- 日本語: ku-nlp/deberta-v2-large-japanese-char-wwm
|
- 日本語: ku-nlp/deberta-v2-large-japanese-char-wwm
|
||||||
- 英語: microsoft/deberta-v3-large
|
- 英語: microsoft/deberta-v3-large
|
||||||
- 中国語: hfl/chinese-roberta-wwm-ext-large
|
- 中国語: hfl/chinese-roberta-wwm-ext-large
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
language (Languages): ロードする学習済みモデルの対象言語
|
language (Languages): ロードする学習済みモデルの対象言語
|
||||||
pretrained_model_name_or_path (str | None): ロードする学習済みモデルの名前またはパス。指定しない場合はデフォルトのパスが利用される (デフォルト: None)
|
pretrained_model_name_or_path (Optional[str]): ロードする学習済みモデルの名前またはパス。指定しない場合はデフォルトのパスが利用される (デフォルト: None)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
PreTrainedModel | DebertaV2Model: ロード済みの BERT モデル
|
PreTrainedModel | DebertaV2Model: ロード済みの BERT モデル
|
||||||
@@ -81,23 +81,23 @@ def load_model(
|
|||||||
|
|
||||||
def load_tokenizer(
|
def load_tokenizer(
|
||||||
language: Languages,
|
language: Languages,
|
||||||
pretrained_model_name_or_path: str | None = None,
|
pretrained_model_name_or_path: Optional[str] = None,
|
||||||
) -> PreTrainedTokenizer | PreTrainedTokenizerFast | DebertaV2Tokenizer:
|
) -> PreTrainedTokenizer | PreTrainedTokenizerFast | DebertaV2Tokenizer:
|
||||||
"""
|
"""
|
||||||
指定された言語の BERT モデルをロードし、ロード済みの BERT トークナイザーを返す
|
指定された言語の BERT モデルをロードし、ロード済みの BERT トークナイザーを返す。
|
||||||
一度ロードされていれば、ロード済みの BERT トークナイザーを即座に返す
|
一度ロードされていれば、ロード済みの BERT トークナイザーを即座に返す。
|
||||||
ライブラリ利用時は常に pretrain_model_name_or_path (Hugging Face のリポジトリ名 or ローカルのファイルパス) を指定する必要がある
|
ライブラリ利用時は常に pretrain_model_name_or_path (Hugging Face のリポジトリ名 or ローカルのファイルパス) を指定する必要がある。
|
||||||
ロードにはそれなりに時間がかかるため、ライブラリ利用前に明示的に pretrained_model_name_or_path を指定してロードしておくべき
|
ロードにはそれなりに時間がかかるため、ライブラリ利用前に明示的に pretrained_model_name_or_path を指定してロードしておくべき。
|
||||||
|
|
||||||
Style-Bert-VITS2 では、BERT モデルに下記の 3 つが利用されている
|
Style-Bert-VITS2 では、BERT モデルに下記の 3 つが利用されている。
|
||||||
これ以外の BERT モデルを指定した場合は正常に動作しない可能性が高い
|
これ以外の BERT モデルを指定した場合は正常に動作しない可能性が高い。
|
||||||
- 日本語: ku-nlp/deberta-v2-large-japanese-char-wwm
|
- 日本語: ku-nlp/deberta-v2-large-japanese-char-wwm
|
||||||
- 英語: microsoft/deberta-v3-large
|
- 英語: microsoft/deberta-v3-large
|
||||||
- 中国語: hfl/chinese-roberta-wwm-ext-large
|
- 中国語: hfl/chinese-roberta-wwm-ext-large
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
language (Languages): ロードする学習済みモデルの対象言語
|
language (Languages): ロードする学習済みモデルの対象言語
|
||||||
pretrained_model_name_or_path (str | None): ロードする学習済みモデルの名前またはパス。指定しない場合はデフォルトのパスが利用される (デフォルト: None)
|
pretrained_model_name_or_path (Optional[str]): ロードする学習済みモデルの名前またはパス。指定しない場合はデフォルトのパスが利用される (デフォルト: None)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
PreTrainedTokenizer | PreTrainedTokenizerFast | DebertaV2Tokenizer: ロード済みの BERT トークナイザー
|
PreTrainedTokenizer | PreTrainedTokenizerFast | DebertaV2Tokenizer: ロード済みの BERT トークナイザー
|
||||||
@@ -127,7 +127,7 @@ def load_tokenizer(
|
|||||||
|
|
||||||
def unload_model(language: Languages) -> None:
|
def unload_model(language: Languages) -> None:
|
||||||
"""
|
"""
|
||||||
指定された言語の BERT モデルをアンロードする
|
指定された言語の BERT モデルをアンロードする。
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
language (Languages): アンロードする BERT モデルの言語
|
language (Languages): アンロードする BERT モデルの言語
|
||||||
@@ -143,7 +143,7 @@ def unload_model(language: Languages) -> None:
|
|||||||
|
|
||||||
def unload_tokenizer(language: Languages) -> None:
|
def unload_tokenizer(language: Languages) -> None:
|
||||||
"""
|
"""
|
||||||
指定された言語の BERT トークナイザーをアンロードする
|
指定された言語の BERT トークナイザーをアンロードする。
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
language (Languages): アンロードする BERT トークナイザーの言語
|
language (Languages): アンロードする BERT トークナイザーの言語
|
||||||
@@ -159,7 +159,7 @@ def unload_tokenizer(language: Languages) -> None:
|
|||||||
|
|
||||||
def unload_all_models() -> None:
|
def unload_all_models() -> None:
|
||||||
"""
|
"""
|
||||||
すべての BERT モデルをアンロードする
|
すべての BERT モデルをアンロードする。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for language in list(__loaded_models.keys()):
|
for language in list(__loaded_models.keys()):
|
||||||
@@ -169,7 +169,7 @@ def unload_all_models() -> None:
|
|||||||
|
|
||||||
def unload_all_tokenizers() -> None:
|
def unload_all_tokenizers() -> None:
|
||||||
"""
|
"""
|
||||||
すべての BERT トークナイザーをアンロードする
|
すべての BERT トークナイザーをアンロードする。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for language in list(__loaded_tokenizers.keys()):
|
for language in list(__loaded_tokenizers.keys()):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from transformers import PreTrainedModel
|
from transformers import PreTrainedModel
|
||||||
@@ -14,7 +15,7 @@ def extract_bert_feature(
|
|||||||
text: str,
|
text: str,
|
||||||
word2ph: list[int],
|
word2ph: list[int],
|
||||||
device: torch.device | str,
|
device: torch.device | str,
|
||||||
assist_text: str | None = None,
|
assist_text: Optional[str] = None,
|
||||||
assist_text_weight: float = 0.7,
|
assist_text_weight: float = 0.7,
|
||||||
) -> torch.Tensor:
|
) -> torch.Tensor:
|
||||||
"""
|
"""
|
||||||
@@ -24,7 +25,7 @@ def extract_bert_feature(
|
|||||||
text (str): 中国語のテキスト
|
text (str): 中国語のテキスト
|
||||||
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
||||||
device (torch.device | str): 推論に利用するデバイス
|
device (torch.device | str): 推論に利用するデバイス
|
||||||
assist_text (str | None, optional): 補助テキスト (デフォルト: None)
|
assist_text (Optional[str], optional): 補助テキスト (デフォルト: None)
|
||||||
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from transformers import PreTrainedModel
|
from transformers import PreTrainedModel
|
||||||
@@ -14,7 +15,7 @@ def extract_bert_feature(
|
|||||||
text: str,
|
text: str,
|
||||||
word2ph: list[int],
|
word2ph: list[int],
|
||||||
device: torch.device | str,
|
device: torch.device | str,
|
||||||
assist_text: str | None = None,
|
assist_text: Optional[str] = None,
|
||||||
assist_text_weight: float = 0.7,
|
assist_text_weight: float = 0.7,
|
||||||
) -> torch.Tensor:
|
) -> torch.Tensor:
|
||||||
"""
|
"""
|
||||||
@@ -24,7 +25,7 @@ def extract_bert_feature(
|
|||||||
text (str): 英語のテキスト
|
text (str): 英語のテキスト
|
||||||
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
||||||
device (torch.device | str): 推論に利用するデバイス
|
device (torch.device | str): 推論に利用するデバイス
|
||||||
assist_text (str | None, optional): 補助テキスト (デフォルト: None)
|
assist_text (Optional[str], optional): 補助テキスト (デフォルト: None)
|
||||||
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from transformers import PreTrainedModel
|
from transformers import PreTrainedModel
|
||||||
@@ -15,7 +16,7 @@ def extract_bert_feature(
|
|||||||
text: str,
|
text: str,
|
||||||
word2ph: list[int],
|
word2ph: list[int],
|
||||||
device: torch.device | str,
|
device: torch.device | str,
|
||||||
assist_text: str | None = None,
|
assist_text: Optional[str] = None,
|
||||||
assist_text_weight: float = 0.7,
|
assist_text_weight: float = 0.7,
|
||||||
) -> torch.Tensor:
|
) -> torch.Tensor:
|
||||||
"""
|
"""
|
||||||
@@ -25,7 +26,7 @@ def extract_bert_feature(
|
|||||||
text (str): 日本語のテキスト
|
text (str): 日本語のテキスト
|
||||||
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
word2ph (list[int]): 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
||||||
device (torch.device | str): 推論に利用するデバイス
|
device (torch.device | str): 推論に利用するデバイス
|
||||||
assist_text (str | None, optional): 補助テキスト (デフォルト: None)
|
assist_text (Optional[str], optional): 補助テキスト (デフォルト: None)
|
||||||
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
assist_text_weight (float, optional): 補助テキストの重み (デフォルト: 0.7)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
Reference in New Issue
Block a user