반응형
Sox를 사용하여 음성 파일의 Sampling rate를 16000, channel을 1로 변환한다.
Bash
for i in *.mp3; do sox "$i" -r 16k -c 1 "$(basename -s .mp3 "$i").wav"; done;
한 폴더에 있는 여러 mp3 파일을 sample rate 16000, channel 1인 .wav 파일로 변경하는 커맨드 라인이다.
python
import os
import subprocess
import re
# Set path to the directory where you want the converted files to be saved
output_dir = './wav/converted'
# Make sure output directory exists
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Loop over each wav in the tsv file
for wav in open("wavs.tsv"):
# Check if the file is a .wav file
if wav.endswith('.wav'):
# Get the name of the file without the path and extension
wav_name = os.path.splitext(os.path.basename(wav))[0]
# Set the output file path
output_file = os.path.join(output_dir, f"{wav_name}.wav")
# Run the SoX command using subprocess
subprocess.run(['sox', wav, '-r', '16000', '-c', '1', output_file], check=True)
wavs.tsv에 한 줄에 wav의 경로가 있다고 했을 때 loop을 돌면서 converted 폴더에 변환된 wav들을 담는 코드이다.
반응형
'Tips' 카테고리의 다른 글
[DEBUG] Torch Distributed Error: Received 1 death signal, shutting down workers (2) | 2023.09.01 |
---|---|
NVLink in GPUs (0) | 2023.08.31 |
[VSCode] Vscode에서 검색한 내용 복사하기 (0) | 2023.05.08 |
[환경설정] conda disk quota exceeded 해결 (0) | 2023.04.24 |