Skip to content

Commit

Permalink
fix num ch (#3652)
Browse files Browse the repository at this point in the history
Signed-off-by: ekmb <ebakhturina@nvidia.com>
  • Loading branch information
ekmb authored Feb 12, 2022
1 parent d5ab59d commit 461a866
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/ctc_segmentation/scripts/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
from typing import List

import regex
import scipy.io.wavfile as wav
from joblib import Parallel, delayed
from normalization_helpers import LATIN_TO_RU, RU_ABBREVIATIONS
from num2words import num2words
from pydub import AudioSegment
from pydub.utils import mediainfo
from tqdm import tqdm

from nemo.collections.asr.models import ASRModel
from nemo.collections.asr.parts.preprocessing.segment import AudioSegment
from nemo.utils import model_utils

try:
Expand Down Expand Up @@ -84,8 +84,13 @@ def process_audio(in_file: str, wav_file: str = None, cut_prefix: int = 0, sampl
sample_rate: target sampling rate
"""
try:
audio = AudioSegment.from_file(in_file, target_sr=sample_rate, offset=cut_prefix)
wav.write(wav_file, data=audio._samples, rate=sample_rate)
info = mediainfo(in_file)
sound = AudioSegment.from_file(in_file, start_second=cut_prefix)
if info["sample_rate"] != str(sample_rate):
sound = sound.set_frame_rate(sample_rate)
if info["channels"] != 1:
sound = sound.set_channels(1)
sound.export(wav_file, format="wav")
except Exception as e:
print(f'{in_file} skipped - {e}')

Expand Down

0 comments on commit 461a866

Please sign in to comment.