把任意格式转成mp3文件
(any_path, mp3_path)
| 241 | |
| 242 | |
| 243 | def any_to_mp3(any_path, mp3_path): |
| 244 | """ |
| 245 | 把任意格式转成mp3文件 |
| 246 | """ |
| 247 | if any_path.endswith(".mp3"): |
| 248 | shutil.copy2(any_path, mp3_path) |
| 249 | return |
| 250 | if any_path.endswith(".sil") or any_path.endswith(".silk") or any_path.endswith(".slk"): |
| 251 | sil_to_wav(any_path, any_path) |
| 252 | any_path = mp3_path |
| 253 | audio = AudioSegment.from_file(any_path) |
| 254 | audio = audio.set_frame_rate(16000) |
| 255 | audio.export(mp3_path, format="mp3") |
| 256 | |
| 257 | |
| 258 | def sil_to_wav(silk_path, wav_path, rate: int = 24000): |
no test coverage detected