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

__call__函数的参数audio_file为BytesIO类型时执行到self.preprocess(model, audio_file)会报错,需要判断audio_file为BytesIO类型时执行audio_file.seek(0)。
pull/2488/head
ZapBird 3 years ago
parent a657cc3e1b
commit b2fd68cd21

@ -15,6 +15,7 @@ import argparse
import os import os
import sys import sys
import time import time
from io import BytesIO
from collections import OrderedDict from collections import OrderedDict
from typing import List from typing import List
from typing import Optional from typing import Optional
@ -229,6 +230,8 @@ class ASRExecutor(BaseExecutor):
audio_file = input audio_file = input
if isinstance(audio_file, (str, os.PathLike)): if isinstance(audio_file, (str, os.PathLike)):
logger.debug("Preprocess audio_file:" + audio_file) logger.debug("Preprocess audio_file:" + audio_file)
elif isinstance(audio_file, BytesIO):
audio_file.seek(0)
# Get the object for feature extraction # Get the object for feature extraction
if "deepspeech2" in model_type or "conformer" in model_type or "transformer" in model_type: if "deepspeech2" in model_type or "conformer" in model_type or "transformer" in model_type:
@ -352,6 +355,8 @@ class ASRExecutor(BaseExecutor):
if not os.path.isfile(audio_file): if not os.path.isfile(audio_file):
logger.error("Please input the right audio file path") logger.error("Please input the right audio file path")
return False return False
elif isinstance(audio_file, BytesIO):
audio_file.seek(0)
logger.debug("checking the audio file format......") logger.debug("checking the audio file format......")
try: try:

Loading…
Cancel
Save