Unverified Commit 7e03e469 authored by Sanchit Gandhi's avatar Sanchit Gandhi Committed by GitHub
Browse files

[ASR pipeline] Check for torchaudio (#23953)



* [ASR pipeline] Check for torchaudio

* add pip instructions
Co-authored-by: default avatarSylvain Gugger <sylvain.gugger@gmail.com>

---------
Co-authored-by: default avatarSylvain Gugger <sylvain.gugger@gmail.com>
parent 6ce6d62b
......@@ -17,7 +17,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Union
import numpy as np
import requests
from ..utils import is_torch_available, logging
from ..utils import is_torch_available, is_torchaudio_available, logging
from .audio_utils import ffmpeg_read
from .base import ChunkPipeline
......@@ -349,7 +349,14 @@ class AutomaticSpeechRecognitionPipeline(ChunkPipeline):
inputs = _inputs
if in_sampling_rate != self.feature_extractor.sampling_rate:
import torch
if is_torchaudio_available():
from torchaudio import functional as F
else:
raise ImportError(
"torchaudio is required to resample audio samples in AutomaticSpeechRecognitionPipeline. "
"The torchaudio package can be installed through: `pip install torchaudio`."
)
inputs = F.resample(
torch.from_numpy(inputs), in_sampling_rate, self.feature_extractor.sampling_rate
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment