Skip to content

Commit

Permalink
BytesIO类型时,要保证切到初始位置,这样多次读取才能够正常。比如__call__函数。 (#2484)
Browse files Browse the repository at this point in the history
* BytesIO类型时,要保证切到初始位置,这样多次读取才能够正常。比如__call__函数。
__call__函数的参数audio_file为BytesIO类型时执行到self.preprocess(model, audio_file)会报错,需要判断audio_file为BytesIO类型时执行audio_file.seek(0)。
  • Loading branch information
ZapBird authored Sep 30, 2022
1 parent a657cc3 commit 7a13b35
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions paddlespeech/cli/asr/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import io
import os
import sys
import time
Expand Down Expand Up @@ -229,6 +230,8 @@ def preprocess(self, model_type: str, input: Union[str, os.PathLike]):
audio_file = input
if isinstance(audio_file, (str, os.PathLike)):
logger.debug("Preprocess audio_file:" + audio_file)
elif isinstance(audio_file, io.BytesIO):
audio_file.seek(0)

# Get the object for feature extraction
if "deepspeech2" in model_type or "conformer" in model_type or "transformer" in model_type:
Expand Down Expand Up @@ -352,6 +355,8 @@ def _check(self, audio_file: str, sample_rate: int, force_yes: bool=False):
if not os.path.isfile(audio_file):
logger.error("Please input the right audio file path")
return False
elif isinstance(audio_file, io.BytesIO):
audio_file.seek(0)

logger.debug("checking the audio file format......")
try:
Expand Down

0 comments on commit 7a13b35

Please sign in to comment.