Add time_suffix option
This commit is contained in:
15
slice.py
15
slice.py
@@ -60,6 +60,7 @@ def split_wav(
|
|||||||
min_sec=2,
|
min_sec=2,
|
||||||
max_sec=12,
|
max_sec=12,
|
||||||
min_silence_dur_ms=700,
|
min_silence_dur_ms=700,
|
||||||
|
time_suffix=False,
|
||||||
):
|
):
|
||||||
margin = 200 # ミリ秒単位で、音声の前後に余裕を持たせる
|
margin = 200 # ミリ秒単位で、音声の前後に余裕を持たせる
|
||||||
speech_timestamps = get_stamps(
|
speech_timestamps = get_stamps(
|
||||||
@@ -88,7 +89,11 @@ def split_wav(
|
|||||||
end_sample = int(end_ms / 1000 * sr)
|
end_sample = int(end_ms / 1000 * sr)
|
||||||
segment = data[start_sample:end_sample]
|
segment = data[start_sample:end_sample]
|
||||||
|
|
||||||
sf.write(os.path.join(target_dir, f"{file_name}-{i}.wav"), segment, sr)
|
if time_suffix:
|
||||||
|
file = f"{file_name}-{int(start_ms)}-{int(end_ms)}.wav"
|
||||||
|
else:
|
||||||
|
file = f"{file_name}-{i}.wav"
|
||||||
|
sf.write(os.path.join(target_dir, file), segment, sr)
|
||||||
total_time_ms += end_ms - start_ms
|
total_time_ms += end_ms - start_ms
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
@@ -123,6 +128,12 @@ if __name__ == "__main__":
|
|||||||
default=700,
|
default=700,
|
||||||
help="Silence above this duration (ms) is considered as a split point.",
|
help="Silence above this duration (ms) is considered as a split point.",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--time_suffix",
|
||||||
|
"-t",
|
||||||
|
action='store_true',
|
||||||
|
help="Make the filename end with -start_ms-end_ms when saving wav.",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with open(os.path.join("configs", "paths.yml"), "r", encoding="utf-8") as f:
|
with open(os.path.join("configs", "paths.yml"), "r", encoding="utf-8") as f:
|
||||||
@@ -134,6 +145,7 @@ if __name__ == "__main__":
|
|||||||
min_sec = args.min_sec
|
min_sec = args.min_sec
|
||||||
max_sec = args.max_sec
|
max_sec = args.max_sec
|
||||||
min_silence_dur_ms = args.min_silence_dur_ms
|
min_silence_dur_ms = args.min_silence_dur_ms
|
||||||
|
time_suffix = args.time_suffix
|
||||||
|
|
||||||
wav_files = Path(input_dir).glob("**/*.wav")
|
wav_files = Path(input_dir).glob("**/*.wav")
|
||||||
wav_files = list(wav_files)
|
wav_files = list(wav_files)
|
||||||
@@ -151,6 +163,7 @@ if __name__ == "__main__":
|
|||||||
min_sec=min_sec,
|
min_sec=min_sec,
|
||||||
max_sec=max_sec,
|
max_sec=max_sec,
|
||||||
min_silence_dur_ms=min_silence_dur_ms,
|
min_silence_dur_ms=min_silence_dur_ms,
|
||||||
|
time_suffix=time_suffix,
|
||||||
)
|
)
|
||||||
total_sec += time_sec
|
total_sec += time_sec
|
||||||
total_count += count
|
total_count += count
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ def do_slice(
|
|||||||
min_sec: float,
|
min_sec: float,
|
||||||
max_sec: float,
|
max_sec: float,
|
||||||
min_silence_dur_ms: int,
|
min_silence_dur_ms: int,
|
||||||
|
time_suffix: bool,
|
||||||
input_dir: str,
|
input_dir: str,
|
||||||
):
|
):
|
||||||
if model_name == "":
|
if model_name == "":
|
||||||
@@ -36,6 +37,8 @@ def do_slice(
|
|||||||
"--min_silence_dur_ms",
|
"--min_silence_dur_ms",
|
||||||
str(min_silence_dur_ms),
|
str(min_silence_dur_ms),
|
||||||
]
|
]
|
||||||
|
if time_suffix:
|
||||||
|
cmd.append("--time_suffix")
|
||||||
if input_dir != "":
|
if input_dir != "":
|
||||||
cmd += ["--input_dir", input_dir]
|
cmd += ["--input_dir", input_dir]
|
||||||
# onnxの警告が出るので無視する
|
# onnxの警告が出るので無視する
|
||||||
@@ -140,6 +143,10 @@ with gr.Blocks(theme=GRADIO_THEME) as app:
|
|||||||
step=100,
|
step=100,
|
||||||
label="無音とみなして区切る最小の無音の長さ(ms)",
|
label="無音とみなして区切る最小の無音の長さ(ms)",
|
||||||
)
|
)
|
||||||
|
time_suffix = gr.Checkbox(
|
||||||
|
value=False,
|
||||||
|
label="WAVファイル名の末尾に元ファイルの時間範囲を付与する",
|
||||||
|
)
|
||||||
slice_button = gr.Button("スライスを実行")
|
slice_button = gr.Button("スライスを実行")
|
||||||
result1 = gr.Textbox(label="結果")
|
result1 = gr.Textbox(label="結果")
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
@@ -174,7 +181,7 @@ with gr.Blocks(theme=GRADIO_THEME) as app:
|
|||||||
result2 = gr.Textbox(label="結果")
|
result2 = gr.Textbox(label="結果")
|
||||||
slice_button.click(
|
slice_button.click(
|
||||||
do_slice,
|
do_slice,
|
||||||
inputs=[model_name, min_sec, max_sec, min_silence_dur_ms, input_dir],
|
inputs=[model_name, min_sec, max_sec, min_silence_dur_ms, time_suffix, input_dir],
|
||||||
outputs=[result1],
|
outputs=[result1],
|
||||||
)
|
)
|
||||||
transcribe_button.click(
|
transcribe_button.click(
|
||||||
|
|||||||
Reference in New Issue
Block a user