(self, request: Request)
| 29 | self.extra_params = {} |
| 30 | |
| 31 | async def preload(self, request: Request): |
| 32 | try: |
| 33 | if self._type == "url": |
| 34 | timeout = int(os.getenv("REQUEST_TIMEOUT", "5")) |
| 35 | proxy = os.getenv("REQUEST_PROXY", None) |
| 36 | audio_data = await fetch_resource(self._data, request, timeout=timeout, proxy=proxy) |
| 37 | elif self._type == "base64": |
| 38 | audio_data = base64.b64decode(self._data) |
| 39 | else: |
| 40 | raise ValueError(f"cannot read audio which type is {self._type}!") |
| 41 | |
| 42 | # check if valid audio bytes |
| 43 | audio_values, _ = librosa.load(BytesIO(audio_data), sr=16000) |
| 44 | from lightllm.models.whisper.defaults import MIN_AUDIO_LEN |
| 45 | |
| 46 | self.audio_length = max(audio_values.shape[0], MIN_AUDIO_LEN) # 如果音频过短,会被pad到480的长度 |
| 47 | self._preload_data = audio_data |
| 48 | return |
| 49 | |
| 50 | except Exception as e: |
| 51 | raise ValueError(f"Failed to read image type={self._type}, data[:100]={self._data[:100]}: {e}!") |
| 52 | |
| 53 | def read(self): |
| 54 | assert self._preload_data is not None |
no test coverage detected