Skip to content

Commit

Permalink
support commandline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleZhang1118 committed Oct 11, 2024
1 parent 9203816 commit 7d957b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 12 additions & 7 deletions wesep/cli/extractor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import os
import sys

import numpy as np
from silero_vad import load_silero_vad, read_audio, get_speech_timestamps
from silero_vad import load_silero_vad, get_speech_timestamps
import torch
import torchaudio
import torchaudio.compliance.kaldi as kaldi
import yaml
from tqdm import tqdm
import soundfile

from wesep.cli.hub import Hub
Expand Down Expand Up @@ -85,9 +83,16 @@ def extract_speech(self, audio_path: str, audio_path_2: str):
pcm_enroll, sample_rate_enroll = torchaudio.load(
audio_path_2, normalize=self.wavform_norm
)
return self.extract_speech_from_pcm(pcm_mix, sample_rate_mix, pcm_enroll, sample_rate_enroll)

def extract_speech_from_pcm(self, pcm_mix: torch.Tensor, sample_rate_mix: int, pcm_enroll: torch.Tensor, sample_rate_enroll: int,):
return self.extract_speech_from_pcm(pcm_mix,
sample_rate_mix,
pcm_enroll,
sample_rate_enroll)

def extract_speech_from_pcm(self,
pcm_mix: torch.Tensor,
sample_rate_mix: int,
pcm_enroll: torch.Tensor,
sample_rate_enroll: int):
if self.apply_vad:
# TODO(Binbin Zhang): Refine the segments logic, here we just
# suppose there is only silence at the start/end of the speech
Expand All @@ -113,7 +118,7 @@ def extract_speech_from_pcm(self, pcm_mix: torch.Tensor, sample_rate_mix: int, p
pcm_enroll = pcmTotal.unsqueeze(0)
else: # all silence, nospeech
return None

pcm_mix = pcm_mix.to(torch.float)
if sample_rate_mix != self.resample_rate:
pcm_mix = torchaudio.transforms.Resample(
Expand Down
1 change: 0 additions & 1 deletion wesep/cli/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# limitations under the License.

import os
import requests
import sys
from pathlib import Path
import tarfile
Expand Down

0 comments on commit 7d957b3

Please sign in to comment.