modify app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,6 @@ TRAIN_CONFIG = base_dir / "config.yaml"
|
|
| 13 |
NORM_CONFIG = base_dir / "feats_stats.npz"
|
| 14 |
DEVICE = "cpu"
|
| 15 |
RESAMPLING_RATE = 16000
|
| 16 |
-
THRESHOLD = 5000000
|
| 17 |
|
| 18 |
# モデル
|
| 19 |
speech2text = Speech2Text(
|
|
@@ -33,6 +32,9 @@ def resample(audio: np.ndarray, original_sr: int) -> tuple[np.ndarray, int]:
|
|
| 33 |
Returns:
|
| 34 |
tuple[np.ndarray, int]: リサンプリングされた音声信号と目標のサンプルレート
|
| 35 |
"""
|
|
|
|
|
|
|
|
|
|
| 36 |
# audioのサンプリングレートをoriginal_srから16kに調整する
|
| 37 |
resampled_audio = librosa.resample(
|
| 38 |
audio, orig_sr=original_sr, target_sr=RESAMPLING_RATE
|
|
@@ -57,9 +59,7 @@ def transcribe(input: tuple[int, np.ndarray]) -> str:
|
|
| 57 |
|
| 58 |
sr = input[0]
|
| 59 |
audio = input[1]
|
| 60 |
-
|
| 61 |
-
if len(audio) > THRESHOLD:
|
| 62 |
-
audio, _ = resample(audio, sr)
|
| 63 |
# 認識
|
| 64 |
nbests = speech2text(audio)
|
| 65 |
text, *_ = nbests[0]
|
|
|
|
| 13 |
NORM_CONFIG = base_dir / "feats_stats.npz"
|
| 14 |
DEVICE = "cpu"
|
| 15 |
RESAMPLING_RATE = 16000
|
|
|
|
| 16 |
|
| 17 |
# モデル
|
| 18 |
speech2text = Speech2Text(
|
|
|
|
| 32 |
Returns:
|
| 33 |
tuple[np.ndarray, int]: リサンプリングされた音声信号と目標のサンプルレート
|
| 34 |
"""
|
| 35 |
+
# int16あのでfloatに変換
|
| 36 |
+
if audio.dtype in [np.int16, np.int32]:
|
| 37 |
+
audio = audio.astype(np.float32) / np.iinfo(audio.dtype).max
|
| 38 |
# audioのサンプリングレートをoriginal_srから16kに調整する
|
| 39 |
resampled_audio = librosa.resample(
|
| 40 |
audio, orig_sr=original_sr, target_sr=RESAMPLING_RATE
|
|
|
|
| 59 |
|
| 60 |
sr = input[0]
|
| 61 |
audio = input[1]
|
| 62 |
+
audio, _ = resample(audio, sr)
|
|
|
|
|
|
|
| 63 |
# 認識
|
| 64 |
nbests = speech2text(audio)
|
| 65 |
text, *_ = nbests[0]
|