Refactor: TTSModel.convert_to_16_bit_wav() to @staticmethod

This commit is contained in:
tsukumi
2024-11-10 07:11:53 +09:00
parent 20b0b0908b
commit 689217e350

View File

@@ -308,7 +308,8 @@ class TTSModel:
xvec = mean + (xvec - mean) * weight xvec = mean + (xvec - mean) * weight
return xvec return xvec
def convert_to_16_bit_wav(self, data: NDArray[Any]) -> NDArray[Any]: @staticmethod
def convert_to_16_bit_wav(data: NDArray[Any]) -> NDArray[Any]:
""" """
音声データを 16-bit int 形式に変換する。 音声データを 16-bit int 形式に変換する。
gradio.processing_utils.convert_to_16_bit_wav() を移植したもの。 gradio.processing_utils.convert_to_16_bit_wav() を移植したもの。
@@ -319,6 +320,7 @@ class TTSModel:
Returns: Returns:
NDArray[Any]: 16-bit int 形式の音声データ NDArray[Any]: 16-bit int 形式の音声データ
""" """
# Based on: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html # Based on: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html
if data.dtype in [np.float64, np.float32, np.float16]: # type: ignore if data.dtype in [np.float64, np.float32, np.float16]: # type: ignore
data = data / np.abs(data).max() data = data / np.abs(data).max()
@@ -343,6 +345,7 @@ class TTSModel:
"Audio data cannot be converted automatically from " "Audio data cannot be converted automatically from "
f"{data.dtype} to 16-bit int format." f"{data.dtype} to 16-bit int format."
) )
return data return data
def infer( def infer(