File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import torch
44import numpy as np
55from typing import Dict , Tuple , Optional
6- from transformers import AutoModel , AutoProcessor , AutoFeatureExtractor
7- import torchaudio
6+ from transformers import AutoModel , AutoProcessor , AutoFeatureExtractor
87from tqdm import tqdm
98
9+ def import_torchaudio_gracefully ():
10+ try :
11+ import torchaudio
12+ return torchaudio
13+ except ImportError :
14+ raise ImportError ('torchaudio is required for SpeechFeatureExtractor. Please install it with this command:\n pip install torchaudio' )
1015
1116def auto_device (fn ):
1217 def wrapper (self , * args , ** kwargs ):
@@ -40,6 +45,7 @@ def __init__(
4045 target_sample_rate : int = 16000 ,
4146 disable_tqdm : bool = False ,
4247 ):
48+ import_torchaudio_gracefully ()
4349 assert pool in {"last" , "mean" }, "pool must be 'last' or 'mean'"
4450 self .model_name = model_name
4551 self .chunk_size = float (chunk_size )
You can’t perform that action at this time.
0 commit comments