Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BytesIO类型时,要保证切到初始位置,这样多次读取才能够正常。比如__call__函数。 #2484

Merged
merged 5 commits into from
Sep 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions paddlespeech/cli/asr/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import sys
import time
from io import BytesIO
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import 的位置不对,需要按照官方库、第三方库,字典序 import,否则过不了 CodeStyle 的 CI

from collections import OrderedDict
from typing import List
from typing import Optional
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, 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, BytesIO):
audio_file.seek(0)

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