Skip to content

Commit

Permalink
Merge pull request #977 from hanasay/main
Browse files Browse the repository at this point in the history
Convert audio to mono while extract speech token
  • Loading branch information
aluminumbox authored Feb 16, 2025
2 parents 95e99e0 + 296ed4f commit fd45708
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/extract_speech_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def single_job(utt):
audio, sample_rate = torchaudio.load(utt2wav[utt], backend='soundfile')
if sample_rate != 16000:
audio = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)(audio)
# Convert audio to mono
if audio.shape[0] > 1:
audio = audio.mean(dim=0, keepdim=True)
if audio.shape[1] / 16000 > 30:
logging.warning('do not support extract speech token for audio longer than 30s')
speech_token = []
Expand Down

0 comments on commit fd45708

Please sign in to comment.