Validate frame rate. Args: input: Input audio/text data. fs: TODO.
(
input,
fs: int = 16000,
)
| 238 | |
| 239 | |
| 240 | def validate_frame_rate( |
| 241 | input, |
| 242 | fs: int = 16000, |
| 243 | ): |
| 244 | |
| 245 | # 将文件读取为字节流 |
| 246 | """Validate frame rate. |
| 247 | |
| 248 | Args: |
| 249 | input: Input audio/text data. |
| 250 | fs: TODO. |
| 251 | """ |
| 252 | byte_data = BytesIO(input) |
| 253 | |
| 254 | # 使用 pydub 加载音频 |
| 255 | try: |
| 256 | audio = AudioSegment.from_file(byte_data) |
| 257 | except: |
| 258 | raise RuntimeError( |
| 259 | "You are decoding the pcm data, please install pydub first. via `pip install pydub`." |
| 260 | ) |
| 261 | |
| 262 | # 确保采样率为 16000 Hz |
| 263 | if audio.frame_rate != fs: |
| 264 | audio = audio.set_frame_rate(fs) |
| 265 | |
| 266 | # 将重新采样后的音频导出为字节流 |
| 267 | output = BytesIO() |
| 268 | audio.export(output, format="wav") |
| 269 | output.seek(0) |
| 270 | |
| 271 | # 获取重新采样后的字节流数据 |
| 272 | input = output.read() |
| 273 | |
| 274 | return input |
| 275 | |
| 276 | |
| 277 | def extract_fbank(data, data_len=None, data_type: str = "sound", frontend=None, **kwargs): |
no test coverage detected
searching dependent graphs…